113113 "id" : {"type" : "keyword" },
114114 "collection" : {"type" : "keyword" },
115115 "geometry" : {"type" : "geo_shape" },
116- "assets" : {"type" : "object" , "enabled" : False },
116+ "assets" : {"type" : "object" },
117117 "links" : {"type" : "object" , "enabled" : False },
118118 "properties" : {
119119 "type" : "object" ,
@@ -324,9 +324,7 @@ class DatabaseLogic:
324324 sync_client = SyncElasticsearchSettings ().create_client
325325
326326 item_serializer : Type [ItemSerializer ] = attr .ib (default = ItemSerializer )
327- collection_serializer : Type [CollectionSerializer ] = attr .ib (
328- default = CollectionSerializer
329- )
327+ collection_serializer : Type [CollectionSerializer ] = attr .ib (default = CollectionSerializer )
330328
331329 extensions : List [str ] = attr .ib (default = attr .Factory (list ))
332330
@@ -360,15 +358,9 @@ class DatabaseLogic:
360358 "size" : 10000 ,
361359 }
362360 },
363- "sun_elevation_frequency" : {
364- "histogram" : {"field" : "properties.view:sun_elevation" , "interval" : 5 }
365- },
366- "sun_azimuth_frequency" : {
367- "histogram" : {"field" : "properties.view:sun_azimuth" , "interval" : 5 }
368- },
369- "off_nadir_frequency" : {
370- "histogram" : {"field" : "properties.view:off_nadir" , "interval" : 5 }
371- },
361+ "sun_elevation_frequency" : {"histogram" : {"field" : "properties.view:sun_elevation" , "interval" : 5 }},
362+ "sun_azimuth_frequency" : {"histogram" : {"field" : "properties.view:sun_azimuth" , "interval" : 5 }},
363+ "off_nadir_frequency" : {"histogram" : {"field" : "properties.view:off_nadir" , "interval" : 5 }},
372364 "centroid_geohash_grid_frequency" : {
373365 "geohash_grid" : {
374366 "field" : "properties.proj:centroid" ,
@@ -465,9 +457,7 @@ async def get_one_item(self, collection_id: str, item_id: str) -> Dict:
465457 id = mk_item_id (item_id , collection_id ),
466458 )
467459 except exceptions .NotFoundError :
468- raise NotFoundError (
469- f"Item { item_id } does not exist in Collection { collection_id } "
470- )
460+ raise NotFoundError (f"Item { item_id } does not exist in Collection { collection_id } " )
471461 return item ["_source" ]
472462
473463 @staticmethod
@@ -497,16 +487,10 @@ def apply_datetime_filter(search: Search, datetime_search):
497487 Search: The filtered search object.
498488 """
499489 if "eq" in datetime_search :
500- search = search .filter (
501- "term" , ** {"properties__datetime" : datetime_search ["eq" ]}
502- )
490+ search = search .filter ("term" , ** {"properties__datetime" : datetime_search ["eq" ]})
503491 else :
504- search = search .filter (
505- "range" , properties__datetime = {"lte" : datetime_search ["lte" ]}
506- )
507- search = search .filter (
508- "range" , properties__datetime = {"gte" : datetime_search ["gte" ]}
509- )
492+ search = search .filter ("range" , properties__datetime = {"lte" : datetime_search ["lte" ]})
493+ search = search .filter ("range" , properties__datetime = {"gte" : datetime_search ["gte" ]})
510494 return search
511495
512496 @staticmethod
@@ -600,9 +584,7 @@ def apply_free_text_filter(search: Search, free_text_queries: Optional[List[str]
600584 """Database logic to perform query for search endpoint."""
601585 if free_text_queries is not None :
602586 free_text_query_string = '" OR properties.\\ *:"' .join (free_text_queries )
603- search = search .query (
604- "query_string" , query = f'properties.\\ *:"{ free_text_query_string } "'
605- )
587+ search = search .query ("query_string" , query = f'properties.\\ *:"{ free_text_query_string } "' )
606588
607589 return search
608590
@@ -715,11 +697,7 @@ async def execute_search(
715697 if hits and (sort_array := hits [limit - 1 ].get ("sort" )):
716698 next_token = urlsafe_b64encode (json .dumps (sort_array ).encode ()).decode ()
717699
718- matched = (
719- es_response ["hits" ]["total" ]["value" ]
720- if es_response ["hits" ]["total" ]["relation" ] == "eq"
721- else None
722- )
700+ matched = es_response ["hits" ]["total" ]["value" ] if es_response ["hits" ]["total" ]["relation" ] == "eq" else None
723701 if count_task .done ():
724702 try :
725703 matched = count_task .result ().get ("count" )
@@ -799,9 +777,7 @@ async def check_collection_exists(self, collection_id: str):
799777 if not await self .client .exists (index = COLLECTIONS_INDEX , id = collection_id ):
800778 raise NotFoundError (f"Collection { collection_id } does not exist" )
801779
802- async def prep_create_item (
803- self , item : Item , base_url : str , exist_ok : bool = False
804- ) -> Item :
780+ async def prep_create_item (self , item : Item , base_url : str , exist_ok : bool = False ) -> Item :
805781 """
806782 Preps an item for insertion into the database.
807783
@@ -823,15 +799,11 @@ async def prep_create_item(
823799 index = index_alias_by_collection_id (item ["collection" ]),
824800 id = mk_item_id (item ["id" ], item ["collection" ]),
825801 ):
826- raise ConflictError (
827- f"Item { item ['id' ]} in collection { item ['collection' ]} already exists"
828- )
802+ raise ConflictError (f"Item { item ['id' ]} in collection { item ['collection' ]} already exists" )
829803
830804 return self .item_serializer .stac_to_db (item , base_url )
831805
832- def sync_prep_create_item (
833- self , item : Item , base_url : str , exist_ok : bool = False
834- ) -> Item :
806+ def sync_prep_create_item (self , item : Item , base_url : str , exist_ok : bool = False ) -> Item :
835807 """
836808 Prepare an item for insertion into the database.
837809
@@ -860,9 +832,7 @@ def sync_prep_create_item(
860832 index = index_alias_by_collection_id (collection_id ),
861833 id = mk_item_id (item_id , collection_id ),
862834 ):
863- raise ConflictError (
864- f"Item { item_id } in collection { collection_id } already exists"
865- )
835+ raise ConflictError (f"Item { item_id } in collection { collection_id } already exists" )
866836
867837 return self .item_serializer .stac_to_db (item , base_url )
868838
@@ -890,13 +860,9 @@ async def create_item(self, item: Item, refresh: bool = False):
890860 )
891861
892862 if (meta := es_resp .get ("meta" )) and meta .get ("status" ) == 409 :
893- raise ConflictError (
894- f"Item { item_id } in collection { collection_id } already exists"
895- )
863+ raise ConflictError (f"Item { item_id } in collection { collection_id } already exists" )
896864
897- async def delete_item (
898- self , item_id : str , collection_id : str , refresh : bool = False
899- ):
865+ async def delete_item (self , item_id : str , collection_id : str , refresh : bool = False ):
900866 """Delete a single item from the database.
901867
902868 Args:
@@ -914,9 +880,7 @@ async def delete_item(
914880 refresh = refresh ,
915881 )
916882 except exceptions .NotFoundError :
917- raise NotFoundError (
918- f"Item { item_id } in collection { collection_id } not found"
919- )
883+ raise NotFoundError (f"Item { item_id } in collection { collection_id } not found" )
920884
921885 async def create_collection (self , collection : Collection , refresh : bool = False ):
922886 """Create a single collection in the database.
@@ -963,17 +927,13 @@ async def find_collection(self, collection_id: str) -> Collection:
963927 collection as a `Collection` object. If the collection is not found, a `NotFoundError` is raised.
964928 """
965929 try :
966- collection = await self .client .get (
967- index = COLLECTIONS_INDEX , id = collection_id
968- )
930+ collection = await self .client .get (index = COLLECTIONS_INDEX , id = collection_id )
969931 except exceptions .NotFoundError :
970932 raise NotFoundError (f"Collection { collection_id } not found" )
971933
972934 return collection ["_source" ]
973935
974- async def update_collection (
975- self , collection_id : str , collection : Collection , refresh : bool = False
976- ):
936+ async def update_collection (self , collection_id : str , collection : Collection , refresh : bool = False ):
977937 """Update a collection from the database.
978938
979939 Args:
@@ -1035,14 +995,10 @@ async def delete_collection(self, collection_id: str, refresh: bool = False):
1035995 function also calls `delete_item_index` to delete the index for the items in the collection.
1036996 """
1037997 await self .find_collection (collection_id = collection_id )
1038- await self .client .delete (
1039- index = COLLECTIONS_INDEX , id = collection_id , refresh = refresh
1040- )
998+ await self .client .delete (index = COLLECTIONS_INDEX , id = collection_id , refresh = refresh )
1041999 await delete_item_index (collection_id )
10421000
1043- async def bulk_async (
1044- self , collection_id : str , processed_items : List [Item ], refresh : bool = False
1045- ) -> None :
1001+ async def bulk_async (self , collection_id : str , processed_items : List [Item ], refresh : bool = False ) -> None :
10461002 """Perform a bulk insert of items into the database asynchronously.
10471003
10481004 Args:
@@ -1064,9 +1020,7 @@ async def bulk_async(
10641020 raise_on_error = False ,
10651021 )
10661022
1067- def bulk_sync (
1068- self , collection_id : str , processed_items : List [Item ], refresh : bool = False
1069- ) -> None :
1023+ def bulk_sync (self , collection_id : str , processed_items : List [Item ], refresh : bool = False ) -> None :
10701024 """Perform a bulk insert of items into the database synchronously.
10711025
10721026 Args:
0 commit comments