diff options
author | ClementTsang <clementjhtsang@gmail.com> | 2020-01-21 23:35:16 -0500 |
---|---|---|
committer | ClementTsang <clementjhtsang@gmail.com> | 2020-01-21 23:35:16 -0500 |
commit | fe99b99d0af3435636562dc4ca80a944e74ac926 (patch) | |
tree | 722fed55075f411f42beabad055447ac9c063931 /src | |
parent | e6b6048afb3ddfa89d308742f0be1eb5478ecf5c (diff) |
Removed btreemap and went back to vec as it makes more sense for us
Diffstat (limited to 'src')
-rw-r--r-- | src/app/data_collection.rs | 10 | ||||
-rw-r--r-- | src/app/data_collection/network.rs | 13 |
2 files changed, 7 insertions, 16 deletions
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<Vec<network::NetworkJoinPoint>> = 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<Vec<NetworkJoinPoint>>)); #[derive(Clone, Debug)] pub struct NetworkStorage { - pub data_points: BTreeMap<Instant, (NetworkData, Option<Vec<NetworkJoinPoint>>)>, + pub data_points: Vec<NetworkDataGroup>, 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; |