Skip to content

Commit

Permalink
Merge branch 'main' into issue-21-parameter-name
Browse files Browse the repository at this point in the history
  • Loading branch information
Teddy-1000 committed Feb 6, 2024
2 parents a8b3360 + 85d290b commit 00f099c
Show file tree
Hide file tree
Showing 12 changed files with 621 additions and 373 deletions.
13 changes: 7 additions & 6 deletions api/routers/edr.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@
# Maybe it would be better to only query a limited set of data instead of everything (meaning 24 hours)
async def get_locations(bbox: str = Query(..., example="5.0,52.0,6.0,52.1")) -> FeatureCollection: # Hack to use string
left, bottom, right, top = map(str.strip, bbox.split(","))
print("bbox: {}".format(bbox))
poly = geometry.Polygon([(left, bottom), (right, bottom), (right, top), (left, top)])
ts_request = dstore.GetObsRequest(
instruments=["tn"], # Hack
filter=dict(instrument=dstore.Strings(values=["tn"])), # Hack
inside=dstore.Polygon(points=[dstore.Point(lat=coord[1], lon=coord[0]) for coord in poly.exterior.coords]),
)

Expand Down Expand Up @@ -71,7 +72,10 @@ async def get_data_location_id(
range = get_datetime_range(datetime)
standard_name, level, func, period = parse_parameter_name(parameter_name)
get_obs_request = dstore.GetObsRequest(
platforms=[location_id],
filter=dict(
platform=dstore.Strings(values=[location_id]),
instrument=dstore.Strings(values=list(map(str.strip, parameter_name.split(",")))),
),
interval=dstore.TimeInterval(start=range[0], end=range[1]) if range else None,
standard_name=standard_name,
level=level,
Expand Down Expand Up @@ -117,10 +121,7 @@ async def get_data_area(
range = get_datetime_range(datetime)
standard_name, level, func, period = parse_parameter_name(parameter_name)
get_obs_request = dstore.GetObsRequest(
standard_name=standard_name,
level=level,
func=func,
period=period,
filter=dict(instrument=dstore.Strings(values=list(map(str.strip, parameter_name.split(","))))),
inside=dstore.Polygon(points=[dstore.Point(lat=coord[1], lon=coord[0]) for coord in poly.exterior.coords]),
interval=dstore.TimeInterval(start=range[0], end=range[1]) if range else None,
)
Expand Down
35 changes: 18 additions & 17 deletions datastore/datastore/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,19 @@ go mod tidy

The following environment variables are supported:

Variable | Mandatory | Default value | Description
:-- | :-- | :-- | :--
`SERVERPORT` | No | `50050` | Server port number.
`PGHOST` | No | `localhost` | PostgreSQL host.
`PGPORT` | No | `5433` | PostgreSQL port number.
`PGBUSER` | No | `postgres` | PostgreSQL user name.
`PGPASSWORD` | No | `mysecretpassword` | PostgreSQL password.
`PGDBNAME` | No | `data` | PostgreSQL database name.
`DYNAMICTIME` | No | `true` | Whether the valid time range is _dynamic_ or _static_ (defined below).
`LOTIME` | No | `86400` | The _earliest_ valid time as seconds to be either [1] subtracted from the current time (if the valid time range is _dynamic_) or [2] added to UNIX epoch (1970-01-01T00:00:00Z) (if the valid time range is _static_). In the case of a _static_ valid time range, the `LOTIME` can optionally be specified as an ISO-8601 datetime of the exact form `2023-10-10T00:00:00Z`.
`HITIME` | No | `-2` | Same as `LOTIME`, but for the _latest_ valid time. Note a default leeway of 2 seconds into the future to reduce risk of missing the newest observations.
`CLEANUPINTERVAL` | No | `86400` | The minimum time duration in seconds between automatic cleanups (like removing obsolete observations from the physical store).
`PUTOBSLIMIT` | No | `100000` | Maximum number of observations allowed in a single call to `PutObservations`.
| Variable | Mandatory | Default value | Description |
| :-- | :-- | :-- | :-- |
| `SERVERPORT` | No | `50050` | Server port number. |
| `PGHOST` | No | `localhost` | PostgreSQL host. |
| `PGPORT` | No | `5433` | PostgreSQL port number. |
| `PGBUSER` | No | `postgres` | PostgreSQL user name. |
| `PGPASSWORD` | No | `mysecretpassword` | PostgreSQL password. |
| `PGDBNAME` | No | `data` | PostgreSQL database name. |
| `DYNAMICTIME` | No | `true` | Whether the valid time range is _dynamic_ or _static_ (defined below). |
| `LOTIME` | No | `86400` | The _earliest_ valid time as seconds to be either [1] subtracted from the current time (if the valid time range is _dynamic_) or [2] added to UNIX epoch (1970-01-01T00:00:00Z) (if the valid time range is _static_). In the case of a _static_ valid time range, the `LOTIME` can optionally be specified as an ISO-8601 datetime of the exact form `2023-10-10T00:00:00Z`. |
| `HITIME` | No | `-2` | Same as `LOTIME`, but for the _latest_ valid time. Note a default leeway of 2 seconds into the future to reduce risk of missing the newest observations. |
| `CLEANUPINTERVAL` | No | `86400` | The minimum time duration in seconds between automatic cleanups (like removing obsolete observations from the physical store). |
| `PUTOBSLIMIT` | No | `100000` | Maximum number of observations allowed in a single call to `PutObservations`. |

**TODO:** Ensure that these variables are [passed properly](https://docs.docker.com/compose/environment-variables/set-environment-variables/) to the relevant `docker compose`
commands. Any secrets should be passed using a [special mechanism](https://docs.docker.com/compose/use-secrets/), etc.
Expand All @@ -175,8 +175,9 @@ datastore.Datastore
$ grpcurl -plaintext -proto protobuf/datastore.proto describe
datastore.Datastore is a service:
service Datastore {
rpc GetObservations ( .datastore.GetObsRequest ) returns ( .datastore.GetObsResponse );
rpc PutObservations ( .datastore.PutObsRequest ) returns ( .datastore.PutObsResponse );
// get temporal and spatial extents of current storage contents
rpc GetExtents ( .datastore.GetExtentsRequest ) returns ( .datastore.GetExtentsResponse );
...
}
```

Expand All @@ -185,6 +186,7 @@ service Datastore {
```text
$ grpcurl -plaintext -proto protobuf/datastore.proto describe datastore.Datastore.PutObservations
datastore.Datastore.PutObservations is a method:
// insert observations into the storage (or update existing ones)
rpc PutObservations ( .datastore.PutObsRequest ) returns ( .datastore.PutObsResponse );
```

Expand Down Expand Up @@ -234,9 +236,8 @@ $ grpcurl -d '{"interval": {"start": "2023-01-01T00:00:00Z", "end": "2023-01-01T
```

### Retrieve wind speed and air temperature observations in a time range and a polygon

```text
$ grpcurl -d '{"standard_names": ["wind_speed", "air_temperature"], "interval": {"start": "2023-01-01T00:00:00Z", "end": "2023-01-01T00:00:10Z"}, "inside": {"points": [{"lat": 59.90, "lon": 10.70}, {"lat": 59.90, "lon": 10.80}, {"lat": 60, "lon": 10.80}, {"lat": 60, "lon": 10.70}]}}' -plaintext -proto protobuf/datastore.proto 127.0.0.1:50050 datastore.Datastore.GetObservations
$ grpcurl -d '{"filter": {"standard_name": {"values": ["wind_speed", "air_temperature"]}}, "interval": {"start": "2023-01-01T00:00:00Z", "end": "2023-01-01T00:00:10Z"}, "inside": {"points": [{"lat": 59.90, "lon": 10.70}, {"lat": 59.90, "lon": 10.80}, {"lat": 60, "lon": 10.80}, {"lat": 60, "lon": 10.70}]}}' -plaintext -proto protobuf/datastore.proto 127.0.0.1:50050 datastore.Datastore.GetObservations
...
```

Expand Down
Loading

1 comment on commit 00f099c

@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%23–68
datastore_pb2_grpc.py43430%2–225
dependencies.py72703%3–113
grpc_getter.py13130%1–23
locustfile.py15150%1–31
main.py22220%3–51
metadata_endpoints.py19190%1–70
formatters
   \_\_init\_\_.py12650%16–32
   base_formatter.py7186%18
   covjson.py522944%32–33, 37–87, 92–101
routers
   \_\_init\_\_.py00100% 
   edr.py51510%2–130
   records.py00100% 
test
   test_covjson.py604623%13–38, 42–64, 68–89, 93–102, 106–108, 112–113
   test_parse_parameter_name.py28267%4–51
TOTAL45238714% 

API Unit Test Coverage Summary

Tests Skipped Failures Errors Time
1 0 💤 0 ❌ 1 🔥 1.096s ⏱️

Please sign in to comment.