From 4232263a4572a32b27cdec825422ec73fc6f5d3e Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Sun, 13 Feb 2022 15:39:09 +0100 Subject: [PATCH] Hook up the Buienradar provider metric in the forecast Also, sync up the Luchtmeetnet provider documentation a bit. --- src/main.rs | 7 +++++-- src/providers/luchtmeetnet.rs | 9 ++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 3a5fb4b..57cdc26 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,6 +21,7 @@ use rocket::tokio::{self, select}; use rocket::{get, routes, FromFormField, State}; use self::maps::{Maps, MapsHandle}; +use self::providers::buienradar::Item as BuienradarItem; use self::providers::luchtmeetnet::Item as LuchtmeetnetItem; pub(crate) mod maps; @@ -69,7 +70,7 @@ struct Forecast { /// The precipitation (when asked for). #[serde(skip_serializing_if = "Option::is_none")] - precipitation: Option<()>, + precipitation: Option>, /// The UV index (when asked for). #[serde(rename = "UVI", skip_serializing_if = "Option::is_none")] @@ -154,7 +155,9 @@ async fn forecast( Metric::PAQI => forecast.paqi = Some(()), Metric::PM10 => forecast.pm10 = providers::luchtmeetnet::get(lat, lon, metric).await, Metric::Pollen => forecast.pollen = Some(()), - Metric::Precipitation => forecast.precipitation = Some(()), + Metric::Precipitation => { + forecast.precipitation = providers::buienradar::get(lat, lon, metric).await + } Metric::UVI => forecast.uvi = Some(()), } } diff --git a/src/providers/luchtmeetnet.rs b/src/providers/luchtmeetnet.rs index a704e31..26c243d 100644 --- a/src/providers/luchtmeetnet.rs +++ b/src/providers/luchtmeetnet.rs @@ -25,12 +25,13 @@ struct Container { #[derive(Debug, Deserialize, Serialize)] #[serde(crate = "rocket::serde")] pub(crate) struct Item { - /// The time for when the value is forecast. + /// The time(stamp) of the forecast. #[serde( rename(deserialize = "timestamp_measured"), serialize_with = "ts_seconds::serialize" )] time: DateTime, + /// The forecasted value. /// /// The unit depends on the selected [metric](Metric). @@ -39,6 +40,12 @@ pub(crate) struct Item { /// Retrieves the Luchtmeetnet forecasted items for the provided position and metric. /// +/// It supports the following metrics: +/// * [`Metric::AQI`] +/// * [`Metric::NO2`] +/// * [`Metric::O3`] +/// * [`Metric::PM10`] +/// /// Returns [`None`] if retrieval or deserialization fails, or if the metric is not supported by /// this provider. pub(crate) async fn get(lat: f64, lon: f64, metric: Metric) -> Option> {