Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/collection extents and summaries #211

Merged
merged 3 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 5 additions & 47 deletions database/runtime/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def create_collection_search_functions(cursor) -> None:

def create_collection_summaries_functions(cursor) -> None:
"""
Functions to summarize datetimes and raster statistics for 'default' collections of items with single band COG assets
Functions to summarize datetimes and raster statistics for 'default' collections of items
"""

periodic_datetime_summary_sql = """
Expand All @@ -264,7 +264,7 @@ def create_collection_summaries_functions(cursor) -> None:
SELECT to_jsonb(
array[
to_char(min(datetime) at time zone 'Z', 'YYYY-MM-DD"T"HH24:MI:SS"Z"'),
to_char(max(datetime) at time zone 'Z', 'YYYY-MM-DD"T"HH24:MI:SS"Z"')
to_char(max(end_datetime) at time zone 'Z', 'YYYY-MM-DD"T"HH24:MI:SS"Z"')
])​
FROM items WHERE collection=$1;
;
Expand All @@ -287,23 +287,6 @@ def create_collection_summaries_functions(cursor) -> None:
"""
cursor.execute(sql.SQL(distinct_datetime_summary_sql))

cog_default_summary_sql = """
CREATE OR REPLACE FUNCTION dashboard.cog_default_summary(id text) RETURNS jsonb
LANGUAGE sql
IMMUTABLE PARALLEL SAFE
SET search_path TO 'pgstac', 'public'
AS $function$
SELECT jsonb_build_object(
'min', min((items."content"->'assets'->'cog_default'->'raster:bands'-> 0 ->'statistics'->>'minimum')::float),
'max', max((items."content"->'assets'->'cog_default'->'raster:bands'-> 0 ->'statistics'->>'maximum')::float)
)
FROM items WHERE collection=$1;
;
$function$
;
"""
cursor.execute(sql.SQL(cog_default_summary_sql))

update_collection_default_summaries_sql = """
CREATE OR REPLACE FUNCTION dashboard.update_collection_default_summaries(id text)
RETURNS void
Expand All @@ -320,13 +303,6 @@ def create_collection_summaries_functions(cursor) -> None:
THEN dashboard.periodic_datetime_summary(collections.id)
ELSE dashboard.discrete_datetime_summary(collections.id)
END
),
'cog_default', (
CASE
WHEN collections."content"->'item_assets' ? 'cog_default'
THEN dashboard.cog_default_summary(collections.id)
ELSE NULL
END
)
)
)
Expand All @@ -343,27 +319,9 @@ def create_collection_summaries_functions(cursor) -> None:
LANGUAGE sql
SET search_path TO 'pgstac', 'public'
AS $function$
UPDATE collections SET
"content" = "content" ||
jsonb_build_object(
'summaries', jsonb_build_object(
'datetime', (
CASE
WHEN (collections."content"->>'dashboard:is_periodic')::boolean
THEN dashboard.periodic_datetime_summary(collections.id)
ELSE dashboard.discrete_datetime_summary(collections.id)
END
),
'cog_default', (
CASE
WHEN collections."content"->'item_assets' ? 'cog_default'
THEN dashboard.cog_default_summary(collections.id)
ELSE NULL
END
)
)
)
WHERE collections."content" ?| array['item_assets', 'dashboard:is_periodic']
SELECT dashboard.update_collection_default_summaries(collections.id)
FROM collections
WHERE collections."content" ?| array['dashboard:is_periodic']
;
$function$
;
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ services:
database:
container_name: veda.db
platform: linux/amd64
image: ghcr.io/stac-utils/pgstac:v0.7.6
image: ghcr.io/stac-utils/pgstac:v0.7.10
environment:
- POSTGRES_USER=username
- POSTGRES_PASSWORD=password
Expand Down
Loading