Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
gutzbenj committed Nov 20, 2024
1 parent c8367f3 commit 1db939b
Show file tree
Hide file tree
Showing 15 changed files with 49 additions and 9 deletions.
6 changes: 2 additions & 4 deletions tests/ui/cli/test_cli_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@
(
"dwd",
"mosmix",
"--parameter=hourly/large "
f"--date={datetime.strftime(datetime.today() + timedelta(days=2), '%Y-%m-%d')}",
"--parameter=hourly/large " f"--date={datetime.strftime(datetime.today() + timedelta(days=2), '%Y-%m-%d')}",
"10488",
"DRESDEN",
),
(
"dwd",
"dmo",
"--parameter=hourly/icon "
f"--date={datetime.strftime(datetime.today() + timedelta(days=2), '%Y-%m-%d')}",
"--parameter=hourly/icon " f"--date={datetime.strftime(datetime.today() + timedelta(days=2), '%Y-%m-%d')}",
"10488",
"DRESDEN",
),
Expand Down
24 changes: 19 additions & 5 deletions wetterdienst/metadata/metadata_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from dataclasses import dataclass
from typing import TYPE_CHECKING

from pydantic import BaseModel, Field, SkipValidation
from pydantic import BaseModel, Field, SkipValidation, field_validator

from wetterdienst import Period, Resolution # noqa: TCH001, needs to stay here for pydantic model to work
from wetterdienst.util.python import to_list
Expand Down Expand Up @@ -46,8 +46,9 @@ class DatasetModel(BaseModel):
name: str
name_original: str
grouped: bool # if parameters are grouped together e.g. in one file
periods: list[Period] | None = None
periods: list[Period]
description: str | None = None
date_required: bool
parameters: list[ParameterModel]
resolution: SkipValidation[ResolutionModel] = Field(default=None, exclude=True, repr=False)

Expand Down Expand Up @@ -90,16 +91,29 @@ class ResolutionModel(BaseModel):
name: str
name_original: str
value: Resolution = Field(alias="name", exclude=True, repr=False) # this is just to make the code more readable
datasets: list[DatasetModel]
periods: list[Period] | None = None
description: str | None = None
date_required: bool | None = None
datasets: list[DatasetModel]

@field_validator("datasets", mode="before")
def validate_datasets(cls, v, validation_info):
periods = validation_info.data["periods"]
date_required = validation_info.data["date_required"]
if periods:
for dataset in v:
if not dataset.get("periods"):
dataset["periods"] = periods
if date_required is not None:
for dataset in v:
if dataset.get("date_required") is None:
dataset["date_required"] = date_required
return v

def __init__(self, **data):
super().__init__(**data)
for dataset in self.datasets:
dataset.resolution = self
# propagate periods to dataset
dataset.periods = dataset.periods or self.periods

