1use chrono::prelude::*;
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Deserialize, Serialize)]
5pub struct Observation {
6 pub issue_time: DateTime<Utc>,
7 pub observation_time: DateTime<Utc>,
8 pub temp: f32,
9 pub temp_feels_like: f32,
10 pub wind: Wind,
11 pub gust: Gust,
12 pub max_gust: MaxGust,
13 pub max_temp: Temperature,
14 pub min_temp: Temperature,
15 pub rain_since_9am: Option<f32>,
16 pub humidity: u8,
17 pub station: Station,
18}
19
20impl From<ObservationResponse> for Option<Observation> {
21 fn from(response: ObservationResponse) -> Option<Observation> {
22 response.metadata.issue_time?;
23
24 Some(Observation {
25 issue_time: response.metadata.issue_time.unwrap(),
26 observation_time: response.metadata.observation_time.unwrap(),
27 temp: response.data.temp.unwrap(),
28 temp_feels_like: response.data.temp_feels_like.unwrap(),
29 wind: response.data.wind.unwrap(),
30 gust: response.data.gust.unwrap(),
31 max_gust: response.data.max_gust.unwrap(),
32 max_temp: response.data.max_temp.unwrap(),
33 min_temp: response.data.min_temp.unwrap(),
34 rain_since_9am: response.data.rain_since_9am,
35 humidity: response.data.humidity.unwrap(),
36 station: response.data.station.unwrap(),
37 })
38 }
39}
40
41#[derive(Debug, Deserialize, Serialize)]
42pub struct ObservationResponse {
43 pub data: ObservationData,
44 pub metadata: ObservationMetadata,
45}
46
47#[derive(Debug, Deserialize, Serialize)]
48pub struct ObservationData {
49 pub temp: Option<f32>,
50 pub temp_feels_like: Option<f32>,
51 pub wind: Option<Wind>,
52 pub gust: Option<Gust>,
53 pub max_gust: Option<MaxGust>,
54 pub max_temp: Option<Temperature>,
55 pub min_temp: Option<Temperature>,
56 pub rain_since_9am: Option<f32>,
57 pub humidity: Option<u8>,
58 pub station: Option<Station>,
59}
60
61#[derive(Debug, Deserialize, Serialize)]
62pub struct ObservationMetadata {
63 pub issue_time: Option<DateTime<Utc>>,
64 pub observation_time: Option<DateTime<Utc>>,
65 pub response_timestamp: DateTime<Utc>,
66}
67
68#[derive(Debug, Deserialize, Serialize)]
69pub struct Gust {
70 pub speed_kilometre: u8,
71 pub speed_knot: u8,
72}
73
74#[derive(Debug, Deserialize, Serialize)]
75pub struct MaxGust {
76 pub speed_kilometre: u8,
77 pub speed_knot: u8,
78 pub time: DateTime<Utc>,
79}
80
81#[derive(Debug, Deserialize, Serialize)]
82pub struct Wind {
83 pub direction: Option<String>,
84 pub speed_kilometre: u8,
85 pub speed_knot: u8,
86}
87
88#[derive(Debug, Deserialize, Serialize)]
89pub struct Temperature {
90 pub time: DateTime<Utc>,
91 pub value: f32,
92}
93
94#[derive(Clone, Debug, Default, Deserialize, Serialize)]
95pub struct Station {
96 pub bom_id: String,
97 pub distance: f64,
98 pub name: String,
99}
100
101#[derive(Debug, Serialize, Deserialize)]
102pub struct PastObservationData {
103 #[serde(rename = "TDZ")]
104 pub tdz: String,
105 pub aifstime_local: String,
106 pub aifstime_utc: String,
107 pub air_temp: f32,
108 pub apparent_t: f32,
109 pub cloud: String,
110 pub cloud_base_m: Option<u32>,
111 pub cloud_oktas: Option<u32>,
112 pub cloud_type: String,
113 pub cloud_type_id: Option<String>, pub delta_t: f32,
115 pub dewpt: f32,
116 pub duration_from_local_9am_date: i64,
117 pub gust_kmh: i64,
118 pub gust_kt: i64,
119 pub history_product: String,
120 pub lat: f64,
121 pub local_9am_date_time: String,
122 pub local_9am_date_time_utc: String,
123 pub lon: f64,
124 pub name: String,
125 pub press: f64,
126 pub press_msl: f64,
127 pub press_qnh: f64,
128 pub press_tend: String,
129 pub rain_hour: f64,
130 pub rain_ten: f64,
131 pub rain_trace: String,
132 pub rain_trace_time: String,
133 pub rain_trace_time_utc: String,
134 pub rel_hum: i64,
135 pub sea_state: String,
136 pub sort_order: i64,
137 pub swell_dir_worded: String,
138 pub swell_height: Option<f64>, pub swell_period: Option<i64>, pub time_zone_name: String,
142 pub vis_km: String,
143 pub weather: String,
144 pub wind_dir: String,
145 pub wind_dir_deg: i64,
146 pub wind_spd_kmh: i64,
147 pub wind_spd_kt: i64,
148 pub wind_src: String,
149 pub wmo: i64,
150}
151#[derive(Debug, Serialize, Deserialize)]
152pub struct PastObservationsHeader {
153 #[serde(rename = "ID")]
154 pub id: String,
155 #[serde(rename = "Office")]
156 pub office: String,
157 #[serde(rename = "TDZ")]
158 pub tdz: String,
159 pub issue_time_local: String,
160 pub issue_time_utc: String,
161 #[serde(rename = "main_ID")]
162 pub main_id: String,
163 pub name: String,
164 pub product_name: String,
165 pub state: String,
166 pub state_time_zone: String,
167 pub time_zone: String,
168 pub time_zone_name: String,
169 pub wmo_id: String,
170}
171#[derive(Debug, Serialize, Deserialize)]
172pub struct PastObservationsNotice {
173 pub copyright: String,
174 pub copyright_url: String,
175 pub disclaimer_url: String,
176 pub feedback_url: String,
177}
178#[derive(Debug, Serialize, Deserialize)]
179pub struct PastObservations {
180 pub data: Vec<PastObservationData>,
181 pub header: Vec<PastObservationsHeader>,
182 pub notice: Vec<PastObservationsNotice>,
183}
184#[derive(Debug, Serialize, Deserialize)]
185pub struct PastObservationsResponse {
186 pub observations: PastObservations,
187}