diff --git a/src/helper.rs b/src/helper.rs index 1dd58f4..db02343 100644 --- a/src/helper.rs +++ b/src/helper.rs @@ -1249,6 +1249,8 @@ pub struct PubP2poolApi { pub user_p2pool_hashrate_u64: u64, pub p2pool_difficulty_u64: u64, pub monero_difficulty_u64: u64, + pub p2pool_hashrate_u64: u64, + pub monero_hashrate_u64: u64, // Tick. Every loop this gets incremented. // At 60, it indicated we should read the below API files. pub tick: u8, @@ -1302,6 +1304,8 @@ impl PubP2poolApi { user_p2pool_hashrate_u64: 0, p2pool_difficulty_u64: 0, monero_difficulty_u64: 0, + p2pool_hashrate_u64: 0, + monero_hashrate_u64: 0, monero_difficulty: HumanNumber::unknown(), monero_hashrate: HumanNumber::unknown(), hash: String::from("???"), @@ -1439,8 +1443,8 @@ impl PubP2poolApi { user_p2pool_percent = HumanNumber::unknown(); } else { p2pool_block_mean = HumanTime::into_human(std::time::Duration::from_secs(monero_difficulty / p2pool_hashrate)); - let f = (user_hashrate as f32 / p2pool_hashrate as f32) * 100.0; - user_p2pool_percent = HumanNumber::to_percent_no_fmt(f); + let f = (user_hashrate as f64 / p2pool_hashrate as f64) * 100.0; + user_p2pool_percent = HumanNumber::from_f64_to_percent_6_point(f); }; let p2pool_percent; let user_monero_percent; @@ -1448,10 +1452,10 @@ impl PubP2poolApi { p2pool_percent = HumanNumber::unknown(); user_monero_percent = HumanNumber::unknown(); } else { - let f = (p2pool_hashrate as f32 / monero_hashrate as f32) * 100.0; - p2pool_percent = HumanNumber::to_percent_no_fmt(f); - let f = (user_hashrate as f32 / monero_hashrate as f32) * 100.0; - user_monero_percent = HumanNumber::to_percent_no_fmt(f); + let f = (p2pool_hashrate as f64 / monero_hashrate as f64) * 100.0; + p2pool_percent = HumanNumber::from_f64_to_percent_6_point(f); + let f = (user_hashrate as f64 / monero_hashrate as f64) * 100.0; + user_monero_percent = HumanNumber::from_f64_to_percent_6_point(f); }; let solo_block_mean; let p2pool_share_mean; @@ -1466,6 +1470,8 @@ impl PubP2poolApi { *public = Self { p2pool_difficulty_u64: p2pool_difficulty, monero_difficulty_u64: monero_difficulty, + p2pool_hashrate_u64: p2pool_hashrate, + monero_hashrate_u64: monero_hashrate, monero_difficulty: HumanNumber::from_u64(monero_difficulty), monero_hashrate: HumanNumber::from_u64_to_gigahash_3_point(monero_hashrate), hash: net.hash, @@ -1492,6 +1498,15 @@ impl PubP2poolApi { } } + pub fn calculate_dominance(my_hashrate: u64, global_hashrate: u64) -> HumanNumber { + if global_hashrate == 0 { + HumanNumber::unknown() + } else { + let f = (my_hashrate as f64 / global_hashrate as f64) * 100.0; + HumanNumber::from_f64_to_percent_6_point(f) + } + } + pub const fn calculate_tick_bar(&self) -> &'static str { // The stars are reduced by one because it takes a frame to render the stats. // We want 0 stars at the same time stats are rendered, so it looks a little off here. diff --git a/src/human.rs b/src/human.rs index 4bf267a..8e78d8e 100644 --- a/src/human.rs +++ b/src/human.rs @@ -129,6 +129,18 @@ impl HumanNumber { pub fn to_percent_no_fmt(f: f32) -> Self { Self(format!("{}%", f)) } + pub fn from_f64_to_percent_3_point(f: f64) -> Self { + Self(format!("{:.3}%", f)) + } + pub fn from_f64_to_percent_6_point(f: f64) -> Self { + Self(format!("{:.6}%", f)) + } + pub fn from_f64_to_percent_9_point(f: f64) -> Self { + Self(format!("{:.9}%", f)) + } + pub fn from_f64_to_percent_no_fmt(f: f64) -> Self { + Self(format!("{}%", f)) + } pub fn from_f32(f: f32) -> Self { let mut buf = num_format::Buffer::new(); buf.write_formatted(&(f as u64), &LOCALE); diff --git a/src/status.rs b/src/status.rs index 0523251..7a6b949 100644 --- a/src/status.rs +++ b/src/status.rs @@ -203,13 +203,24 @@ pub fn show(&mut self, sys: &Arc>, p2pool_api: &Arc>, p2pool_api: &Arc