Skip to content

Commit

Permalink
Update UI snapshots for new bandwidth calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangxp1998 committed Jan 6, 2020
1 parent c7bcffa commit e202799
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 46 deletions.
47 changes: 19 additions & 28 deletions src/display/ui_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ pub struct ConnectionData {
pub interface_name: String,
}

fn calc_avg_bandwidth(prev_bandwidth: u128, curr_bandwidth: u128) -> u128 {
if prev_bandwidth == 0 {
curr_bandwidth
} else {
(prev_bandwidth as f32 * BANDWIDTH_DECAY_FACTOR
+ (1.0 - BANDWIDTH_DECAY_FACTOR) * curr_bandwidth as f32) as u128
}
}

impl Bandwidth for ConnectionData {
fn get_total_bytes_uploaded(&self) -> u128 {
self.total_bytes_uploaded
Expand All @@ -40,22 +49,13 @@ impl Bandwidth for ConnectionData {
self.total_bytes_downloaded
}
fn get_avg_bytes_uploaded(&self) -> u128 {
if self.prev_total_bytes_uploaded == 0 {
self.total_bytes_uploaded
} else {
(self.prev_total_bytes_uploaded as f32 * BANDWIDTH_DECAY_FACTOR
+ (1.0 - BANDWIDTH_DECAY_FACTOR) * self.total_bytes_uploaded as f32)
as u128
}
calc_avg_bandwidth(self.prev_total_bytes_uploaded, self.total_bytes_uploaded)
}
fn get_avg_bytes_downloaded(&self) -> u128 {
if self.prev_total_bytes_downloaded == 0 {
self.total_bytes_downloaded
} else {
(self.prev_total_bytes_downloaded as f32 * BANDWIDTH_DECAY_FACTOR
+ (1.0 - BANDWIDTH_DECAY_FACTOR) * self.total_bytes_downloaded as f32)
as u128
}
calc_avg_bandwidth(
self.prev_total_bytes_downloaded,
self.total_bytes_downloaded,
)
}
}

Expand All @@ -67,22 +67,13 @@ impl Bandwidth for NetworkData {
self.total_bytes_downloaded
}
fn get_avg_bytes_uploaded(&self) -> u128 {
if self.prev_total_bytes_uploaded == 0 {
self.total_bytes_uploaded
} else {
(self.prev_total_bytes_uploaded as f32 * BANDWIDTH_DECAY_FACTOR
+ (1.0 - BANDWIDTH_DECAY_FACTOR) * self.total_bytes_uploaded as f32)
as u128
}
calc_avg_bandwidth(self.prev_total_bytes_uploaded, self.total_bytes_uploaded)
}
fn get_avg_bytes_downloaded(&self) -> u128 {
if self.prev_total_bytes_downloaded == 0 {
self.total_bytes_downloaded
} else {
(self.prev_total_bytes_downloaded as f32 * BANDWIDTH_DECAY_FACTOR
+ (1.0 - BANDWIDTH_DECAY_FACTOR) * self.total_bytes_downloaded as f32)
as u128
}
calc_avg_bandwidth(
self.prev_total_bytes_downloaded,
self.total_bytes_downloaded,
)
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/tests/cases/snapshots/ui__no_resolve_mode-2.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ expression: "&terminal_draw_events_mirror[2]"



5 32 46 3 3 3 3 3 7 (tcp) 5 32 46
1 7 6 1 1 1 1 2 45 (tcp) 1 7 6
5 33 4 3 3 3 3 3 7 (tcp) 5 33 4
1 47 48 1 1 1 1 2 45 (tcp) 1 47 48



Expand All @@ -30,8 +30,8 @@ expression: "&terminal_draw_events_mirror[2]"



3 3 3 3 32 46
1 1 1 1 7 6
3 3 3 3 33 4
1 1 1 1 47 48



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ expression: "&terminal_draw_events_mirror[2]"



61 61
51 51
52 52
45 45



Expand All @@ -30,8 +30,8 @@ expression: "&terminal_draw_events_mirror[2]"



61
51
52
45



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ expression: "&terminal_draw_events_mirror[2]"



5 32 46 3 3 3 3 3 7 (tcp) 5 32 46
1 7 6 1 1 1 1 2 45 (tcp) 1 7 6
5 33 4 3 3 3 3 3 7 (tcp) 5 33 4
1 47 48 1 1 1 1 2 45 (tcp) 1 47 48



Expand All @@ -30,8 +30,8 @@ expression: "&terminal_draw_events_mirror[2]"



3 3 3 3 32 46
1 1 1 1 7 6
3 3 3 3 33 4
1 1 1 1 47 48



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ expression: "&terminal_draw_events_mirror[2]"



51 51
7 7



Expand All @@ -30,7 +30,7 @@ expression: "&terminal_draw_events_mirror[2]"



51
7



Expand Down
Loading

0 comments on commit e202799

Please sign in to comment.