Skip to content

Commit cb68b06

Browse files
committed
more docstrings
1 parent 492d75c commit cb68b06

File tree

1 file changed

+50
-12
lines changed

1 file changed

+50
-12
lines changed

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/database_logic.py

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ async def create_item_index(collection_id: str):
195195

196196
async def delete_item_index(collection_id: str):
197197
"""Delete the index for items in a collection.
198-
198+
199199
Args:
200200
collection_id (str): The ID of the collection whose items index will be deleted.
201201
"""
@@ -206,14 +206,16 @@ async def delete_item_index(collection_id: str):
206206

207207

208208
def bbox2polygon(b0: float, b1: float, b2: float, b3: float) -> List[List[List[float]]]:
209-
"""
210-
Transforms a bounding box represented by its four coordinates `b0`, `b1`, `b2`, and `b3` into a polygon.
211-
212-
:param b0: The x-coordinate of the lower-left corner of the bounding box.
213-
:param b1: The y-coordinate of the lower-left corner of the bounding box.
214-
:param b2: The x-coordinate of the upper-right corner of the bounding box.
215-
:param b3: The y-coordinate of the upper-right corner of the bounding box.
216-
:return: A polygon represented as a list of lists of coordinates.
209+
"""Transform a bounding box represented by its four coordinates `b0`, `b1`, `b2`, and `b3` into a polygon.
210+
211+
Args:
212+
b0 (float): The x-coordinate of the lower-left corner of the bounding box.
213+
b1 (float): The y-coordinate of the lower-left corner of the bounding box.
214+
b2 (float): The x-coordinate of the upper-right corner of the bounding box.
215+
b3 (float): The y-coordinate of the upper-right corner of the bounding box.
216+
217+
Returns:
218+
List[List[List[float]]]: A polygon represented as a list of lists of coordinates.
217219
"""
218220
return [[[b0, b1], [b2, b1], [b2, b3], [b0, b3], [b0, b1]]]
219221

@@ -280,14 +282,38 @@ class DatabaseLogic:
280282
"""CORE LOGIC"""
281283

282284
async def get_all_collections(self) -> Iterable[Dict[str, Any]]:
283-
"""Database logic to retrieve a list of all collections."""
285+
"""Retrieve a list of all collections from the database.
286+
287+
Returns:
288+
collections (Iterable[Dict[str, Any]]): A list of dictionaries containing the source data for each collection.
289+
290+
Notes:
291+
The collections are retrieved from the Elasticsearch database using the `client.search` method,
292+
with the `COLLECTIONS_INDEX` as the target index and `size=1000` to retrieve up to 1000 records.
293+
The result is a generator of dictionaries containing the source data for each collection.
294+
"""
284295
# https://github.com/stac-utils/stac-fastapi-elasticsearch/issues/65
285296
# collections should be paginated, but at least return more than the default 10 for now
286297
collections = await self.client.search(index=COLLECTIONS_INDEX, size=1000)
287298
return (c["_source"] for c in collections["hits"]["hits"])
288299

289300
async def get_one_item(self, collection_id: str, item_id: str) -> Dict:
290-
"""Database logic to retrieve a single item."""
301+
"""Retrieve a single item from the database.
302+
303+
Args:
304+
collection_id (str): The id of the Collection that the Item belongs to.
305+
item_id (str): The id of the Item.
306+
307+
Returns:
308+
item (Dict): A dictionary containing the source data for the Item.
309+
310+
Raises:
311+
NotFoundError: If the specified Item does not exist in the Collection.
312+
313+
Notes:
314+
The Item is retrieved from the Elasticsearch database using the `client.get` method,
315+
with the index for the Collection as the target index and the combined `mk_item_id` as the document id.
316+
"""
291317
try:
292318
item = await self.client.get(
293319
index=index_by_collection_id(collection_id),
@@ -332,7 +358,19 @@ def apply_datetime_filter(search: Search, datetime_search):
332358

333359
@staticmethod
334360
def apply_bbox_filter(search: Search, bbox: List):
335-
"""Database logic to search on bounding box."""
361+
"""Filter search results based on bounding box.
362+
363+
Args:
364+
search (Search): The search object to apply the filter to.
365+
bbox (List): The bounding box coordinates, represented as a list of four values [minx, miny, maxx, maxy].
366+
367+
Returns:
368+
search (Search): The search object with the bounding box filter applied.
369+
370+
Notes:
371+
The bounding box is transformed into a polygon using the `bbox2polygon` function and
372+
a geo_shape filter is added to the search object, set to intersect with the specified polygon.
373+
"""
336374
return search.filter(
337375
Q(
338376
{

0 commit comments

Comments
 (0)