diff --git a/src/app/data_collection.rs b/src/app/data_collection.rs index 0d07e084..433f43d6 100644 --- a/src/app/data_collection.rs +++ b/src/app/data_collection.rs @@ -119,13 +119,9 @@ impl DataState { let joining_points: Option> = if !self.data.network.data_points.is_empty() { - if let Some(prev_data) = self - .data - .network - .data_points - .get(&self.data.network.last_collection_time) - { + if let Some(last_entry) = self.data.network.data_points.last() { // If not empty, inject joining points + let prev_data = &last_entry.1; let rx_diff = new_network_data.rx as f64 - prev_data.0.rx as f64; let tx_diff = new_network_data.tx as f64 - prev_data.0.tx as f64; let time_gap = current_instant @@ -161,7 +157,7 @@ impl DataState { self.data .network .data_points - .insert(current_instant, (new_network_data, joining_points)); + .push((current_instant, (new_network_data, joining_points))); // What we want to do: For timed data, if there is an error, just do not add. For other data, just don't update! push_if_valid( diff --git a/src/app/data_collection/network.rs b/src/app/data_collection/network.rs index da646ad2..b1695409 100644 --- a/src/app/data_collection/network.rs +++ b/src/app/data_collection/network.rs @@ -1,7 +1,6 @@ use futures::StreamExt; use heim::net; use heim::units::information::byte; -use std::collections::BTreeMap; use std::time::Instant; use sysinfo::{NetworkExt, System, SystemExt}; @@ -12,9 +11,10 @@ pub struct NetworkJoinPoint { pub time_offset_milliseconds: f64, } +type NetworkDataGroup = (Instant, (NetworkData, Option>)); #[derive(Clone, Debug)] pub struct NetworkStorage { - pub data_points: BTreeMap>)>, + pub data_points: Vec, pub rx: u64, pub tx: u64, pub total_rx: u64, @@ -25,7 +25,7 @@ pub struct NetworkStorage { impl Default for NetworkStorage { fn default() -> Self { NetworkStorage { - data_points: BTreeMap::default(), + data_points: Vec::default(), rx: 0, tx: 0, total_rx: 0, @@ -37,7 +37,7 @@ impl Default for NetworkStorage { impl NetworkStorage { pub fn first_run(&mut self) { - self.data_points = BTreeMap::default(); + self.data_points = Vec::default(); self.rx = 0; self.tx = 0; } @@ -76,11 +76,6 @@ pub async fn get_network_data( .duration_since(*prev_net_access_time) .as_secs_f64(); - debug!( - "net rx: {}, net tx: {}, net prev rx: {}, net prev tx: {}", - net_rx, net_tx, *prev_net_rx, *prev_net_tx - ); - let rx = ((net_rx - *prev_net_rx) as f64 / elapsed_time) as u64; let tx = ((net_tx - *prev_net_tx) as f64 / elapsed_time) as u64;