Skip to content

Commit

Permalink
Added name of station to time series output schema (#260)
Browse files Browse the repository at this point in the history
* Added name of station to time series output schema

* Complete adding station name to time series payload
  • Loading branch information
ricardogsilva authored Oct 4, 2024
1 parent 29b26c0 commit c4da393
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 28 deletions.
20 changes: 14 additions & 6 deletions arpav_ppcv/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,11 @@ def get_coverage_time_series(
],
Optional[
dict[
tuple[observations.Variable, base.ObservationDataSmoothingStrategy],
tuple[
observations.Station,
observations.Variable,
base.ObservationDataSmoothingStrategy,
],
pd.Series,
]
],
Expand Down Expand Up @@ -705,7 +709,11 @@ def get_coverage_time_series(
),
)
observation_result[
(variable, base.ObservationDataSmoothingStrategy.NO_SMOOTHING)
(
station,
variable,
base.ObservationDataSmoothingStrategy.NO_SMOOTHING,
)
] = station_df[variable.name].squeeze()
for smoothing_strategy in additional_observation_smoothing_strategies:
(
Expand All @@ -714,17 +722,17 @@ def get_coverage_time_series(
) = process_station_data_smoothing_strategy(
station_df, variable.name, smoothing_strategy
)
observation_result[(variable, smoothing_strategy)] = station_df[
smoothed_column
].squeeze()
observation_result[
(station, variable, smoothing_strategy)
] = station_df[smoothed_column].squeeze()
else:
logger.info("No station data found, skipping...")
else:
logger.info(
"Cannot include observation data - no observation variable is related "
"to this coverage configuration"
)
return (coverage_result, observation_result)
return coverage_result, observation_result


def extract_nearby_station_data(
Expand Down
2 changes: 2 additions & 0 deletions arpav_ppcv/schemas/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class StaticObservationSeriesParameter(enum.Enum):
SERIES_NAME = "SERIES_NAME"
PROCESSING_METHOD = "PROCESSING_METHOD"
VARIABLE = "VARIABLE"
STATION = "STATION"
SERIES_ELABORATION = "SERIES_ELABORATION"
DERIVED_SERIES = "DERIVED_SERIES"

Expand All @@ -109,6 +110,7 @@ def get_display_name(self, locale: babel.Locale) -> str:
self.SERIES_NAME.name: _("series name"),
self.PROCESSING_METHOD.name: _("processing method"),
self.VARIABLE.name: _("variable"),
self.STATION.name: _("station"),
self.SERIES_ELABORATION.name: _("series elaboration"),
self.DERIVED_SERIES.name: _("derived series"),
}[self.name] or self.name
Expand Down
3 changes: 3 additions & 0 deletions arpav_ppcv/schemas/observations.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ class Station(StationBase, table=True):
}
)

def __hash__(self):
return hash(self.id)


class StationCreate(sqlmodel.SQLModel):
code: str
Expand Down
24 changes: 14 additions & 10 deletions arpav_ppcv/translations/en/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2024-07-05 15:50+0000\n"
"POT-Creation-Date: 2024-10-04 16:08+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: en\n"
Expand Down Expand Up @@ -63,11 +63,11 @@ msgstr "LOESS"
msgid "centered 11-year moving average"
msgstr "Centered 11-year moving average"

#: schemas/base.py:91 schemas/base.py:109
#: schemas/base.py:91 schemas/base.py:110
msgid "series name"
msgstr "Series name"

#: schemas/base.py:92 schemas/base.py:110
#: schemas/base.py:92 schemas/base.py:111
msgid "processing method"
msgstr "Processing method"

Expand All @@ -79,30 +79,34 @@ msgstr "Coverage identifier"
msgid "coverage configuration"
msgstr "Coverage configuration"

#: schemas/base.py:111
#: schemas/base.py:112
msgid "variable"
msgstr "Variable"

#: schemas/base.py:112
#: schemas/base.py:113
msgid "station"
msgstr "Station"

#: schemas/base.py:114
msgid "series elaboration"
msgstr "Series elaboration"

#: schemas/base.py:113
#: schemas/base.py:115
msgid "derived series"
msgstr "Derived series"

#: schemas/base.py:125
#: schemas/base.py:127
msgid "original"
msgstr "Original"

