瀏覽代碼

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.
Vecna 3 周之前
父節點
當前提交
ec4dc5ca29
共有 1 個文件被更改,包括 17 次插入7 次删除
  1. 17 7
      src/lib.rs

+ 17 - 7
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::<String>::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);