Skip to content

Commit

Permalink
Cli/Restapi: Return empty values if no data is available
Browse files Browse the repository at this point in the history
  • Loading branch information
gutzbenj committed Mar 9, 2024
1 parent 3a60732 commit 80cf726
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Development
***********

- Docker: Install more extras
- Cli/Restapi: Return empty values if no data is available

0.77.1 (08.03.2024)
*******************
Expand Down
17 changes: 17 additions & 0 deletions tests/ui/test_restapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,23 @@ def test_api_values_missing_null(client):
assert response.json()["values"][0]["quality"] is None


@pytest.mark.remote
def test_api_values_missing_empty(client):
response = client.get(
"/api/values",
params={
"provider": "dwd",
"network": "observation",
"station": "00011",
"parameter": "precipitation_height",
"resolution": "1_minute",
"period": "recent",
},
)
assert response.status_code == 200
assert not response.json()["values"]


@pytest.mark.remote
def test_api_stations_missing_null(client):
response = client.get(
Expand Down
17 changes: 11 additions & 6 deletions wetterdienst/ui/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@

from wetterdienst.core.process import create_date_range
from wetterdienst.core.timeseries.request import TimeseriesRequest
from wetterdienst.core.timeseries.result import StationsResult, ValuesResult
from wetterdienst.core.timeseries.result import (
InterpolatedValuesResult,
StationsResult,
SummarizedValuesResult,
ValuesResult,
)
from wetterdienst.metadata.datarange import DataRange
from wetterdienst.metadata.period import PeriodType
from wetterdienst.metadata.resolution import Resolution, ResolutionType
Expand Down Expand Up @@ -285,7 +290,7 @@ def get_values(
else:
if values_.df.is_empty():
log.error("No data available for given constraints")
sys.exit(1)
return values_

if sql_values:
log.info(f"Filtering with SQL: {sql_values}")
Expand All @@ -309,7 +314,7 @@ def get_interpolate(
si_units: bool,
humanize: bool,
use_nearby_station_distance: float,
) -> ValuesResult:
) -> InterpolatedValuesResult:
"""Core function for querying values via cli and restapi"""
r = _get_stations_request(
api=api,
Expand Down Expand Up @@ -341,7 +346,7 @@ def get_interpolate(
else:
if values_.df.is_empty():
log.error("No data available for given constraints")
sys.exit(1)
return values_

if sql_values:
log.info(f"Filtering with SQL: {sql_values}")
Expand All @@ -363,7 +368,7 @@ def get_summarize(
sql_values: str,
si_units: bool,
humanize: bool,
) -> ValuesResult:
) -> SummarizedValuesResult:
"""Core function for querying values via cli and restapi"""
r = _get_stations_request(
api=api,
Expand Down Expand Up @@ -395,7 +400,7 @@ def get_summarize(
else:
if values_.df.is_empty():
log.error("No data available for given constraints")
sys.exit(1)
return values_

if sql_values:
log.info(f"Filtering with SQL: {sql_values}")
Expand Down

0 comments on commit 80cf726

Please sign in to comment.