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

Add localization #159

Closed ricardogsilva closed 2 days ago

ricardogsilva commented 3 weeks ago

This PR adds localization to the backend, making it possible to translate the system to both Italian and English.

The backend deals with two types of translatable string:

This PR includes also the integration of these translated values in with the time series API endpoints, thus providing information to the frontend so that it may localize generated charts. This a sample request:

http://webapp:5001/api/v2/coverages/time-series/tas_seasonal_absolute_model_ensemble-rcp26-DJF
  coords==POINT(11.5469 44.9524)
  datetime==../..
  include_coverage_data==true
  include_observation_data==true
  coverage_data_smoothing==NO_SMOOTHING
  coverage_data_smoothing==MOVING_AVERAGE_11_YEARS
  include_coverage_uncertainty==true
  include_coverage_related_data==true

Would return a response that now includes extensive details about the configuration and translations:

[
  {
    "name": "tas_seasonal_absolute_model_ensemble-rcp26-DJF",
    "values": [...],
    "info": {
      "processing_method": "NO_SMOOTHING",
      "coverage_identifier": "tas_seasonal_absolute_model_ensemble-rcp26-DJF",
      "coverage_configuration": "tas_seasonal_absolute_model_ensemble",
      "scenario": "rcp26",
      "year_period": "DJF"
    },

    "translations": {
      "parameter_names": {
        "series_name": {
          "en": "series name",
          "it": "Nome della serie"
        },
        "processing_method": {
          "en": "processing method", 
          "it": "Metodo di elaborazione"
        },
        "coverage_identifier": {
          "en": "coverage identifier", 
          "it": "Identificatore di copertura"
        },
        "coverage_configuration": {
          "en": "coverage configuration", 
          "it": "Configurazione della copertura"
        },
        "scenario": {
          "en": "Scenario", 
          "it": "Scenario"
        },
        "year_period": {
          "en": "Year period", 
          "it": "Periodo dell'anno"
        }
      },
     "parameter_values": {
        "series_name": {
          "en": "TAS seasonal absolute model ensemble", 
          "it": "TAS valore assoluto di stagione media ensemble"
        },
        "processing_method": {
          "en": "no processing", 
          "it": "nessuna elaborazione"
        },
        "coverage_identifier": {
          "en": "tas_seasonal_absolute_model_ensemble-rcp26-DJF", 
          "it": "tas_seasonal_absolute_model_ensemble-rcp26-DJF"
        },
        "coverage_configuration": {
          "en": "TAS seasonal absolute model ensemble",
          "it": "TAS valore assoluto di stagione media ensemble"
        },
        "scenario": {
          "en": "RCP2.6", 
          "it": "RCP2.6"
        },
        "year_period": {
          "en": "Winter", 
          "it": "Inverno"
        }
      }
    }
  },
  ...
]

Notable things about the response snippet pasted above:

Also included in this PR (admittedly somewhat unrelated) is a refactor of the way time series data is fetched from the remote THREDDS server. The proposed implementation leverages anyio and httpx.AsyncClient in order to interact with THREDD's NCSS service in an async fashion. As commented in #163, this was done with the hopes of improving performance of the system.