Browse Source

cargo-fmt

Vecna 1 year ago
parent
commit
c1b058ce4e
2 changed files with 29 additions and 19 deletions
  1. 7 8
      src/extra_info.rs
  2. 22 11
      src/lib.rs

+ 7 - 8
src/extra_info.rs

@@ -45,7 +45,9 @@ fn get_extra_info_or_error(entry: &HashMap<String, String>) -> Result<ExtraInfo,
         // How did we get here??
         return Err("Cannot parse extra-info: Missing nickname or fingerprint".to_string());
     }
-    if !(entry.contains_key("bridge-stats-end") || entry.contains_key("published")) || !entry.contains_key("bridge-ips") {
+    if !(entry.contains_key("bridge-stats-end") || entry.contains_key("published"))
+        || !entry.contains_key("bridge-ips")
+    {
         // Some extra-infos are missing data on connecting IPs...
         // But we can't do anything in that case.
         return Err(format!(
@@ -64,17 +66,14 @@ fn get_extra_info_or_error(entry: &HashMap<String, String>) -> Result<ExtraInfo,
         let date_str = if entry.contains_key("bridge-stats-end") {
             let line = entry.get("bridge-stats-end").unwrap();
             // Parse out (86400 s) from end of line
-            &line[..line.find("(").unwrap()-1]
+            &line[..line.find("(").unwrap() - 1]
         } else {
             entry.get("published").unwrap().as_str()
         };
         JulianDay::from(
-            DateTime::parse_from_str(
-                &(date_str.to_owned() + " +0000"),
-                "%F %T %z",
-            )
-            .unwrap()
-            .date_naive(),
+            DateTime::parse_from_str(&(date_str.to_owned() + " +0000"), "%F %T %z")
+                .unwrap()
+                .date_naive(),
         )
         .inner()
         .try_into()

+ 22 - 11
src/lib.rs

@@ -126,28 +126,42 @@ pub struct DailyBridgeInfo {
 impl DailyBridgeInfo {
     pub fn new() -> Self {
         Self {
-            info_by_country: BTreeMap::<String, BTreeMap::<BridgeInfoType, u32>>::new(),
+            info_by_country: BTreeMap::<String, BTreeMap<BridgeInfoType, u32>>::new(),
         }
     }
 
-    pub fn add_info(&mut self, info_type: BridgeInfoType, count_per_country: &BTreeMap::<String, u32>) {
+    pub fn add_info(
+        &mut self,
+        info_type: BridgeInfoType,
+        count_per_country: &BTreeMap<String, u32>,
+    ) {
         for country in count_per_country.keys() {
             if self.info_by_country.contains_key(country) {
                 let info = self.info_by_country.get_mut(country).unwrap();
                 if !info.contains_key(&info_type) {
-                    info.insert(info_type, *count_per_country.get(&country.to_string()).unwrap());
+                    info.insert(
+                        info_type,
+                        *count_per_country.get(&country.to_string()).unwrap(),
+                    );
                 } else if info_type == BridgeInfoType::BridgeIps {
                     // Use newest value we've seen today
                     if info.get(&info_type).unwrap() < count_per_country.get(country).unwrap() {
-                        info.insert(BridgeInfoType::BridgeIps, *count_per_country.get(&country.to_string()).unwrap());
+                        info.insert(
+                            BridgeInfoType::BridgeIps,
+                            *count_per_country.get(&country.to_string()).unwrap(),
+                        );
                     }
                 } else {
-                    let new_count = info.get(&info_type).unwrap() + *count_per_country.get(&country.to_string()).unwrap();
+                    let new_count = info.get(&info_type).unwrap()
+                        + *count_per_country.get(&country.to_string()).unwrap();
                     info.insert(info_type, new_count);
                 }
             } else {
                 let mut info = BTreeMap::<BridgeInfoType, u32>::new();
-                info.insert(info_type, *count_per_country.get(&country.to_string()).unwrap());
+                info.insert(
+                    info_type,
+                    *count_per_country.get(&country.to_string()).unwrap(),
+                );
                 self.info_by_country.insert(country.to_string(), info);
             }
         }
@@ -201,15 +215,12 @@ pub fn add_extra_info_to_db(db: &Db, extra_info: ExtraInfo) {
     // If we already have an entry, compare it with the new one. For each
     // country:count mapping, use the greater of the two counts.
     if bridge_info.info_by_day.contains_key(&extra_info.date) {
-        let daily_bridge_info = bridge_info
-            .info_by_day
-            .get_mut(&extra_info.date)
-            .unwrap();
+        let daily_bridge_info = bridge_info.info_by_day.get_mut(&extra_info.date).unwrap();
         daily_bridge_info.add_info(BridgeInfoType::BridgeIps, &extra_info.bridge_ips);
     } else {
         // No existing entry; make a new one.
         let mut daily_bridge_info = DailyBridgeInfo {
-            info_by_country: BTreeMap::<String, BTreeMap::<BridgeInfoType, u32>>::new(),
+            info_by_country: BTreeMap::<String, BTreeMap<BridgeInfoType, u32>>::new(),
         };
         daily_bridge_info.add_info(BridgeInfoType::BridgeIps, &extra_info.bridge_ips);
         bridge_info