mirror of
https://github.com/LibreQoE/LibreQoS.git
synced 2025-02-25 18:55:32 -06:00
lq_utils: Move packet scaling routines to library
This moves the packet scaling routines for g/m/k gps and g/m/k bytes to a shared library.
This commit is contained in:
parent
b2cf27ea9a
commit
40758ffe6b
1
src/rust/Cargo.lock
generated
1
src/rust/Cargo.lock
generated
@ -1459,6 +1459,7 @@ dependencies = [
|
||||
"anyhow",
|
||||
"crossterm 0.19.0",
|
||||
"lqos_bus",
|
||||
"lqos_utils",
|
||||
"tokio",
|
||||
"tui",
|
||||
]
|
||||
|
@ -1,2 +1,3 @@
|
||||
mod string_table_enum;
|
||||
mod commands;
|
||||
pub mod packet_scale;
|
||||
mod string_table_enum;
|
||||
|
23
src/rust/lqos_utils/src/packet_scale.rs
Normal file
23
src/rust/lqos_utils/src/packet_scale.rs
Normal file
@ -0,0 +1,23 @@
|
||||
pub fn scale_packets(n: u64) -> String {
|
||||
if n > 1_000_000_000 {
|
||||
format!("{:.2} gpps", n as f32 / 1_000_000_000.0)
|
||||
} else if n > 1_000_000 {
|
||||
format!("{:.2} mpps", n as f32 / 1_000_000.0)
|
||||
} else if n > 1_000 {
|
||||
format!("{:.2} kpps", n as f32 / 1_000.0)
|
||||
} else {
|
||||
format!("{n} pps")
|
||||
}
|
||||
}
|
||||
|
||||
pub fn scale_bits(n: u64) -> String {
|
||||
if n > 1_000_000_000 {
|
||||
format!("{:.2} gbit/s", n as f32 / 1_000_000_000.0)
|
||||
} else if n > 1_000_000 {
|
||||
format!("{:.2} mbit/s", n as f32 / 1_000_000.0)
|
||||
} else if n > 1_000 {
|
||||
format!("{:.2} kbit/s", n as f32 / 1_000.0)
|
||||
} else {
|
||||
format!("{n} bit/s")
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@ edition = "2021"
|
||||
[dependencies]
|
||||
tokio = { version = "1.22", features = [ "rt", "macros", "net", "io-util", "time" ] }
|
||||
lqos_bus = { path = "../lqos_bus" }
|
||||
lqos_utils = { path = "../lqos_utils" }
|
||||
anyhow = "1"
|
||||
tui = "0.19"
|
||||
crossterm = { version = "0.19", features = [ "serde" ] }
|
||||
|
@ -4,6 +4,7 @@ use crossterm::{
|
||||
terminal::{enable_raw_mode, size},
|
||||
};
|
||||
use lqos_bus::{BusClient, BusRequest, BusResponse, IpStats};
|
||||
use lqos_utils::packet_scale::{scale_bits,scale_packets};
|
||||
use std::{io, time::Duration};
|
||||
use tui::{
|
||||
backend::CrosstermBackend,
|
||||
@ -75,30 +76,6 @@ fn draw_menu<'a>(is_connected: bool) -> Paragraph<'a> {
|
||||
para
|
||||
}
|
||||
|
||||
fn scale_packets(n: u64) -> String {
|
||||
if n > 1_000_000_000 {
|
||||
format!("{:.2} gpps", n as f32 / 1_000_000_000.0)
|
||||
} else if n > 1_000_000 {
|
||||
format!("{:.2} mpps", n as f32 / 1_000_000.0)
|
||||
} else if n > 1_000 {
|
||||
format!("{:.2} kpps", n as f32 / 1_000.0)
|
||||
} else {
|
||||
format!("{n} pps")
|
||||
}
|
||||
}
|
||||
|
||||
fn scale_bits(n: u64) -> String {
|
||||
if n > 1_000_000_000 {
|
||||
format!("{:.2} gbit/s", n as f32 / 1_000_000_000.0)
|
||||
} else if n > 1_000_000 {
|
||||
format!("{:.2} mbit/s", n as f32 / 1_000_000.0)
|
||||
} else if n > 1_000 {
|
||||
format!("{:.2} kbit/s", n as f32 / 1_000.0)
|
||||
} else {
|
||||
format!("{n} bit/s")
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_pps<'a>(
|
||||
packets_per_second: (u64, u64),
|
||||
bits_per_second: (u64, u64),
|
||||
|
Loading…
Reference in New Issue
Block a user