def __getitem__(self, item):
if isinstance(item, int):
Expand Down
1 change: 1 addition & 0 deletions wetterdienst/provider/dwd/dmo/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"name": "hourly",
"name_original": "hourly",
"periods": ["future"],
"date_required": True,
"datasets": [
{
"name": "icon_eu",
Expand Down
1 change: 1 addition & 0 deletions wetterdienst/provider/dwd/mosmix/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"name": "hourly",
"name_original": "hourly",
"periods": ["future"],
"date_required": True,
"datasets": [
{
"name": "small",
Expand Down
8 changes: 8 additions & 0 deletions wetterdienst/provider/dwd/observation/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"name": "1_minute",
"name_original": "1_minute",
"periods": ["historical", "recent", "now"],
"date_required": False,
"datasets": [
{
"name": "precipitation",
Expand Down Expand Up @@ -52,6 +53,7 @@
"name": "5_minutes",
"name_original": "5_minutes",
"periods": ["historical", "recent", "now"],
"date_required": False,
"datasets": [
{
"name": "precipitation",
Expand Down Expand Up @@ -96,6 +98,7 @@
"name": "10_minutes",
"name_original": "10_minutes",
"periods": ["historical", "recent", "now"],
"date_required": False,
"datasets": [
{
"name": "precipitation",
Expand Down Expand Up @@ -308,6 +311,7 @@
"name": "hourly",
"name_original": "hourly",
"periods": ["historical", "recent"],
"date_required": False,
"datasets": [
{
"name": "cloud_type",
Expand Down Expand Up @@ -1001,6 +1005,7 @@
"name": "subdaily",
"name_original": "subdaily",
"periods": ["historical", "recent"],
"date_required": False,
"datasets": [
{
"name": "cloudiness",
Expand Down Expand Up @@ -1198,6 +1203,7 @@
"name": "daily",
"name_original": "daily",
"periods": ["historical", "recent"],
"date_required": False,
"datasets": [
{
"name": "climate_summary",
Expand Down Expand Up @@ -1567,6 +1573,7 @@
"name": "monthly",
"name_original": "monthly",
"periods": ["historical", "recent"],
"date_required": False,
"datasets": [
{
"name": "climate_summary",
Expand Down Expand Up @@ -1757,6 +1764,7 @@
"name": "annual",
"name_original": "annual",
"periods": ["historical", "recent"],
"date_required": False,
"datasets": [
{
"name": "climate_summary",
Expand Down
1 change: 1 addition & 0 deletions wetterdienst/provider/dwd/road/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
{
"name": "15_minutes",
"name_original": "15_minutes",
"date_required": True,
"datasets": [
{
"name": DATASET_NAME_DEFAULT,
Expand Down
5 changes: 5 additions & 0 deletions wetterdienst/provider/ea/hydrology/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"name": "15_minutes",
"name_original": "15_minutes",
"periods": ["historical"],
"date_required": True,
"datasets": [
{
"name": "observations",
Expand All @@ -52,6 +53,8 @@
{
"name": "6_hour",
"name_original": "6_hour",
"periods": ["historical"],
"date_required": True,
"datasets": [
{
"name": "observations",
Expand All @@ -77,6 +80,8 @@
{
"name": "daily",
"name_original": "daily",
"periods": ["historical"],
"date_required": True,
"datasets": [
{
"name": DATASET_NAME_DEFAULT,
Expand Down
1 change: 1 addition & 0 deletions wetterdienst/provider/eaufrance/hubeau/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"name": "dynamic",
"name_original": "dynamic",
"periods": ["historical"],
"date_required": True,
"datasets": [
{
"name": DATASET_NAME_DEFAULT,
Expand Down
4 changes: 4 additions & 0 deletions wetterdienst/provider/eccc/observation/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"name": "hourly",
"name_original": "hourly",
"periods": ["historical"],
"date_required": True,
"datasets": [
{
"name": DATASET_NAME_DEFAULT,
Expand Down Expand Up @@ -136,6 +137,7 @@
"name": "daily",
"name_original": "daily",
"periods": ["historical"],
"date_required": True,
"datasets": [
{
"name": DATASET_NAME_DEFAULT,
Expand Down Expand Up @@ -282,6 +284,7 @@
"name": "monthly",
"name_original": "monthly",
"periods": ["historical"],
"date_required": True,
"datasets": [
{
"name": DATASET_NAME_DEFAULT,
Expand Down Expand Up @@ -428,6 +431,7 @@
"name": "annual",
"name_original": "annual",
"periods": ["historical"],
"date_required": True,
"datasets": [
{
"name": DATASET_NAME_DEFAULT,
Expand Down
1 change: 1 addition & 0 deletions wetterdienst/provider/geosphere/observation/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"name": "10_minutes",
"name_original": "10_minutes",
"periods": ["historical"],
"date_required": True,
"datasets": [
{
"name": DATASET_NAME_DEFAULT,
Expand Down
1 change: 1 addition & 0 deletions wetterdienst/provider/imgw/hydrology/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"name": "daily",
"name_original": "dobowe",
"periods": ["historical"],
"date_required": True,
"datasets": [
{
"name": "hydrology",
Expand Down
1 change: 1 addition & 0 deletions wetterdienst/provider/imgw/meteorology/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"name": "daily",
"name_original": "dobowe",
"periods": ["historical"],
"date_required": True,
"datasets": [
{
"name": "climate",
Expand Down
2 changes: 2 additions & 0 deletions wetterdienst/provider/noaa/ghcn/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"name": "hourly",
"name_original": "hourly",
"periods": ["historical"],
"date_required": True,
"datasets": [
{
"name": DATASET_NAME_DEFAULT,
Expand Down Expand Up @@ -185,6 +186,7 @@
"name": "daily",
"name_original": "daily",
"periods": ["historical"],
"date_required": True,
"datasets": [
{
"name": DATASET_NAME_DEFAULT,
Expand Down
1 change: 1 addition & 0 deletions wetterdienst/provider/nws/observation/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"name": "hourly",
"name_original": "hourly",
"periods": ["recent"],
"date_required": True,
"datasets": [
{
"name": DATASET_NAME_DEFAULT,
Expand Down
1 change: 1 addition & 0 deletions wetterdienst/provider/wsv/pegel/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"name": "dynamic",
"name_original": "dynamic",
"periods": ["recent"],
"date_required": True,
"datasets": [
{
"name": DATASET_NAME_DEFAULT,
Expand Down

0 comments on commit 1db939b

Please sign in to comment.