Compare commits
2 Commits
8ad78929fe
...
d33b5f1dbb
Author | SHA1 | Date | |
---|---|---|---|
d33b5f1dbb | |||
95f30751c6 |
|
@ -7,8 +7,8 @@ use chrono::serde::ts_seconds;
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use rocket::serde::Serialize;
|
use rocket::serde::Serialize;
|
||||||
|
|
||||||
use super::buienradar::{self, Sample as BuienradarSample};
|
pub(crate) use super::buienradar::{self, Sample as BuienradarSample};
|
||||||
use super::luchtmeetnet::{self, Item as LuchtmeetnetItem};
|
pub(crate) use super::luchtmeetnet::{self, Item as LuchtmeetnetItem};
|
||||||
use crate::maps::MapsHandle;
|
use crate::maps::MapsHandle;
|
||||||
use crate::position::Position;
|
use crate::position::Position;
|
||||||
use crate::Metric;
|
use crate::Metric;
|
||||||
|
@ -25,6 +25,14 @@ pub(crate) struct Item {
|
||||||
value: f32,
|
value: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Merges pollen samples and AQI items into combined items.
|
||||||
|
///
|
||||||
|
/// This drops items from either the pollen samples or from the AQI items if they are not stamped
|
||||||
|
/// with half an hour of the first item of the latest stating series, thus lining them before they
|
||||||
|
/// are combined.
|
||||||
|
///
|
||||||
|
/// Returns [`None`] if there are no pollen samples, if there are no AQI items, or if
|
||||||
|
/// lining them up fails.
|
||||||
fn merge(
|
fn merge(
|
||||||
pollen_samples: Vec<BuienradarSample>,
|
pollen_samples: Vec<BuienradarSample>,
|
||||||
aqi_items: Vec<LuchtmeetnetItem>,
|
aqi_items: Vec<LuchtmeetnetItem>,
|
||||||
|
@ -56,10 +64,9 @@ fn merge(
|
||||||
})?;
|
})?;
|
||||||
aqi_items.drain(..idx);
|
aqi_items.drain(..idx);
|
||||||
}
|
}
|
||||||
// pollen_iter.skip_while(|it| it.time.signed_duration_since(aqi_iter.peek()) .. ?
|
|
||||||
// aqi_iter.skip_while(|it| it.time.signed_duration_since(aqi_iter.peek()) ?
|
|
||||||
|
|
||||||
// Combine
|
// Combine the samples with items by taking the maximum of pollen sample score and AQI item
|
||||||
|
// value.
|
||||||
let items = pollen_samples
|
let items = pollen_samples
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.zip(aqi_items.into_iter())
|
.zip(aqi_items.into_iter())
|
||||||
|
@ -99,9 +106,7 @@ pub(crate) async fn get(
|
||||||
return None;
|
return None;
|
||||||
};
|
};
|
||||||
let pollen_items = buienradar::get_samples(position, Metric::Pollen, maps_handle).await;
|
let pollen_items = buienradar::get_samples(position, Metric::Pollen, maps_handle).await;
|
||||||
dbg!(&pollen_items);
|
|
||||||
let aqi_items = luchtmeetnet::get(position, Metric::AQI).await;
|
let aqi_items = luchtmeetnet::get(position, Metric::AQI).await;
|
||||||
dbg!(&aqi_items);
|
|
||||||
|
|
||||||
merge(pollen_items?, aqi_items?)
|
merge(pollen_items?, aqi_items?)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user