fix: p2pool side chain HR unit scale and private stats winner

This commit is contained in:
Cyrix126 2024-03-29 13:49:56 +01:00
parent 6dcb393fce
commit 55cf2bc820
2 changed files with 26 additions and 7 deletions

View file

@ -76,7 +76,11 @@ impl Helper {
ehr ehr
); );
// multiply by a thousand because value is given as kH/s instead H/s // multiply by a thousand because value is given as kH/s instead H/s
lock!(gui_api).sidechain_ehr = ehr * 1000.0; lock!(gui_api).sidechain_ehr = ehr;
debug!(
"P2pool | PTY getting current estimated HR data from status: {} H/s",
lock!(gui_api).sidechain_ehr
);
} else { } else {
error!("P2pool | PTY Getting data from status: Lines contains Your shares but no value found: {}", line); error!("P2pool | PTY Getting data from status: Lines contains Your shares but no value found: {}", line);
} }
@ -211,13 +215,13 @@ impl Helper {
} }
// Takes in a 95-char Monero address, returns the first and last // Takes in a 95-char Monero address, returns the first and last
// 6 characters separated with dots like so: [4abcde...abcdef] // 8 characters separated with dots like so: [4abcdefg...abcdefgh]
pub fn head_tail_of_monero_address(address: &str) -> String { pub fn head_tail_of_monero_address(address: &str) -> String {
if address.len() < 95 { if address.len() < 95 {
return "???".to_string(); return "???".to_string();
} }
let head = &address[0..6]; let head = &address[0..8];
let tail = &address[89..95]; let tail = &address[87..95];
head.to_owned() + "..." + tail head.to_owned() + "..." + tail
} }

View file

@ -17,6 +17,7 @@
// Some regexes used throughout Gupax. // Some regexes used throughout Gupax.
use log::error;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use regex::Regex; use regex::Regex;
@ -149,9 +150,23 @@ pub fn nb_current_shares(s: &str) -> Option<u32> {
None None
} }
pub fn estimated_hr(s: &str) -> Option<f32> { pub fn estimated_hr(s: &str) -> Option<f32> {
static CURRENT_SHARE: Lazy<Regex> = static CURRENT_SHARE: Lazy<Regex> = Lazy::new(|| {
Lazy::new(|| Regex::new(r"(?P<nb>[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)").unwrap()); Regex::new(r"(?P<nb>[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?) (?P<unit>.*)H/s").unwrap()
});
if let Some(c) = CURRENT_SHARE.captures(s) { if let Some(c) = CURRENT_SHARE.captures(s) {
let coeff = if let Some(unit) = c.name("unit") {
match unit.as_str() {
"K" => 1000,
"M" => 1000 * 1000,
"G" => 1000 * 1000 * 1000,
_ => {
error!("unit of your p2pool sidechain HR is not recognized.");
1
}
}
} else {
1
} as f32;
if let Some(m) = c.name("nb") { if let Some(m) = c.name("nb") {
return Some( return Some(
m.as_str().parse::<f32>().expect( m.as_str().parse::<f32>().expect(
@ -160,7 +175,7 @@ pub fn estimated_hr(s: &str) -> Option<f32> {
m.as_str(), m.as_str(),
] ]
.concat(), .concat(),
), ) * coeff,
); );
} }
} }