Skip to content

Commit

Permalink
feat: improve hashrate and time display on Status tab
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyrix126 committed Dec 12, 2024
1 parent 16281c8 commit 2c2b5b2
Show file tree
Hide file tree
Showing 8 changed files with 212 additions and 122 deletions.
12 changes: 6 additions & 6 deletions src/app/panels/middle/status/p2pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,21 +234,21 @@ impl Status {
RichText::new("P2Pool Block Mean").underline().color(BONE),
)
.on_hover_text(STATUS_SUBMENU_P2POOL_BLOCK_MEAN);
ui.label(api.p2pool_block_mean.to_string());
ui.label(api.p2pool_block_mean.display(false));
ui.label(
RichText::new("Your P2Pool Share Mean")
.underline()
.color(BONE),
)
.on_hover_text(STATUS_SUBMENU_P2POOL_SHARE_MEAN);
ui.label(p2pool_share_mean.to_string());
ui.label(p2pool_share_mean.display(false));
ui.label(
RichText::new("Your Solo Block Mean")
.underline()
.color(BONE),
)
.on_hover_text(STATUS_SUBMENU_SOLO_BLOCK_MEAN);
ui.label(solo_block_mean.to_string());
ui.label(solo_block_mean.display(false));
} else {
ui.label(
RichText::new("Your P2Pool Hashrate")
Expand All @@ -261,21 +261,21 @@ impl Status {
RichText::new("P2Pool Block Mean").underline().color(BONE),
)
.on_hover_text(STATUS_SUBMENU_P2POOL_BLOCK_MEAN);
ui.label(api.p2pool_block_mean.to_string());
ui.label(api.p2pool_block_mean.display(false));
ui.label(
RichText::new("Your P2Pool Share Mean")
.underline()
.color(BONE),
)
.on_hover_text(STATUS_SUBMENU_P2POOL_SHARE_MEAN);
ui.label(api.p2pool_share_mean.to_string());
ui.label(api.p2pool_share_mean.display(false));
ui.label(
RichText::new("Your Solo Block Mean")
.underline()
.color(BONE),
)
.on_hover_text(STATUS_SUBMENU_SOLO_BLOCK_MEAN);
ui.label(api.solo_block_mean.to_string());
ui.label(api.solo_block_mean.display(false));
}
})
});
Expand Down
59 changes: 44 additions & 15 deletions src/app/panels/middle/status/processes.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use egui::{ScrollArea, Ui};
use egui::{Label, ScrollArea, Ui};
use std::sync::{Arc, Mutex};

