Skip to content

Commit

Permalink
Merge pull request #209 from EURODEO/issue_194_204-data-loader-to-ingest
Browse files Browse the repository at this point in the history
ObservedProperty label & test data loader through ingestion
  • Loading branch information
fjugipe authored Nov 19, 2024
2 parents 5d239ce + 2347b27 commit 3f3a241
Show file tree
Hide file tree
Showing 35 changed files with 1,033 additions and 1,144 deletions.
72 changes: 36 additions & 36 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
run: just services

- name: Load the data into the database
run: just load
run: just ingest-load

- name: Run the integration test
run: just integration
Expand Down Expand Up @@ -113,56 +113,56 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
architecture: x64
- name: Checkout Source
uses: actions/checkout@v4

- name: Install Dependencies
run: |
pip install --upgrade pip
pip install pytest-timeout
pip install pytest-cov
pip install httpx
pip install -r ./ingest/requirements.txt
pip install ./ingest
cd ./ingest && python3 api/generate_standard_name.py
- name: Install just
run: ./ci/scripts/install-just.sh

- name: Copy protobuf files
run: just copy-proto

- name: Copy Protobuf file to api directory and build
run: |
mkdir ./ingest/protobuf
cp ./protobuf/datastore.proto ./ingest/protobuf/datastore.proto
python -m grpc_tools.protoc --proto_path=./ingest/protobuf --python_out=./ingest --grpc_python_out=./ingest ./ingest/protobuf/datastore.proto
- name: Run the unit test
run: just ingest-unit

- name: Run Tests
run: |
cd ingest
mkdir -p /tmp/metrics
PROMETHEUS_MULTIPROC_DIR=/tmp/metrics python -m pytest -v --timeout=60
- name: Archive test artifacts
uses: actions/upload-artifact@v4
with:
name: ingest-test-results-artifact
path: |
ingest/test/output/pytest-coverage.txt
ingest/test/output/pytest.xml
- name: Cleanup
if: always()
run: just destroy

publish-test-results:
needs: test-datastore
needs:
- test-datastore
- test-ingest
runs-on: ubuntu-latest
if: github.event.ref_type != 'tag'
if: github.event_name != 'push' || github.event.ref_type != 'tag'
permissions:
contents: write
issues: write
pull-requests: write
steps:
- name: Download test results so that they can be published
- name: Download test-datastore results so that they can be published
uses: actions/download-artifact@v4
with:
name: test-results-artifact
path: ./artifacts/test-results

- name: Download test-ingest results so that they can be published
uses: actions/download-artifact@v4
with:
name: ingest-test-results-artifact
path: ./artifacts/ingest-results

- name: Comment coverage
uses: MishaKav/pytest-coverage-comment@main
with:
pytest-coverage-path: api/test/output/pytest-coverage.txt
coverage-path-prefix: api/test/output/
title: API Unit Test Coverage Report
hide-badge: true
hide-report: false
create-new-comment: false
hide-comment: false
report-only-changed-files: false
remove-link-from-badge: false
junitxml-path: api/test/output/pytest.xml
junitxml-title: API Unit Test Coverage Summary
title: Unit Test Coverage Report
pytest-coverage-path: ./artifacts/test-results/api/test/output/pytest-coverage.txt
multiple-files: |
API Unit Tests, ./artifacts/test-results/api/test/output/pytest-coverage.txt, ./artifacts/test-results/api/test/output/pytest.xml
Ingest Unit Tests, ./artifacts/ingest-results/pytest-coverage.txt, ./artifacts/ingest-results/pytest.xml
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,4 @@ cf_standard_names_v84.txt
# API
api/test/output/
datastore/load-test/output/
ingest/test/output/
6 changes: 3 additions & 3 deletions api/formatters/covjson.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
def make_parameter(ts_mdata):
level = convert_cm_to_m(ts_mdata.level)
period = seconds_to_iso_8601_duration(ts_mdata.period)
label = " ".join(ts_mdata.standard_name.capitalize().split("_"))

