Skip to content

Commit

Permalink
feat: finish XvB Tab with private stats and better log output
Browse files Browse the repository at this point in the history
fix: color code status
feat: reload automaticcly XvB process if p2pool is off/online
feat: add all 5 private stat in a pretty way outside of console
feat: begin to use readable to replace human.rs
feat: function to verify if share is in current window
  • Loading branch information
Cyrix126 committed Mar 15, 2024
1 parent ecb1dd2 commit 62c2148
Show file tree
Hide file tree
Showing 11 changed files with 322 additions and 105 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ egui = "0.26.2"
egui_extras = { version = "0.26.2", features = ["image"] }
## 2023-12-28: https://github.com/hinto-janai/gupax/issues/68
eframe = { version = "0.26.2", default-features = false, features = ["glow"] }

## 2023-02-06: The below gets fixed by using the [wgpu] backend instead of [glow]
## It also fixes crashes on CPU-based graphics. Only used for Windows.
## Using [wgpu] actually crashes macOS (fixed in 0.20.x though).
Expand Down Expand Up @@ -82,7 +81,7 @@ serde-this-or-that = "0.4.2"
tar = "0.4.40"
flate2 = "1.0"
sudo = "0.6.0"

readable = "0.16"
# macOS
[target.'cfg(target_os = "macos")'.dependencies]
# On apple-darwin targets there is an issue with the native and rustls
Expand All @@ -97,6 +96,8 @@ openssl = { version = "0.10", features = ["vendored"] }
# We don't even use `xz` in `flate2` but this gets dynamically
# linked as well which causes problems, so statically link it.
lzma-sys = { version = "0.1.20", features = ["static"] }
[dev-dependencies]
egui = {version = "0.26.2", features=["callstack"]}

