cargo-fmt
This commit is contained in:
parent
cc670963c5
commit
c1b058ce4e
|
@ -45,7 +45,9 @@ fn get_extra_info_or_error(entry: &HashMap<String, String>) -> Result<ExtraInfo,
|
||||||
// How did we get here??
|
// How did we get here??
|
||||||
return Err("Cannot parse extra-info: Missing nickname or fingerprint".to_string());
|
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...
|
// Some extra-infos are missing data on connecting IPs...
|
||||||
// But we can't do anything in that case.
|
// But we can't do anything in that case.
|
||||||
return Err(format!(
|
return Err(format!(
|
||||||
|
@ -64,15 +66,12 @@ fn get_extra_info_or_error(entry: &HashMap<String, String>) -> Result<ExtraInfo,
|
||||||
let date_str = if entry.contains_key("bridge-stats-end") {
|
let date_str = if entry.contains_key("bridge-stats-end") {
|
||||||
let line = entry.get("bridge-stats-end").unwrap();
|
let line = entry.get("bridge-stats-end").unwrap();
|
||||||
// Parse out (86400 s) from end of line
|
// Parse out (86400 s) from end of line
|
||||||
&line[..line.find("(").unwrap()-1]
|
&line[..line.find("(").unwrap() - 1]
|
||||||
} else {
|
} else {
|
||||||
entry.get("published").unwrap().as_str()
|
entry.get("published").unwrap().as_str()
|
||||||
};
|
};
|
||||||
JulianDay::from(
|
JulianDay::from(
|
||||||
DateTime::parse_from_str(
|
DateTime::parse_from_str(&(date_str.to_owned() + " +0000"), "%F %T %z")
|
||||||
&(date_str.to_owned() + " +0000"),
|
|
||||||
"%F %T %z",
|
|
||||||
)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.date_naive(),
|
.date_naive(),
|
||||||
)
|
)
|
||||||
|
|
33
src/lib.rs
33
src/lib.rs
|
@ -126,28 +126,42 @@ pub struct DailyBridgeInfo {
|
||||||
impl DailyBridgeInfo {
|
impl DailyBridgeInfo {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
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() {
|
for country in count_per_country.keys() {
|
||||||
if self.info_by_country.contains_key(country) {
|
if self.info_by_country.contains_key(country) {
|
||||||
let info = self.info_by_country.get_mut(country).unwrap();
|
let info = self.info_by_country.get_mut(country).unwrap();
|
||||||
if !info.contains_key(&info_type) {
|
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 {
|
} else if info_type == BridgeInfoType::BridgeIps {
|
||||||
// Use newest value we've seen today
|
// Use newest value we've seen today
|
||||||
if info.get(&info_type).unwrap() < count_per_country.get(country).unwrap() {
|
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 {
|
} 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);
|
info.insert(info_type, new_count);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let mut info = BTreeMap::<BridgeInfoType, u32>::new();
|
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);
|
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
|
// If we already have an entry, compare it with the new one. For each
|
||||||
// country:count mapping, use the greater of the two counts.
|
// country:count mapping, use the greater of the two counts.
|
||||||
if bridge_info.info_by_day.contains_key(&extra_info.date) {
|
if bridge_info.info_by_day.contains_key(&extra_info.date) {
|
||||||
let daily_bridge_info = bridge_info
|
let daily_bridge_info = bridge_info.info_by_day.get_mut(&extra_info.date).unwrap();
|
||||||
.info_by_day
|
|
||||||
.get_mut(&extra_info.date)
|
|
||||||
.unwrap();
|
|
||||||
daily_bridge_info.add_info(BridgeInfoType::BridgeIps, &extra_info.bridge_ips);
|
daily_bridge_info.add_info(BridgeInfoType::BridgeIps, &extra_info.bridge_ips);
|
||||||
} else {
|
} else {
|
||||||
// No existing entry; make a new one.
|
// No existing entry; make a new one.
|
||||||
let mut daily_bridge_info = DailyBridgeInfo {
|
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);
|
daily_bridge_info.add_info(BridgeInfoType::BridgeIps, &extra_info.bridge_ips);
|
||||||
bridge_info
|
bridge_info
|
||||||
|
|
Loading…
Reference in New Issue