Changed network data to show decimal point.

This commit is contained in:
ClementTsang 2019-12-11 01:01:40 -05:00
parent 467af10c36
commit 076d6a0546
1 changed files with 10 additions and 10 deletions

View File

@ -287,31 +287,31 @@ pub fn convert_network_data_points(network_data: &[data_collection::network::Net
let rx_display = if let Some(last_num_bytes_entry) = network_data.last() {
let num_bytes = last_num_bytes_entry.rx;
if num_bytes < 1024 {
format!("RX: {:4} B", num_bytes).to_string()
format!("RX: {:5.*} B/s", 1, num_bytes as f64).to_string()
} else if num_bytes < (1024 * 1024) {
format!("RX: {:4}KB", num_bytes / 1024).to_string()
format!("RX: {:5.*}KB/s", 1, num_bytes as f64 / 1024.0).to_string()
} else if num_bytes < (1024 * 1024 * 1024) {
format!("RX: {:4}MB", num_bytes / 1024 / 1024).to_string()
format!("RX: {:5.*}MB/s", 1, num_bytes as f64 / 1024.0 / 1024.0).to_string()
} else {
format!("RX: {:4}GB", num_bytes / 1024 / 1024 / 1024).to_string()
format!("RX: {:5.*}GB/s", 1, num_bytes as f64 / 1024.0 / 1024.0 / 1024.0).to_string()
}
} else {
"0B".to_string()
"0.0B/s".to_string()
};
let tx_display = if let Some(last_num_bytes_entry) = network_data.last() {
let num_bytes = last_num_bytes_entry.tx;
if num_bytes < 1024 {
format!("TX: {:4} B", num_bytes).to_string()
format!("TX: {:5.*} B/s", 1, num_bytes as f64).to_string()
} else if num_bytes < (1024 * 1024) {
format!("TX: {:4}KB", num_bytes / 1024).to_string()
format!("TX: {:5.*}KB/s", 1, num_bytes as f64 / 1024.0).to_string()
} else if num_bytes < (1024 * 1024 * 1024) {
format!("TX: {:4}MB", num_bytes / 1024 / 1024).to_string()
format!("TX: {:5.*}MB/s", 1, num_bytes as f64 / 1024.0 / 1024.0).to_string()
} else {
format!("TX: {:4}GB", num_bytes / 1024 / 1024 / 1024).to_string()
format!("TX: {:5.*}GB/s", 1, num_bytes as f64 / 1024.0 / 1024.0 / 1024.0).to_string()
}
} else {
"0B".to_string()
"0B.0/s".to_string()
};
ConvertedNetworkData {