From c329428609c7d6da003603f993c5a2895960a7ab Mon Sep 17 00:00:00 2001 From: yggverse Date: Sat, 28 Mar 2026 20:32:32 +0200 Subject: [PATCH] set uptime format to float; update minor version as api changed --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/main.rs | 4 ++-- src/stats.rs | 2 +- src/stats/snap.rs | 22 +++++++++++----------- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f1d83bc..1053a0e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1429,7 +1429,7 @@ dependencies = [ [[package]] name = "psocks" -version = "0.5.0" +version = "0.6.0" dependencies = [ "anyhow", "env_logger", diff --git a/Cargo.toml b/Cargo.toml index f5e3acd..a106003 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "psocks" -version = "0.5.0" +version = "0.6.0" edition = "2024" license = "MIT" readme = "README.md" diff --git a/src/main.rs b/src/main.rs index 19797d7..b6a780e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,7 +27,7 @@ async fn index( let r = rules.read().await; Json(totals.inner().snap( stats::Rules::from_totals(r.total(true), r.total(false)), - startup_time.elapsed().as_secs(), + startup_time.elapsed().as_secs_f32(), )) } @@ -40,7 +40,7 @@ async fn api_totals( let r = rules.read().await; Json(totals.inner().snap( stats::Rules::from_totals(r.total(true), r.total(false)), - startup_time.elapsed().as_secs(), + startup_time.elapsed().as_secs_f32(), )) } diff --git a/src/stats.rs b/src/stats.rs index 9f81dbf..b1d27e2 100644 --- a/src/stats.rs +++ b/src/stats.rs @@ -11,7 +11,7 @@ pub struct Total { } impl Total { - pub fn snap(&self, rules: Rules, seconds_from_startup: u64) -> Snap { + pub fn snap(&self, rules: Rules, seconds_from_startup: f32) -> Snap { Snap::shot( rules, self.request.load(Ordering::Relaxed), diff --git a/src/stats/snap.rs b/src/stats/snap.rs index 16013c7..adde86a 100644 --- a/src/stats/snap.rs +++ b/src/stats/snap.rs @@ -2,19 +2,19 @@ use rocket::serde::Serialize; #[derive(Serialize)] pub struct Up { - seconds: u64, - minutes: u64, - hours: u64, - days: u64, - weeks: u64, + seconds: f32, + minutes: f32, + hours: f32, + days: f32, + weeks: f32, } impl Up { - pub fn from_startup_seconds(seconds: u64) -> Self { - let minutes = seconds / 60; - let hours = minutes / 60; - let days = hours / 24; - let weeks = days / 7; + pub fn from_startup_seconds(seconds: f32) -> Self { + let minutes = seconds / 60.; + let hours = minutes / 60.; + let days = hours / 24.; + let weeks = days / 7.; Self { seconds, minutes, @@ -63,7 +63,7 @@ pub struct Snap { } impl Snap { - pub fn shot(rules: Rules, request: u64, blocked: u64, seconds_from_startup: u64) -> Self { + pub fn shot(rules: Rules, request: u64, blocked: u64, seconds_from_startup: f32) -> Self { let blocked_percent = if request > 0 { blocked as f32 * 100.0 / request as f32 } else {