geobeyond / Arpav-PPCV-backend

Backend di Piattaforma Proiezioni Climatiche per il Nord-Est.
Creative Commons Attribution 4.0 International
0 stars 1 forks source link

Generate time series for historical data #98

Closed ricardogsilva closed 3 months ago

ricardogsilva commented 3 months ago

This PR implements an API endpoint for getting time series for historical data from observation stations. It has been implemented mostly like what is described in #96, with the following exceptions:

Here is a sample screenshot for data retrieved by making the following request:

/api/v2/observations/time-series/91/TDd/1?
    datetime=../..&
    smoothing=NO_SMOOTHING&
    smoothing=MOVING_AVERAGE_5_YEARS&
    include_decade_data=true&
    include_mann_kendall_trend=true&
    mann_kendall_start_year=2003&
    mann_kendall_end_year=2008

image

The response also includes relevant additional information, like the mann-kendall test parameters, which in the example above are:

{
  "series": [
    {
      "name":"TDd__MANN_KENDALL",
      "values":[
        {"value":-8.8985,"datetime":"2003-01-01T00:00:00Z"},
        ...
      ],
      "info":{
        "trend":"no trend",
        "h":0.0,
        "p":0.2596563563704499,
        "z":1.1272037239532693,
        "tau":0.4666666666666667,
        "s":7.0,
        "var_s":28.333333333333332,
        "slope":1.076,
        "intercept":-8.8985
      }
    },
    ...
  ]
}

Note: I'm not 100% sure whether the mann-kendall filtering is implemented correctly, but I think we can discuss the details and improve it after this PR is merged.