Skip to content

Commit

Permalink
Ported client code to new gRPC API
Browse files Browse the repository at this point in the history
Attribute fields now use singular form (instruments -> instrument) for
consistency and simplification (in particular when using reflection).
  • Loading branch information
jo-asplin-met-no committed Jan 10, 2024
1 parent bb59242 commit 707ddce
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions datastore/api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def get_locations(bbox: str = Query(..., example="5.0,52.0,6.0,52.1")) -> Featur
with grpc.insecure_channel(f"{os.getenv('DSHOST', 'localhost')}:{os.getenv('DSPORT', '50050')}") as channel:
grpc_stub = dstore_grpc.DatastoreStub(channel)
ts_request = dstore.GetObsRequest(
instruments=["tn"], # Hack
instrument=["tn"], # Hack
inside=dstore.Polygon(points=[dstore.Point(lat=coord[1], lon=coord[0]) for coord in poly.exterior.coords]),
)
ts_response = grpc_stub.GetObservations(ts_request)
Expand Down Expand Up @@ -227,8 +227,8 @@ def get_data_location_id(
# This is just a quick and dirty demo
range = get_datetime_range(datetime)
get_obs_request = dstore.GetObsRequest(
platforms=[location_id],
instruments=list(map(str.strip, parameter_name.split(","))),
platform=[location_id],
instrument=list(map(str.strip, parameter_name.split(","))),
interval=dstore.TimeInterval(start=range[0], end=range[1]) if range else None,
)
return get_data_for_time_series(get_obs_request)
Expand Down
12 changes: 6 additions & 6 deletions datastore/integration-test/test_knmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def grpc_stub():


def test_find_series_single_station_single_parameter(grpc_stub):
request = dstore.GetObsRequest(platforms=["06260"], instruments=["rh"])
request = dstore.GetObsRequest(platform=["06260"], instrument=["rh"])
response = grpc_stub.GetObservations(request)

assert len(response.observations) == 1
Expand All @@ -30,21 +30,21 @@ def test_find_series_single_station_single_parameter(grpc_stub):


def test_find_series_all_stations_single_parameter(grpc_stub):
request = dstore.GetObsRequest(instruments=["rh"])
request = dstore.GetObsRequest(instrument=["rh"])
response = grpc_stub.GetObservations(request)

assert len(response.observations) == 46 # Not all station have RH


def test_find_series_single_station_all_parameters(grpc_stub):
request = dstore.GetObsRequest(platforms=["06260"])
request = dstore.GetObsRequest(platform=["06260"])
response = grpc_stub.GetObservations(request)

assert len(response.observations) == 42 # Station 06260 doesn't have all parameters


def test_get_values_single_station_single_parameter(grpc_stub):
ts_request = dstore.GetObsRequest(platforms=["06260"], instruments=["rh"])
ts_request = dstore.GetObsRequest(platform=["06260"], instrument=["rh"])
response = grpc_stub.GetObservations(ts_request)

assert len(response.observations) == 1
Expand All @@ -60,7 +60,7 @@ def test_get_values_single_station_single_parameter_one_hour(grpc_stub):
end_datetime.FromDatetime(datetime(2022, 12, 31, 12))

ts_request = dstore.GetObsRequest(
platforms=["06260"], instruments=["rh"], interval=dstore.TimeInterval(start=start_datetime, end=end_datetime)
platform=["06260"], instrument=["rh"], interval=dstore.TimeInterval(start=start_datetime, end=end_datetime)
)
response = grpc_stub.GetObservations(ts_request)

Expand Down Expand Up @@ -148,7 +148,7 @@ def test_get_values_single_station_single_parameter_one_hour(grpc_stub):
@pytest.mark.parametrize("coords,param_ids,expected_station_ids", input_params_polygon)
def test_get_observations_with_polygon(grpc_stub, coords, param_ids, expected_station_ids):
polygon = dstore.Polygon(points=[dstore.Point(lat=lat, lon=lon) for lat, lon in coords])
get_obs_request = dstore.GetObsRequest(inside=polygon, instruments=param_ids)
get_obs_request = dstore.GetObsRequest(inside=polygon, instrument=param_ids)
get_obs_response = grpc_stub.GetObservations(get_obs_request)

actual_station_ids = sorted({ts.ts_mdata.platform for ts in get_obs_response.observations})
Expand Down
6 changes: 3 additions & 3 deletions datastore/load-test/locustfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def get_data_for_single_timeserie(self):

request = dstore.GetObsRequest(
interval=dstore.TimeInterval(start=from_time, end=to_time),
platforms=[random.choice(stations)],
instruments=[random.choice(parameters)],
platform=[random.choice(stations)],
instrument=[random.choice(parameters)],
)
response = self.stub.GetObservations(request)
assert len(response.observations) == 1
Expand All @@ -63,7 +63,7 @@ def get_data_single_station_through_bbox(self):

request = dstore.GetObsRequest(
interval=dstore.TimeInterval(start=from_time, end=to_time),
instruments=[random.choice(parameters)],
instrument=[random.choice(parameters)],
inside=dstore.Polygon(points=[dstore.Point(lat=coord[1], lon=coord[0]) for coord in poly.exterior.coords]),
)
response = self.stub.GetObservations(request)
Expand Down

0 comments on commit 707ddce

Please sign in to comment.