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

Feature/retrieve sfids from polygon #37

Merged
Show file tree
Hide file tree
Changes from 7 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
19 changes: 19 additions & 0 deletions geosyspy/geosys.py
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • missing attributes description in docstring
    For example: geometry (str) : the input geometry
  • missing type in signature (geometry, season_fields_ids )

Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,25 @@ def get_available_permissions(self):

return result["permissions"]

def get_sfid_from_geometry(self, geometry):
"""Retrieves every season field ID contained within the passed geometry.

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):
"""Retrieves every season field with data from the id list.

Returns:
result: an array containing all the seasonfield
"""
result = self.__master_data_management_service.get_season_fields(season_field_ids)
return result

###########################################
# AGRIQUEST #
###########################################
Expand Down
49 changes: 49 additions & 0 deletions geosyspy/services/master_data_management_service.py
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing doctstring

Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,24 @@ 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):
api_call: str = urljoin(
self.base_url,
GeosysApiEndpoints.MASTER_DATA_MANAGEMENT_ENDPOINT.value + "/seasonfields",
'?Geometry=$within:' + polygon
+ '&$limit=none'
)
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 @@ -184,3 +202,34 @@ def get_permission_codes(self) -> List[str]:
raise ValueError(
f"Cannot handle HTTP response : {str(response.status_code)} : {str(response.json())}"
)

def get_season_fields(self, season_field_ids: [str]):
"""Extracts the list of seasonfields for the input ids
For now retrieves only geometry, to complete with future needs

Args:

Returns:
A list of seasonfields with the required data

Raises:
ValueError: The response status code is not as expected.
"""

mdm_url: str = urljoin(
self.base_url,
GeosysApiEndpoints.MASTER_DATA_MANAGEMENT_ENDPOINT.value
+'/seasonfields?$fields=id,geometry' #add other fields if needed
+'&Id=$in:' + '|'.join(season_field_ids)
+'&$limit=none'
)

response = self.http_client.get(mdm_url)

dict_response = response.json()

if response.status_code == 200:
return dict_response
raise ValueError(
f"Cannot handle HTTP response : {str(response.status_code)} : {str(dict_response)}"
)
Loading
Loading