Add module src/free_api_v25/current/precipitation.rs
This commit is contained in:
parent
bbec51dbe6
commit
6ae6fb57cb
@ -20,5 +20,6 @@
|
|||||||
pub mod clouds;
|
pub mod clouds;
|
||||||
pub mod coord;
|
pub mod coord;
|
||||||
pub mod main;
|
pub mod main;
|
||||||
|
pub mod precipitation;
|
||||||
pub mod weather;
|
pub mod weather;
|
||||||
pub mod wind;
|
pub mod wind;
|
||||||
|
36
src/free_api_v25/current/precipitation.rs
Normal file
36
src/free_api_v25/current/precipitation.rs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
/// Precipitation information for rain or snow
|
||||||
|
///
|
||||||
|
/// Contains precipitation volumes over different time periods.
|
||||||
|
#[derive(Debug, Clone, Deserialize, Serialize, Default, PartialEq)]
|
||||||
|
pub struct Precipitation {
|
||||||
|
/// Precipitation volume over the last 1 hour (mm)
|
||||||
|
#[serde(rename = "1h", default)]
|
||||||
|
pub one_hour: Option<f32>,
|
||||||
|
|
||||||
|
/// Precipitation volume over the last 3 hours (mm)
|
||||||
|
#[serde(rename = "3h", default)]
|
||||||
|
pub three_hour: Option<f32>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Precipitation {
|
||||||
|
/// Returns the precipitation intensity category
|
||||||
|
///
|
||||||
|
/// - None: No precipitation data
|
||||||
|
/// - "Light": < 2.5 mm/h
|
||||||
|
/// - "Moderate": 2.5 - 7.5 mm/h
|
||||||
|
/// - "Heavy": > 7.5 mm/h
|
||||||
|
#[must_use]
|
||||||
|
pub fn intensity(&self) -> Option<&'static str> {
|
||||||
|
let rate = self.one_hour.or(self.three_hour.map(|v| v / 3.0))?;
|
||||||
|
|
||||||
|
if rate < 2.5 {
|
||||||
|
Some("Light")
|
||||||
|
} else if rate <= 7.5 {
|
||||||
|
Some("Moderate")
|
||||||
|
} else {
|
||||||
|
Some("Heavy")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user