Skip to content

Commit

Permalink
Merge pull request #93 from EURODEO/issue_73_req_filtering
Browse files Browse the repository at this point in the history
Issue 73 - Refactor building ObsRequest optional filter parameters
  • Loading branch information
fjugipe authored Mar 27, 2024
2 parents 34f88fd + 04f0cdd commit b85a220
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions api/routers/edr.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,23 @@ async def get_data_location_id(
):
# TODO: There is no error handling of any kind at the moment!
# This is just a quick and dirty demo
range = get_datetime_range(datetime)
if parameter_name:
parameter_name = split_and_strip(parameter_name)
await verify_parameter_names(parameter_name)
request = dstore.GetObsRequest(
filter=dict(
parameter_name=dstore.Strings(values=parameter_name),
platform=dstore.Strings(values=[location_id]),
),
temporal_interval=(dstore.TimeInterval(start=range[0], end=range[1]) if range else None),
included_response_fields=response_fields_needed_for_data_api,
)

if parameter_name:
parameter_name = split_and_strip(parameter_name)
await verify_parameter_names(parameter_name)
request.filter["parameter_name"].values.extend(parameter_name)

if datetime:
start, end = get_datetime_range(datetime)
request.temporal_interval.start.CopyFrom(start)
request.temporal_interval.end.CopyFrom(end)

response = await get_obs_request(request)
return formatters.formatters[f](response)

Expand Down Expand Up @@ -262,18 +267,23 @@ async def get_data_area(
detail={"coords": f"Unexpected error occurred during wkt parsing: {coords}"},
)

range = get_datetime_range(datetime)
if parameter_name:
parameter_name = split_and_strip(parameter_name)
await verify_parameter_names(parameter_name)
request = dstore.GetObsRequest(
filter=dict(parameter_name=dstore.Strings(values=parameter_name if parameter_name else None)),
spatial_area=dstore.Polygon(
points=[dstore.Point(lat=coord[1], lon=coord[0]) for coord in poly.exterior.coords]
),
temporal_interval=dstore.TimeInterval(start=range[0], end=range[1]) if range else None,
included_response_fields=response_fields_needed_for_data_api,
)

if parameter_name:
parameter_name = split_and_strip(parameter_name)
await verify_parameter_names(parameter_name)
request.filter["parameter_name"].values.extend(parameter_name)

if datetime:
start, end = get_datetime_range(datetime)
request.temporal_interval.start.CopyFrom(start)
request.temporal_interval.end.CopyFrom(end)

coverages = await get_obs_request(request)
coverages = formatters.formatters[f](coverages)
return coverages

1 comment on commit b85a220

@github-actions
Copy link

Choose a reason for hiding this comment

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

API Unit Test Coverage Report
FileStmtsMissCoverMissing
\_\_init\_\_.py00100% 
datastore_pb2.py584621%24–69
datastore_pb2_grpc.py432347%37–52, 85–87, 92–94, 99–101, 106–108, 112–136, 174, 191, 208, 225
grpc_getter.py201145%15–16, 20–23, 27–29, 33–35
locustfile.py15150%1–31
main.py34585%41, 51–52, 62–63
metadata_endpoints.py552555%42–51, 55, 72–151, 155
utilities.py683253%15, 33, 40, 62–65, 73–80, 85–92, 104–123
custom_geo_json
   edr_feature_collection.py60100% 
formatters
   \_\_init\_\_.py110100% 
   covjson.py53198%75
   geojson.py15193%42
routers
   \_\_init\_\_.py00100% 
   edr.py1052675%59–134, 219–220, 264–265
   feature.py451958%70–103, 113–118, 124–146
TOTAL52820461% 

API Unit Test Coverage Summary

Tests Skipped Failures Errors Time
17 0 💤 0 ❌ 0 🔥 1.965s ⏱️

Please sign in to comment.