#: schemas/base.py:126
#: schemas/base.py:128
msgid "derived"
msgstr "Derived"

#: schemas/base.py:138
#: schemas/base.py:140
msgid "decade series"
msgstr "Decade series"

#: schemas/base.py:139
#: schemas/base.py:141
msgid "Mann-Kendall series"
msgstr "Mann-Kendall series"
24 changes: 14 additions & 10 deletions arpav_ppcv/translations/it/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2024-07-05 15:50+0000\n"
"POT-Creation-Date: 2024-10-04 16:08+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: it\n"
Expand Down Expand Up @@ -63,11 +63,11 @@ msgstr "LOESS"
msgid "centered 11-year moving average"
msgstr "media mobile centrata a 11 anni"

#: schemas/base.py:91 schemas/base.py:109
#: schemas/base.py:91 schemas/base.py:110
msgid "series name"
msgstr "Nome della serie"

#: schemas/base.py:92 schemas/base.py:110
#: schemas/base.py:92 schemas/base.py:111
msgid "processing method"
msgstr "Metodo di elaborazione"

Expand All @@ -79,30 +79,34 @@ msgstr "Identificatore di copertura"
msgid "coverage configuration"
msgstr "Configurazione della copertura"

#: schemas/base.py:111
#: schemas/base.py:112
msgid "variable"
msgstr "Variabile"

#: schemas/base.py:112
#: schemas/base.py:113
msgid "station"
msgstr "Stazione"

#: schemas/base.py:114
msgid "series elaboration"
msgstr "elaborazione in serie"

#: schemas/base.py:113
#: schemas/base.py:115
msgid "derived series"
msgstr "Serie derivate"

#: schemas/base.py:125
#: schemas/base.py:127
msgid "original"
msgstr "Originale"

#: schemas/base.py:126
#: schemas/base.py:128
msgid "derived"
msgstr "Derivata"

#: schemas/base.py:138
#: schemas/base.py:140
msgid "decade series"
msgstr "serie decennale"

#: schemas/base.py:139
#: schemas/base.py:141
msgid "Mann-Kendall series"
msgstr "serie Mann-Kendall"
4 changes: 2 additions & 2 deletions arpav_ppcv/webapp/api_v2/routers/coverages.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,10 +719,10 @@ def get_time_series(
)
if observations_series is not None:
for observation_info, pd_series in observations_series.items():
variable, smoothing_strategy = observation_info
station, variable, smoothing_strategy = observation_info
series.append(
TimeSeries.from_observation_series(
pd_series, variable, smoothing_strategy
pd_series, station, variable, smoothing_strategy
)
)
return TimeSeriesList(series=series)
Expand Down
18 changes: 18 additions & 0 deletions arpav_ppcv/webapp/api_v2/schemas/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class TimeSeries(pydantic.BaseModel):
def from_observation_series(
cls,
series: pd.Series,
station: observations_schemas.Station,
variable: observations_schemas.Variable,
smoothing_strategy: base_schemas.ObservationDataSmoothingStrategy,
extra_info: typing.Optional[dict[str, str | int | float | dict]] = None,
Expand Down Expand Up @@ -120,6 +121,7 @@ def from_observation_series(
],
info={
"processing_method": smoothing_strategy.value,
"station": station.name,
"variable": variable.name,
"series_elaboration": series_elaboration.value,
"derived_series": (
Expand Down Expand Up @@ -153,6 +155,18 @@ def from_observation_series(
)
),
},
"station": {
LOCALE_EN.language: (
StaticObservationSeriesParameter.STATION.get_display_name(
LOCALE_EN
)
),
LOCALE_IT.language: (
StaticObservationSeriesParameter.STATION.get_display_name(
LOCALE_IT
)
),
},
"variable": {
LOCALE_EN.language: (
StaticObservationSeriesParameter.VARIABLE.get_display_name(
Expand Down Expand Up @@ -206,6 +220,10 @@ def from_observation_series(
LOCALE_IT.language: variable.display_name_italian
or variable.name,
},
"station": {
LOCALE_EN.language: station.name,
LOCALE_IT.language: station.name,
},
"series_elaboration": {
LOCALE_EN.language: series_elaboration.get_display_name(
LOCALE_EN
Expand Down

0 comments on commit c4da393

Please sign in to comment.