custom_fields = {
"rodeo:standard_name": ts_mdata.standard_name,
Expand All @@ -40,12 +41,11 @@ def make_parameter(ts_mdata):

return Parameter(
description={
"en": f"{ts_mdata.standard_name} at {level}m, "
f"aggregated over {period} with method '{ts_mdata.function}'",
"en": f"{label} at {level}m, aggregated over {period} with method '{ts_mdata.function}'",
},
observedProperty=ObservedProperty(
id=f"https://vocab.nerc.ac.uk/standard_name/{ts_mdata.standard_name}",
label={"en": ts_mdata.parameter_name},
label={"en": label},
),
measurementType=MeasurementType(
method=ts_mdata.function,
Expand Down
5 changes: 3 additions & 2 deletions api/metadata_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,18 @@ async def get_collection_metadata(base_url: str, is_self) -> Collection:
ts = group.combo
level = convert_cm_to_m(ts.level)
period = seconds_to_iso_8601_duration(ts.period)
label = " ".join(ts.standard_name.capitalize().split("_"))

custom_fields = {
"rodeo:standard_name": ts.standard_name,
"rodeo:level": level,
}

parameter = Parameter(
description=f"{ts.standard_name} at {level}m, aggregated over {period} with method '{ts.function}'",
description=f"{label} at {level}m, aggregated over {period} with method '{ts.function}'",
observedProperty=ObservedProperty(
id=f"https://vocab.nerc.ac.uk/standard_name/{ts.standard_name}",
label=ts.parameter_name,
label=label,
),
measurementType=MeasurementType(
method=ts.function,
Expand Down
12 changes: 6 additions & 6 deletions api/test/test_data/test_coverages_covjson.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@
"air_temperature:2.0:mean:PT1M": {
"type": "Parameter",
"description": {
"en": "air_temperature at 2.0m, aggregated over PT1M with method 'mean'"
"en": "Air temperature at 2.0m, aggregated over PT1M with method 'mean'"
},
"observedProperty": {
"id": "https://vocab.nerc.ac.uk/standard_name/air_temperature",
"label": {
"en": "air_temperature:2.0:mean:PT1M"
"en": "Air temperature"
}
},
"unit": {
Expand Down Expand Up @@ -139,12 +139,12 @@
"air_temperature:2.0:mean:PT1M": {
"type": "Parameter",
"description": {
"en": "air_temperature at 2.0m, aggregated over PT1M with method 'mean'"
"en": "Air temperature at 2.0m, aggregated over PT1M with method 'mean'"
},
"observedProperty": {
"id": "https://vocab.nerc.ac.uk/standard_name/air_temperature",
"label": {
"en": "air_temperature:2.0:mean:PT1M"
"en": "Air temperature"
}
},
"unit": {
Expand Down Expand Up @@ -186,12 +186,12 @@
"air_temperature:2.0:mean:PT1M": {
"type": "Parameter",
"description": {
"en": "air_temperature at 2.0m, aggregated over PT1M with method 'mean'"
"en": "Air temperature at 2.0m, aggregated over PT1M with method 'mean'"
},
"observedProperty": {
"id": "https://vocab.nerc.ac.uk/standard_name/air_temperature",
"label": {
"en": "air_temperature:2.0:mean:PT1M"
"en": "Air temperature"
}
},
"unit": {
Expand Down
8 changes: 4 additions & 4 deletions api/test/test_data/test_feature_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@
"air_pressure_at_sea_level:1.0:mean:PT1M": {
"type": "Parameter",
"description": {
"en": "air_pressure_at_sea_level at 1.0m, aggregated over PT1M with method 'mean'"
"en": "Air pressure at sea level at 1.0m, aggregated over PT1M with method 'mean'"
},
"observedProperty": {
"id": "https://vocab.nerc.ac.uk/standard_name/air_pressure_at_sea_level",
"label": {
"en": "air_pressure_at_sea_level:1.0:mean:PT1M"
"en": "Air pressure at sea level"
}
},
"unit": {
Expand All @@ -67,12 +67,12 @@
"air_temperature:0.1:minimum:PT10M": {
"type": "Parameter",
"description": {
"en": "air_temperature at 0.1m, aggregated over PT10M with method 'minimum'"
"en": "Air temperature at 0.1m, aggregated over PT10M with method 'minimum'"
},
"observedProperty": {
"id": "https://vocab.nerc.ac.uk/standard_name/air_temperature",
"label": {
"en": "air_temperature:0.1:minimum:PT10M"
"en": "Air temperature"
}
},
"unit": {
Expand Down
12 changes: 6 additions & 6 deletions api/test/test_data/test_multiple_covjson.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@
"relative_humidity:2.0:mean:PT1M": {
"type": "Parameter",
"description": {
"en": "relative_humidity at 2.0m, aggregated over PT1M with method 'mean'"
"en": "Relative humidity at 2.0m, aggregated over PT1M with method 'mean'"
},
"observedProperty": {
"id": "https://vocab.nerc.ac.uk/standard_name/relative_humidity",
"label": {
"en": "relative_humidity:2.0:mean:PT1M"
"en": "Relative humidity"
}
},
"unit": {
Expand All @@ -71,12 +71,12 @@
"wind_from_direction:2.0:mean:PT10M": {
"type": "Parameter",
"description": {
"en": "wind_from_direction at 2.0m, aggregated over PT10M with method 'mean'"
"en": "Wind from direction at 2.0m, aggregated over PT10M with method 'mean'"
},
"observedProperty": {
"id": "https://vocab.nerc.ac.uk/standard_name/wind_from_direction",
"label": {
"en": "wind_from_direction:2.0:mean:PT10M"
"en": "Wind from direction"
}
},
"unit": {
Expand All @@ -94,12 +94,12 @@
"wind_speed:10.0:mean:PT10M": {
"type": "Parameter",
"description": {
"en": "wind_speed at 10.0m, aggregated over PT10M with method 'mean'"
"en": "Wind speed at 10.0m, aggregated over PT10M with method 'mean'"
},
"observedProperty": {
"id": "https://vocab.nerc.ac.uk/standard_name/wind_speed",
"label": {
"en": "wind_speed:10.0:mean:PT10M"
"en": "Wind speed"
}
},
"unit": {
Expand Down
4 changes: 2 additions & 2 deletions api/test/test_data/test_single_covjson.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@
"wind_speed:10.0:mean:PT10M": {
"type": "Parameter",
"description": {
"en": "wind_speed at 10.0m, aggregated over PT10M with method 'mean'"
"en": "Wind speed at 10.0m, aggregated over PT10M with method 'mean'"
},
"observedProperty": {
"id": "https://vocab.nerc.ac.uk/standard_name/wind_speed",
"label": {
"en": "wind_speed:10.0:mean:PT10M"
"en": "Wind speed"
}
},
"unit": {
Expand Down
11 changes: 11 additions & 0 deletions datastore/data-loader/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ FROM python:3.11-slim-bookworm

SHELL ["/bin/bash", "-eux", "-o", "pipefail", "-c"]

ARG THROUGH_INGEST=false
ENV DOCKER_PATH="/clients/python"

COPY "test-data/KNMI/20221231.nc" "${DOCKER_PATH}/test-data/KNMI/20221231.nc"
Expand Down Expand Up @@ -29,7 +30,17 @@ RUN python -m grpc_tools.protoc \
--grpc_python_out="${DOCKER_PATH}"

COPY "./parameters.py" "${DOCKER_PATH}/parameters.py"
COPY "./utilities.py" "${DOCKER_PATH}/utilities.py"

# Copy both loaders and conditionally use the wanted one
COPY "./client_knmi_station_ingest.py" "${DOCKER_PATH}/client_knmi_station_ingest.py"
COPY "./client_knmi_station.py" "${DOCKER_PATH}/client_knmi_station.py"

RUN if [ "${THROUGH_INGEST}" = "true" ]; then \
mv "${DOCKER_PATH}/client_knmi_station_ingest.py" "${DOCKER_PATH}/client_knmi_station.py"; \
else \
rm "${DOCKER_PATH}/client_knmi_station_ingest.py"; \
fi

WORKDIR "${DOCKER_PATH}"
CMD ["python", "-u", "./client_knmi_station.py"]
Loading

1 comment on commit 3f3a241

@github-actions
Copy link

Choose a reason for hiding this comment

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

Coverage

Unit Test Coverage Report
FileStmtsMissCoverMissing
__init__.py00100% 
datastore_pb2.py614821%34–81
datastore_pb2_grpc.py542750%15–16, 19, 65–80, 121–123, 128–130, 135–137, 142–144, 148–173, 219, 246, 273, 300
export_metrics.py100100% 
grpc_getter.py201145%15–19, 23–26, 30–32, 36–38
locustfile.py15150%1–31
main.py43784%45, 50, 60, 70–71, 81–82
metadata_endpoints.py663252%45–54, 58, 85, 100–220, 224
response_classes.py50100% 
utilities.py1744674%20, 38, 45, 67–70, 78–89, 94–101, 121, 125, 127, 155, 161, 179, 193–194, 198, 214–218, 222–228, 232–234, 264, 268, 290, 295
custom_geo_json
   edr_feature_collection.py60100% 
formatters
   __init__.py110100% 
   covjson.py60198%91
   geojson.py21290%27, 52
openapi
   custom_dimension_examples.py40100% 
   edr_query_parameter_descriptions.py110100% 
   openapi_examples.py130100% 
routers
   __init__.py00100% 
   edr.py101496%348–349, 438–439
   feature.py471960%99–132, 148–153, 159–181
TOTAL72221271% 

Title Coverage Tests Skipped Failures Errors Time
API Unit Tests Coverage 30 0 💤 0 ❌ 0 🔥 1.815s ⏱️
Ingest Unit Tests Coverage 16 0 💤 0 ❌ 0 🔥 1m 44s ⏱️

Please sign in to comment.