use crate::app::eframe_impl::ProcessStatesGui;
Expand Down Expand Up @@ -30,7 +30,7 @@ impl Status {
states: &ProcessStatesGui,
) {
let width_column = ui.text_style_height(&TextStyle::Body) * 16.0;
let height_column = width_column * 2.5;
let height_column = width_column * 2.7;
ui.style_mut().wrap_mode = Some(egui::TextWrapMode::Extend);
// let width = ((ui.available_width() / 5.0) - (SPACE * 1.7500)).max(0.0);
ScrollArea::vertical().show(ui, |ui| {
Expand Down Expand Up @@ -121,7 +121,14 @@ fn gupax(ui: &mut Ui, sys: &Arc<Mutex<Sys>>) {
let sys = sys.lock().unwrap();
ui.label(RichText::new("Uptime").underline().color(BONE))
.on_hover_text(STATUS_GUPAX_UPTIME);
ui.label(sys.gupax_uptime.to_string());
// put some space for uptime so that when seconds appears every minutes, no label is moved.
ui.add_sized(
[
0.0,
(ui.text_style_height(&TextStyle::Body) + ui.spacing().item_spacing.y) * 1.5,
],
Label::new(sys.gupax_uptime.to_string()),
);
ui.label(RichText::new("Gupaxx CPU").underline().color(BONE))
.on_hover_text(STATUS_GUPAX_CPU_USAGE);
ui.label(sys.gupax_cpu_usage.to_string());
Expand Down Expand Up @@ -159,7 +166,14 @@ fn p2pool(
let api = p2pool_api.lock().unwrap();
ui.label(RichText::new("Uptime").underline().color(BONE))
.on_hover_text(STATUS_P2POOL_UPTIME);
ui.label(format!("{}", api.uptime));
// put some space for uptime so that when seconds appears every minutes, no label is moved.
ui.add_sized(
[
0.0,
(ui.text_style_height(&TextStyle::Body) + ui.spacing().item_spacing.y) * 1.5,
],
Label::new(api.uptime.display(true)),
);
ui.label(RichText::new("Current Shares").underline().color(BONE))
.on_hover_text(STATUS_P2POOL_CURRENT_SHARES);
ui.label(api.sidechain_shares.to_string());
Expand Down Expand Up @@ -193,10 +207,7 @@ fn p2pool(
.color(BONE),
)
.on_hover_text(STATUS_P2POOL_HASHRATE);
ui.label(format!(
"[{} H/s]\n[{} H/s]\n[{} H/s]",
api.hashrate_15m, api.hashrate_1h, api.hashrate_24h
));
ui.label(&api.hashrate);
ui.label(RichText::new("Miners Connected").underline().color(BONE))
.on_hover_text(STATUS_P2POOL_CONNECTIONS);
ui.label(format!("{}", api.connections));
Expand Down Expand Up @@ -240,17 +251,21 @@ fn xmrig_proxy(
let api = xmrig_proxy_api.lock().unwrap();
ui.label(RichText::new("Uptime").underline().color(BONE))
.on_hover_text(STATUS_XMRIG_PROXY_UPTIME);
ui.label(api.uptime.to_string());
// put some space for uptime so that when seconds appears every minutes, no label is moved.
ui.add_sized(
[
0.0,
(ui.text_style_height(&TextStyle::Body) + ui.spacing().item_spacing.y) * 1.5,
],
Label::new(api.uptime.display(true)),
);
ui.label(
RichText::new("Hashrate\n(1m/10m/1h/12h/24h)")
.underline()
.color(BONE),
)
.on_hover_text(STATUS_XMRIG_PROXY_HASHRATE);
ui.label(format!(
"[{} H/s]\n[{} H/s]\n[{} H/s]\n[{} H/s]\n[{} H/s]",
api.hashrate_1m, api.hashrate_10m, api.hashrate_1h, api.hashrate_12h, api.hashrate_24h
));
ui.label(&api.hashrate);
ui.label(format!(
"[Accepted: {}]\n[Rejected: {}]",
api.accepted, api.rejected
Expand Down Expand Up @@ -282,7 +297,14 @@ fn xmrig(
let api = xmrig_api.lock().unwrap();
ui.label(RichText::new("Uptime").underline().color(BONE))
.on_hover_text(STATUS_XMRIG_UPTIME);
ui.label(api.uptime.to_string());
// put some space for uptime so that when seconds appears every minutes, no label is moved.
ui.add_sized(
[
0.0,
(ui.text_style_height(&TextStyle::Body) + ui.spacing().item_spacing.y) * 1.5,
],
Label::new(api.uptime.display(true)),
);
ui.label(api.resources.to_string());
ui.label(
RichText::new("Hashrate\n(10s/1m/15m)")
Expand Down Expand Up @@ -407,7 +429,14 @@ fn node(ui: &mut Ui, node_alive: bool, node_api: &Arc<Mutex<PubNodeApi>>) {
let api = node_api.lock().unwrap();
ui.label(RichText::new("Uptime").underline().color(BONE))
.on_hover_text(STATUS_NODE_UPTIME);
ui.label(api.uptime.to_string());
// put some space for uptime so that when seconds appears every minutes, no label is moved.
ui.add_sized(
[
0.0,
(ui.text_style_height(&TextStyle::Body) + ui.spacing().item_spacing.y) * 1.5,
],
Label::new(api.uptime.display(true)),
);

ui.label(RichText::new("Block Height").underline().color(BONE))
.on_hover_text(STATUS_NODE_BLOCK_HEIGHT);
Expand Down
22 changes: 17 additions & 5 deletions src/helper/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ impl Helper {
helper: &Helper,
max_threads: u16,
) {
let gupax_uptime = helper.uptime.to_string();
let gupax_uptime = helper.uptime.display(true);
let cpu = &sysinfo.cpus()[0];
let gupax_cpu_usage = format!(
"{:.2}%",
Expand Down Expand Up @@ -793,14 +793,20 @@ fn signal_end(
let uptime = HumanTime::into_human(start.elapsed());
info!(
"{} Watchdog | Stopped ... Uptime was: [{}], Exit status: [{}]",
process.name, uptime, exit_status
process.name,
uptime.display(false),
exit_status
);
// This is written directly into the GUI API, because sometimes the 900ms event loop can't catch it.
let name = process.name.to_owned();
if let Err(e) = writeln!(
gui_api_output_raw,
"{}\n{} stopped | Uptime: [{}] | Exit status: [{}]\n{}\n\n\n\n",
name, HORI_CONSOLE, uptime, exit_status, HORI_CONSOLE
name,
HORI_CONSOLE,
uptime.display(false),
exit_status,
HORI_CONSOLE
) {
error!(
"{} Watchdog | GUI Uptime/Exit status write failed: {}",
Expand Down Expand Up @@ -831,14 +837,20 @@ fn signal_end(
let uptime = HumanTime::into_human(start.elapsed());
info!(
"{} Watchdog | Stopped ... Uptime was: [{}], Exit status: [{}]",
process.name, uptime, exit_status
process.name,
uptime.display(false),
exit_status
);
// This is written directly into the GUI API, because sometimes the 900ms event loop can't catch it.
let name = process.name.to_owned();
if let Err(e) = writeln!(
gui_api_output_raw,
"{}\n{} stopped | Uptime: [{}] | Exit status: [{}]\n{}\n\n\n\n",
name, HORI_CONSOLE, uptime, exit_status, HORI_CONSOLE
name,
HORI_CONSOLE,
uptime.display(false),
exit_status,
HORI_CONSOLE
) {
error!(
"{} Watchdog | GUI Uptime/Exit status write failed: {}",
Expand Down
26 changes: 17 additions & 9 deletions src/helper/p2pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -706,9 +706,10 @@ pub struct PubP2poolApi {
pub xmr_day: f64,
pub xmr_month: f64,
// Local API
pub hashrate_15m: HumanNumber,
pub hashrate_1h: HumanNumber,
pub hashrate_24h: HumanNumber,
pub hashrate: String,
pub hashrate_15m: u64,
pub hashrate_1h: u64,
pub hashrate_24h: u64,
pub shares_found: Option<u64>,
pub average_effort: HumanNumber,
pub current_effort: HumanNumber,
Expand Down Expand Up @@ -766,9 +767,10 @@ impl PubP2poolApi {
xmr_hour: 0.0,
xmr_day: 0.0,
xmr_month: 0.0,
hashrate_15m: HumanNumber::unknown(),
hashrate_1h: HumanNumber::unknown(),
hashrate_24h: HumanNumber::unknown(),
hashrate: HumanNumber::from_hashrate(&[None, None, None]).to_string(),
hashrate_15m: 0,
hashrate_1h: 0,
hashrate_24h: 0,
shares_found: None,
average_effort: HumanNumber::unknown(),
current_effort: HumanNumber::unknown(),
Expand Down Expand Up @@ -940,9 +942,15 @@ impl PubP2poolApi {
// Mutate [PubP2poolApi] with data from a [PrivP2poolLocalApi] and the process output.
pub(super) fn update_from_local(public: &mut Self, local: PrivP2poolLocalApi) {
*public = Self {
hashrate_15m: HumanNumber::from_u64(local.hashrate_15m),
hashrate_1h: HumanNumber::from_u64(local.hashrate_1h),
hashrate_24h: HumanNumber::from_u64(local.hashrate_24h),
hashrate: HumanNumber::from_hashrate(&[
Some(local.hashrate_15m),
Some(local.hashrate_1h),
Some(local.hashrate_24h),
])
.to_string(),
hashrate_15m: local.hashrate_15m,
hashrate_1h: local.hashrate_1h,
hashrate_24h: local.hashrate_24h,
shares_found: Some(local.shares_found),
average_effort: HumanNumber::to_percent(local.average_effort),
current_effort: HumanNumber::to_percent(local.current_effort),
Expand Down
16 changes: 8 additions & 8 deletions src/helper/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,9 @@ Uptime = 0h 2m 4s
let mut p = public.lock().unwrap();
PubP2poolApi::update_from_local(&mut p, local);
println!("AFTER LOCAL: {:#?}", p);
assert_eq!(p.hashrate_15m.to_string(), "10,000");
assert_eq!(p.hashrate_1h.to_string(), "20,000");
assert_eq!(p.hashrate_24h.to_string(), "30,000");
assert_eq!(p.hashrate_15m.to_string(), "10000");
assert_eq!(p.hashrate_1h.to_string(), "20000");
assert_eq!(p.hashrate_24h.to_string(), "30000");
assert_eq!(
p.shares_found.expect("the value is set").to_string(),
"1000"
Expand All @@ -297,14 +297,14 @@ Uptime = 0h 2m 4s
assert_eq!(p.p2pool_hashrate.to_string(), "1.000 MH/s");
assert_eq!(p.miners.to_string(), "1,000");
assert_eq!(
p.solo_block_mean.to_string(),
"5 months\n21 days\n9 hours\n52 minutes"
p.solo_block_mean.display(false),
"5 months, 21 days, 9 hours, 52 minutes"
);
assert_eq!(
p.p2pool_block_mean.to_string(),
"3 days\n11 hours\n20 minutes"
p.p2pool_block_mean.display(false),
"3 days, 11 hours, 20 minutes"
);
assert_eq!(p.p2pool_share_mean.to_string(), "8 minutes\n20 seconds");
assert_eq!(p.p2pool_share_mean.display(false), "8 minutes, 20 seconds");
assert_eq!(p.p2pool_percent.to_string(), "0.040000%");
assert_eq!(p.user_p2pool_percent.to_string(), "2.000000%");
assert_eq!(p.user_monero_percent.to_string(), "0.000800%");
Expand Down
9 changes: 7 additions & 2 deletions src/helper/xrig/xmrig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -793,11 +793,16 @@ impl PubXmrigApi {
Some(Some(h)) => *h,
_ => 0.0,
};

let total_hasrate = private
.hashrate
.total
.iter()
.map(|x| x.as_ref().map(|y| *y as u64))
.collect::<Vec<Option<u64>>>();
*public = Self {
worker_id: private.worker_id,
resources: HumanNumber::from_load(private.resources.load_average).to_string(),
hashrate: HumanNumber::from_hashrate(private.hashrate.total).to_string(),
hashrate: HumanNumber::from_hashrate(&total_hasrate).to_string(),
diff: Unsigned::from(private.connection.diff as usize).to_string(),
accepted: Unsigned::from(private.connection.accepted as usize).to_string(),
rejected: Unsigned::from(private.connection.rejected as usize).to_string(),
Expand Down
13 changes: 12 additions & 1 deletion src/helper/xrig/xmrig_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::{
};
use tokio::spawn;

use crate::human::HumanTime;
use crate::human::{HumanNumber, HumanTime};
use crate::miscs::client;
use crate::{
GUPAX_VERSION_UNDERSCORE, UNKNOWN_DATA,
Expand Down Expand Up @@ -467,12 +467,14 @@ impl Helper {
// sleep
}
}
#[allow(unused)]
#[derive(Debug, Clone)]
pub struct PubXmrigProxyApi {
pub output: String,
pub uptime: HumanTime,
pub accepted: u32,
pub rejected: u32,
pub hashrate: String,
pub hashrate_1m: f32,
pub hashrate_10m: f32,
pub hashrate_1h: f32,
Expand All @@ -493,6 +495,7 @@ impl PubXmrigProxyApi {
uptime: HumanTime::new(),
accepted: 0,
rejected: 0,
hashrate: HumanNumber::from_hashrate(&[None, None, None, None, None, None]).to_string(),
hashrate_1m: 0.0,
hashrate_10m: 0.0,
hashrate_1h: 0.0,
Expand Down Expand Up @@ -555,9 +558,17 @@ impl PubXmrigProxyApi {
}
fn update_from_priv(public: &Arc<Mutex<Self>>, private: PrivXmrigProxyApi) {
let mut public = public.lock().unwrap();
let mut total_hashrate = private
.hashrate
.total
.iter()
.map(|x| Some(*x as u64))
.collect::<Vec<Option<u64>>>();
total_hashrate.remove(5);
*public = Self {
accepted: private.results.accepted,
rejected: private.results.rejected,
hashrate: HumanNumber::from_hashrate(&total_hashrate).to_string(),
hashrate_1m: private.hashrate.total[0],
hashrate_10m: private.hashrate.total[1],
hashrate_1h: private.hashrate.total[2],
Expand Down
Loading

0 comments on commit 2c2b5b2

Please sign in to comment.