Filter out items that are older than 1h before now

Luchtmeetnet seems to yield some results that are in the past some
times?
This commit is contained in:
Paul van Tilburg 2022-02-24 20:21:48 +01:00
parent a78c55332f
commit d0ace275ec
Signed by untrusted user: paul
GPG Key ID: C6DE073EDA9EEC4D
1 changed files with 10 additions and 2 deletions

View File

@ -4,7 +4,7 @@
use cached::proc_macro::cached;
use chrono::serde::ts_seconds;
use chrono::{DateTime, Utc};
use chrono::{DateTime, Duration, Utc};
use reqwest::Url;
use rocket::serde::{Deserialize, Serialize};
@ -75,5 +75,13 @@ pub(crate) async fn get(position: Position, metric: Metric) -> Option<Vec<Item>>
Err(_err) => return None,
};
Some(root.data)
// Filter items that are older than one hour before now. They seem to occur sometimes?
let too_old = Utc::now() - Duration::hours(1);
let items = root
.data
.into_iter()
.filter(|item| item.time > too_old)
.collect();
Some(items)
}