[target.'cfg(not(target_os = "macos"))'.dependencies]
tls-api-native-tls = "0.9.0"
Expand Down
4 changes: 2 additions & 2 deletions src/app/panels/bottom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,11 +644,11 @@ fn status_xvb(state: ProcessState, ui: &mut Ui, size: Vec2) {
color = RED;
XVB_FAILED
}
NotMining => {
NotMining | Syncing => {
color = ORANGE;
XVB_PUBLIC_ONLY
}
Middle | Waiting | Syncing => {
Middle | Waiting => {
color = YELLOW;
XVB_MIDDLE
}
Expand Down
28 changes: 15 additions & 13 deletions src/app/panels/middle/status/benchmarks.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use std::sync::{Arc, Mutex};

use crate::{
app::Benchmark, disk::state::Status, helper::xmrig::PubXmrigApi, utils::human::HumanNumber,
};
use crate::{app::Benchmark, disk::state::Status, helper::xmrig::PubXmrigApi};
use egui::{Hyperlink, ProgressBar, Spinner, Vec2};
use readable::num::{Float, Percent, Unsigned};

use crate::utils::macros::lock;

Expand Down Expand Up @@ -67,7 +66,7 @@ impl Status {
.on_hover_text(STATUS_SUBMENU_YOUR_HIGH);
ui.add_sized(
[width, text],
Label::new(format!("{} H/s", HumanNumber::from_f32(cpu.high))),
Label::new(format!("{} H/s", Float::from_0(cpu.high.into()))),
);
ui.add_sized(
[width, text],
Expand All @@ -76,7 +75,7 @@ impl Status {
.on_hover_text(STATUS_SUBMENU_YOUR_AVERAGE);
ui.add_sized(
[width, text],
Label::new(format!("{} H/s", HumanNumber::from_f32(cpu.average))),
Label::new(format!("{} H/s", Float::from_0(cpu.average.into()))),
);
ui.add_sized(
[width, text],
Expand All @@ -85,7 +84,7 @@ impl Status {
.on_hover_text(STATUS_SUBMENU_YOUR_LOW);
ui.add_sized(
[width, text],
Label::new(format!("{} H/s", HumanNumber::from_f32(cpu.low))),
Label::new(format!("{} H/s", Float::from_0(cpu.low.into()))),
);
})
})
Expand All @@ -96,7 +95,7 @@ impl Status {
if xmrig_alive {
let api = lock!(xmrig_api);
let percent = (api.hashrate_raw / cpu.high) * 100.0;
let human = HumanNumber::to_percent(percent);
let human = Percent::from(percent);
if percent > 100.0 {
ui.add_sized(
[width, double],
Expand Down Expand Up @@ -188,31 +187,34 @@ impl Status {
ui.add_sized([cpu, text], Label::new(benchmark.cpu.as_str()));
ui.separator();
ui.add_sized([bar, text], ProgressBar::new(benchmark.percent / 100.0))
.on_hover_text(HumanNumber::to_percent(benchmark.percent).as_str());
.on_hover_text(Percent::from(benchmark.percent).as_str());
ui.separator();
ui.add_sized(
[high, text],
Label::new(HumanNumber::to_hashrate(benchmark.high).as_str()),
Label::new(format!("{} H/s", Float::from_0(benchmark.high.into()))),
);
ui.separator();
ui.add_sized(
[average, text],
Label::new(HumanNumber::to_hashrate(benchmark.average).as_str()),
Label::new(format!(
"{} H/s",
Float::from_0(benchmark.average.into())
)),
);
ui.separator();
ui.add_sized(
[low, text],
Label::new(HumanNumber::to_hashrate(benchmark.low).as_str()),
Label::new(format!("{} H/s", Float::from_0(benchmark.low.into()))),
);
ui.separator();
ui.add_sized(
[rank, text],
Label::new(HumanNumber::from_u16(benchmark.rank).as_str()),
Label::new(Float::from(benchmark.low).as_str()),
);
ui.separator();
ui.add_sized(
[bench, text],
Label::new(HumanNumber::from_u16(benchmark.benchmarks).as_str()),
Label::new(Unsigned::from(benchmark.benchmarks).as_str()),
);
})
});
Expand Down
5 changes: 3 additions & 2 deletions src/app/panels/middle/status/p2pool.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::sync::{Arc, Mutex};

use egui::{Label, RichText, SelectableLabel, Slider, TextEdit, Vec2};
use readable::num::Unsigned;

use crate::{
disk::{
Expand All @@ -9,7 +10,7 @@ use crate::{
status::{Hash, PayoutView},
},
helper::p2pool::PubP2poolApi,
utils::{constants::*, human::HumanNumber, macros::lock},
utils::{constants::*, macros::lock},
};

impl Status {
Expand Down Expand Up @@ -267,7 +268,7 @@ impl Status {
);
ui.add_sized(
[width, text],
Label::new(format!("{} H/s", HumanNumber::from_u64(hashrate))),
Label::new(format!("{} H/s", Unsigned::from(hashrate))),
);
ui.add_sized(
[width, text],
Expand Down
18 changes: 16 additions & 2 deletions src/app/panels/middle/status/processes.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use egui::{ScrollArea, Ui, Vec2};
use readable::up::UptimeFull;
use std::sync::{Arc, Mutex};

use crate::disk::state::Status;
Expand Down Expand Up @@ -164,7 +165,17 @@ fn p2pool(
Label::new(RichText::new("Shares Found").underline().color(BONE)),
)
.on_hover_text(STATUS_P2POOL_SHARES);
ui.add_sized([width, height], Label::new(format!("{}", api.shares_found)));
ui.add_sized(
[width, height],
Label::new(format!(
"{}",
if let Some(s) = api.shares_found {
s.to_string()
} else {
UNKNOWN_DATA.to_string()
}
)),
);
ui.add_sized(
[width, height],
Label::new(RichText::new("Payouts").underline().color(BONE)),
Expand Down Expand Up @@ -293,7 +304,10 @@ fn xmrig(
Label::new(RichText::new("Uptime").underline().color(BONE)),
)
.on_hover_text(STATUS_XMRIG_UPTIME);
ui.add_sized([width, height], Label::new(format!("{}", api.uptime)));
ui.add_sized(
[width, height],
Label::new(UptimeFull::from(api.uptime).as_str()),
);
ui.add_sized(
[width, height],
Label::new(
Expand Down
37 changes: 33 additions & 4 deletions src/app/panels/middle/xvb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use log::debug;
use crate::helper::xvb::PubXvbApi;
use crate::utils::constants::{
GREEN, LIGHT_GRAY, ORANGE, RED, XVB_DONATED_1H_FIELD, XVB_DONATED_24H_FIELD, XVB_FAILURE_FIELD,
XVB_HELP, XVB_HERO_SELECT, XVB_TOKEN_FIELD, XVB_TOKEN_LEN, XVB_URL_RULES,
XVB_HELP, XVB_HERO_SELECT, XVB_ROUND_TYPE_FIELD, XVB_TOKEN_FIELD, XVB_TOKEN_LEN, XVB_URL_RULES,
XVB_WINNER_FIELD,
};
use crate::utils::macros::lock;
use crate::utils::regex::Regexes;
Expand Down Expand Up @@ -125,11 +126,15 @@ impl crate::disk::state::Xvb {
// ui.vertical_centered(|ui| {
ui.horizontal(|ui| {
// widget takes a third less space for two separator.
let width_stat =
(ui.available_width() / 3.0) - (12.0 + ui.style().spacing.item_spacing.x) / 3.0;
let width_stat = (ui.available_width() / 5.0)
- ((24.0 + ui.style().spacing.item_spacing.x + SPACE) / 5.0);
// 0.0 means minimum
let height_stat = 0.0;
let size_stat = vec2(width_stat, height_stat);
let round = match &priv_stats.round_participate {
Some(r) => r.to_string(),
None => "None".to_string(),
};
ui.add_sized(size_stat, |ui: &mut Ui| {
ui.group(|ui| {
let size_stat = vec2(
Expand Down Expand Up @@ -159,12 +164,36 @@ impl crate::disk::state::Xvb {
})
.response
});
ui.separator();
ui.add_enabled_ui(priv_stats.round_participate.is_some(), |ui| {
ui.add_sized(size_stat, |ui: &mut Ui| {
ui.vertical_centered(|ui| {
ui.label(XVB_ROUND_TYPE_FIELD);
ui.label(round);
})
.response
})
.on_disabled_hover_text("You do not yet have a share in the PPLNS Window.");
});
ui.separator();
ui.add_sized(size_stat, |ui: &mut Ui| {
ui.vertical_centered(|ui| {
ui.label(XVB_WINNER_FIELD);
ui.label(
priv_stats
.win_current
.then(|| "You are Winning the round !")
.unwrap_or("You are not the winner"),
);
})
.response
});
})
.response
});
});
// Rules link help
ui.add_space(ui.available_height() / 4.0);
ui.add_space(ui.available_height() / 2.0);
ui.vertical_centered(|ui| {
ui.hyperlink_to("Rules", XVB_URL_RULES)
.on_hover_text("Click here to read the rules and understand how the raffle works.");
Expand Down
5 changes: 4 additions & 1 deletion src/helper/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,10 @@ mod test {
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.shares_found.to_string(), "1,000");
assert_eq!(
p.shares_found.expect("the value is set").to_string(),
"1,000"
);
assert_eq!(p.average_effort.to_string(), "100.00%");
assert_eq!(p.current_effort.to_string(), "200.00%");
assert_eq!(p.connections.to_string(), "1,234");
Expand Down
47 changes: 43 additions & 4 deletions src/helper/p2pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl Helper {

// Takes in a 95-char Monero address, returns the first and last
// 6 characters separated with dots like so: [4abcde...abcdef]
fn head_tail_of_monero_address(address: &str) -> String {
pub fn head_tail_of_monero_address(address: &str) -> String {
if address.len() < 95 {
return "???".to_string();
}
Expand Down Expand Up @@ -718,7 +718,7 @@ pub struct PubP2poolApi {
pub hashrate_15m: HumanNumber,
pub hashrate_1h: HumanNumber,
pub hashrate_24h: HumanNumber,
pub shares_found: HumanNumber,
pub shares_found: Option<u64>,
pub average_effort: HumanNumber,
pub current_effort: HumanNumber,
pub connections: HumanNumber,
Expand Down Expand Up @@ -775,7 +775,7 @@ impl PubP2poolApi {
hashrate_15m: HumanNumber::unknown(),
hashrate_1h: HumanNumber::unknown(),
hashrate_24h: HumanNumber::unknown(),
shares_found: HumanNumber::unknown(),
shares_found: None,
average_effort: HumanNumber::unknown(),
current_effort: HumanNumber::unknown(),
connections: HumanNumber::unknown(),
Expand Down Expand Up @@ -944,7 +944,7 @@ impl PubP2poolApi {
hashrate_15m: HumanNumber::from_u64(local.hashrate_15m),
hashrate_1h: HumanNumber::from_u64(local.hashrate_1h),
hashrate_24h: HumanNumber::from_u64(local.hashrate_24h),
shares_found: HumanNumber::from_u64(local.shares_found),
shares_found: Some(local.shares_found),
average_effort: HumanNumber::to_percent(local.average_effort),
current_effort: HumanNumber::to_percent(local.current_effort),
connections: HumanNumber::from_u32(local.connections),
Expand Down Expand Up @@ -1114,6 +1114,45 @@ impl PubP2poolApi {
_ => "[************************************************************]",
}
}
// function to know if a share is in current window.
// If new share found, an instant of when it was found.
pub(super) fn is_share_present_in_ppplns_window(
&self,
old_shares: &mut u64,
last_time_found: Option<Instant>,
mini: bool,
) -> (bool, Option<Instant>) {
if let Some(v) = self.shares_found {
if v > *old_shares {
// found new share
*old_shares = v;
return (true, Some(Instant::now()));
} else {
// no new share found this last minute, check if last share is still valid
if let Some(n) = last_time_found {
// a share was found before, is it still valid ?
let time_window = if mini {
TIME_PPLNS_WINDOW_MINI
} else {
TIME_PPLNS_WINDOW_MAIN
};
if n.elapsed() > time_window {
// if time is expired, no share is present in current PW
(false, None)
} else {
// if time is not expired, at least one is present in current PW
(true, None)
}
} else {
// no share found before and no new share found, so there is no share in current PW
(false, None)
}
}
} else {
// data from p2pool is not ready yet, so no share in pplns window.
return (false, None);
}
}
}

//---------------------------------------------------------------------------------------------------- Private P2Pool "Local" Api
Expand Down
Loading

0 comments on commit 62c2148

Please sign in to comment.