Skip to content

Commit

Permalink
add total; 0.0.18
Browse files Browse the repository at this point in the history
  • Loading branch information
the2pizza committed Oct 29, 2024
1 parent 79b9da9 commit f2c2f22
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pony"
version = "0.0.17"
version = "0.0.18"
edition = "2021"

[dependencies]
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use crate::web::not_found;

#[derive(Parser)]
#[command(
version = "0.0.17",
version = "0.0.18",
about = "Pony - montiroing tool for Xray/Wireguard"
)]
struct Cli {
Expand Down Expand Up @@ -77,7 +77,7 @@ async fn main() -> std::io::Result<()> {
std::process::exit(1);
} else {
info!(">>> Settings: {:?}", settings);
info!(">>> Version: 0.0.17");
info!(">>> Version: 0.0.18");
}

let carbon_server = settings.carbon.address.clone();
Expand Down
22 changes: 19 additions & 3 deletions src/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn convert_bps_to_mbps(rx: Bps, tx: Bps) -> MbpsByServer {
server_list
}

type ConnectionsByServer = HashMap<String, Vec<HashMap<String, f64>>>;
type ConnectionsByServer = HashMap<String, Vec<Connection>>;

fn convert_connections(connections: ConnectionsByType) -> ConnectionsByServer {
let mut server_map: ConnectionsByServer = HashMap::new();
Expand All @@ -69,16 +69,32 @@ fn convert_connections(connections: ConnectionsByType) -> ConnectionsByServer {
("ss", connections.ss),
("wg", connections.wg),
] {
for conn in conn_list {
for conn in conn_list.clone() {
for (server, &value) in &conn.connection {
server_map
.entry(server.clone())
.or_insert_with(Vec::new)
.push(HashMap::from([(conn_type.to_string(), value)]));
.push(Connection {
connection: HashMap::from([(conn_type.to_string(), value)]),
});
}
}
}

for (_, conn_list) in &mut server_map {
let mut total = 0.0;

for conn in conn_list.iter() {
for &value in conn.connection.values() {
total += value;
}
}

conn_list.push(Connection {
connection: HashMap::from([("total".to_string(), total)]),
});
}

server_map
}

Expand Down

0 comments on commit f2c2f22

Please sign in to comment.