From ec4dc5ca295e66a0d5ffb23465458d3813828469 Mon Sep 17 00:00:00 2001 From: Vecna Date: Fri, 26 Apr 2024 15:11:31 -0400 Subject: [PATCH] Re-evaluate past days in case we got new reports since last evaluation It would be better to track which bridges got new reports and only re-evaluate those. --- src/lib.rs | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index db86c58..0e3e869 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -634,13 +634,23 @@ pub fn guess_blockages( let mut bridge_info: BridgeInfo = bincode::deserialize(&db.get(fingerprint).unwrap().unwrap()).unwrap(); let mut new_blockages = HashSet::::new(); - let blocked_in = analysis::blocked_in(analyzer, &bridge_info, confidence, get_date()); - for country in blocked_in { - let bridge_country_info = bridge_info.info_by_country.get_mut(&country).unwrap(); - if !bridge_country_info.blocked { - new_blockages.insert(country.to_string()); - // Mark bridge as blocked when db gets updated - bridge_country_info.blocked = true; + // Re-evaluate the last MAX_BACKDATE + 1 days in case we received new + // reports for those days. For efficiency, we could instead keep track + // of which bridges received new reports and only re-evaluate those. + for i in 0..MAX_BACKDATE + 1 { + let blocked_in = analysis::blocked_in( + analyzer, + &bridge_info, + confidence, + get_date() - MAX_BACKDATE - 1 + i, + ); + for country in blocked_in { + let bridge_country_info = bridge_info.info_by_country.get_mut(&country).unwrap(); + if !bridge_country_info.blocked { + new_blockages.insert(country.to_string()); + // Mark bridge as blocked when db gets updated + bridge_country_info.blocked = true; + } } } blockages.insert(fingerprint, new_blockages);