Skip to content

Commit

Permalink
fixed PR + added data to season field retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienJaussaudGeosys committed May 29, 2024
1 parent 39626ca commit 26308e2
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 16 deletions.
8 changes: 6 additions & 2 deletions geosyspy/geosys.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,19 +661,23 @@ def get_available_permissions(self):

return result["permissions"]

def get_sfid_from_geometry(self, geometry):
def get_sfid_from_geometry(self, geometry: str):
"""Retrieves every season field ID contained within the passed geometry.
Args: geometry: a string representing the polygon containing the seasonfields.
Returns:
ids: an array containing all the seasonfield ids
"""
result = self.__master_data_management_service.retrieve_season_fields_in_polygon(geometry)
ids = [item['id'] for item in result.json()]
return ids

def get_season_fields(self, season_field_ids):
def get_season_fields(self, season_field_ids: List[str]):
"""Retrieves every season field with data from the id list.
Args: season_field_ids: a list of all season field ids for which get the detailed data.
Returns:
result: an array containing all the seasonfield
"""
Expand Down
2 changes: 1 addition & 1 deletion geosyspy/services/map_product_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def get_satellite_coverage_post(self, polygon: str,
end_date: str = end_date.strftime("%Y-%m-%d")
sensors: list[str] = [elem.value for elem in sensors_collection]

parameters = f"?Image.Sensor=$in:{'|'.join(sensors)}&coveragePercent=$gte:20$limit=9999&$filter=Image.Date >= '{start_date}' and Image.Date <= '{end_date}'"
parameters = f"?Image.Sensor=$in:{'|'.join(sensors)}&coveragePercent=$gte:20&$filter=Image.Date >= '{start_date}' and Image.Date <= '{end_date}'&$limit=None"
payload = {
"seasonFields": [
{
Expand Down
15 changes: 3 additions & 12 deletions geosyspy/services/master_data_management_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def extract_season_field_id(self, polygon: str) -> str:
f"Cannot handle HTTP response : {str(response.status_code)} : {str(response.json())}"
)

def retrieve_season_fields_in_polygon(self, polygon: str):
def retrieve_season_fields_in_polygon(self, polygon: str) -> List[object]:
api_call: str = urljoin(
self.base_url,
GeosysApiEndpoints.MASTER_DATA_MANAGEMENT_ENDPOINT.value + "/seasonfields",
Expand All @@ -82,15 +82,6 @@ def retrieve_season_fields_in_polygon(self, polygon: str):
)
return self.http_client.get(api_call)

def retrieve_season_fields_in_polygon(self, polygon: str):
api_call: str = urljoin(
self.base_url,
GeosysApiEndpoints.MASTER_DATA_MANAGEMENT_ENDPOINT.value + "/seasonfields",
'?fields=geometry,id'
+ '&$limit=none'
)
return self.http_client.get(api_call)

def get_season_field_unique_id(self, season_field_id: str) -> str:
"""Extracts the season field unique id from the response object.
Expand Down Expand Up @@ -203,7 +194,7 @@ def get_permission_codes(self) -> List[str]:
f"Cannot handle HTTP response : {str(response.status_code)} : {str(response.json())}"
)

def get_season_fields(self, season_field_ids: [str]):
def get_season_fields(self, season_field_ids: str) -> List[object]:
"""Extracts the list of seasonfields for the input ids
For now retrieves only geometry, to complete with future needs
Expand All @@ -219,7 +210,7 @@ def get_season_fields(self, season_field_ids: [str]):
mdm_url: str = urljoin(
self.base_url,
GeosysApiEndpoints.MASTER_DATA_MANAGEMENT_ENDPOINT.value
+'/seasonfields?$fields=id,geometry' #add other fields if needed
+'/seasonfields?$fields=id,geometry,sowingDate,estimatedHarvestDate' #add other fields if needed
+'&Id=$in:' + '|'.join(season_field_ids)
+'&$limit=none'
)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_int_geosys.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,4 +316,4 @@ def test_get_farm_info_from_location(self):

def test_retrieve_sfid_from_geometry(self):
result = self.client.get_sfid_from_geometry(geometry='POLYGON((-96.5130239465625 40.6059966855058,-96.37878474978515 40.6059966855058,-96.37878474978515 40.52044824466329,-96.5130239465625 40.52044824466329,-96.5130239465625 40.6059966855058))')
assert len(result) == 20
assert all(x in result for x in ['b3g9mvz', 'p1ramj2', 've3ply6'])

0 comments on commit 26308e2

Please sign in to comment.