feat: add slider for hashrate

This commit is contained in:
mostafaei2002 2024-06-09 16:37:31 +03:30
parent 574a67dd4e
commit 709e778479
6 changed files with 25 additions and 58 deletions

View file

@ -528,15 +528,7 @@ impl App {
// Set saved Hero mode to runtime. // Set saved Hero mode to runtime.
debug!("Setting runtime_mode & runtime_manual_amount"); debug!("Setting runtime_mode & runtime_manual_amount");
app.xvb_api.lock().unwrap().stats_priv.runtime_mode = app.state.xvb.mode.clone().into(); app.xvb_api.lock().unwrap().stats_priv.runtime_mode = app.state.xvb.mode.clone().into();
app.xvb_api.lock().unwrap().stats_priv.runtime_manual_amount = match app.state.xvb.amount.parse() { app.xvb_api.lock().unwrap().stats_priv.runtime_manual_amount = app.state.xvb.amount;
Ok(n) => n,
Err(e) => {
error!("App Init | Failed to parse manual amount: {}", e);
app.xvb_api.lock().unwrap().stats_priv.runtime_mode = RuntimeMode::Auto;
0
}
};
// Check if [P2pool.node] exists // Check if [P2pool.node] exists
info!("App Init | Checking if saved remote node still exists..."); info!("App Init | Checking if saved remote node still exists...");
app.state.p2pool.node = RemoteNode::check_exists(&app.state.p2pool.node); app.state.p2pool.node = RemoteNode::check_exists(&app.state.p2pool.node);

View file

@ -162,7 +162,7 @@ path_xmr: {:#?}\n
} }
Tab::Xvb => { Tab::Xvb => {
debug!("App | Entering [XvB] Tab"); debug!("App | Entering [XvB] Tab");
crate::disk::state::Xvb::show(&mut self.state.xvb, self.size, &self.state.p2pool.address, ctx, ui, &self.xvb_api, lock!(self.xvb).state == ProcessState::Alive); crate::disk::state::Xvb::show(&mut self.state.xvb, self.size, &self.state.p2pool.address, ctx, ui, &self.xvb_api, &self.xmrig_api, lock!(self.xvb).state == ProcessState::Alive);
} }
} }
}); });

View file

@ -8,6 +8,7 @@ use readable::num::Float;
use readable::up::Uptime; use readable::up::Uptime;
use crate::disk::state::XvbMode; use crate::disk::state::XvbMode;
use crate::helper::xmrig::PubXmrigApi;
use crate::helper::xvb::priv_stats::RuntimeMode; use crate::helper::xvb::priv_stats::RuntimeMode;
use crate::helper::xvb::PubXvbApi; use crate::helper::xvb::PubXvbApi;
use crate::regex::num_lines; use crate::regex::num_lines;
@ -33,6 +34,7 @@ impl crate::disk::state::Xvb {
_ctx: &egui::Context, _ctx: &egui::Context,
ui: &mut egui::Ui, ui: &mut egui::Ui,
api: &Arc<Mutex<PubXvbApi>>, api: &Arc<Mutex<PubXvbApi>>,
gui_api_xmrig: &Arc<Mutex<PubXmrigApi>>,
private_stats: bool, private_stats: bool,
) { ) {
let website_height = size.y / 10.0; let website_height = size.y / 10.0;
@ -149,26 +151,21 @@ impl crate::disk::state::Xvb {
ui.selectable_value(&mut self.mode, XvbMode::ManuallyKeep, "Manually Keep"); ui.selectable_value(&mut self.mode, XvbMode::ManuallyKeep, "Manually Keep");
}); });
if self.mode == XvbMode::ManuallyDonate || self.mode == XvbMode::ManuallyKeep { if self.mode == XvbMode::ManuallyDonate || self.mode == XvbMode::ManuallyKeep {
let (text, color) = if self.amount.is_empty() {
(
format!(""),
LIGHT_GRAY,
)
} else if self.amount.parse::<u32>().is_ok() {
(format!(""), GREEN)
} else {
(
format!("Invalid hashrate ❌"),
RED,
)
};
ui.add_space(space_h); ui.add_space(space_h);
ui.colored_label(color, text); let hashrate_xmrig = {
if lock!(gui_api_xmrig).hashrate_raw_15m > 0.0 {
lock!(gui_api_xmrig).hashrate_raw_15m
} else if lock!(gui_api_xmrig).hashrate_raw_1m > 0.0 {
lock!(gui_api_xmrig).hashrate_raw_1m
} else {
lock!(gui_api_xmrig).hashrate_raw
}
};
ui.add( ui.add(
TextEdit::singleline(&mut self.amount) egui::Slider::new(&mut self.amount, 0.0..=(hashrate_xmrig as f64)).text("H/s")
.vertical_align(egui::Align::Center)
).on_hover_text(XVB_MANUAL_HASHRATE_HELP); ).on_hover_text(XVB_MANUAL_HASHRATE_HELP);
} }
@ -178,15 +175,7 @@ impl crate::disk::state::Xvb {
// Set runtime_mode & runtime_manual_amount // Set runtime_mode & runtime_manual_amount
lock!(api).stats_priv.runtime_mode = self.mode.clone().into(); lock!(api).stats_priv.runtime_mode = self.mode.clone().into();
lock!(api).stats_priv.runtime_manual_amount = match self.amount.parse() { lock!(api).stats_priv.runtime_manual_amount = self.amount;
Ok(n) => n,
Err(e) => {
error!("Error parsing int {}", e);
lock!(api).stats_priv.runtime_mode = RuntimeMode::Auto;
0
}
};
} }

View file

@ -251,13 +251,13 @@ pub enum XvbMode {
Hero, Hero,
} }
#[derive(Clone, Eq, PartialEq, Debug, Deserialize, Serialize, Default)] #[derive(Clone, PartialEq, Debug, Deserialize, Serialize, Default)]
pub struct Xvb { pub struct Xvb {
pub simple: bool, pub simple: bool,
pub token: String, pub token: String,
pub simple_hero_mode: bool, pub simple_hero_mode: bool,
pub mode: XvbMode, pub mode: XvbMode,
pub amount: String pub amount: f64
} }
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]

View file

@ -83,33 +83,17 @@ pub(crate) fn calcul_donated_time(
default_spared_time default_spared_time
}, },
RuntimeMode::ManuallyDonate => { RuntimeMode::ManuallyDonate => {
let mut donate_hr = lock!(gui_api_xvb).stats_priv.runtime_manual_amount; let donate_hr = lock!(gui_api_xvb).stats_priv.runtime_manual_amount;
info!("RuntimeMode::ManuallyDonate - lhr:{lhr} donate_hr:{donate_hr}"); info!("RuntimeMode::ManuallyDonate - lhr:{lhr} donate_hr:{donate_hr}");
if donate_hr > (lhr as u64) {
donate_hr = lhr as u64;
}
if lhr < 1.0 {
default_spared_time
} else {
XVB_TIME_ALGO * (donate_hr as u32) / (lhr as u32) XVB_TIME_ALGO * (donate_hr as u32) / (lhr as u32)
}
}, },
RuntimeMode::ManuallyKeep => { RuntimeMode::ManuallyKeep => {
let mut keep_hr = lock!(gui_api_xvb).stats_priv.runtime_manual_amount; let keep_hr = lock!(gui_api_xvb).stats_priv.runtime_manual_amount;
info!("RuntimeMode::ManuallyDonate - lhr:{lhr} keep_hr:{keep_hr}"); info!("RuntimeMode::ManuallyDonate - lhr:{lhr} keep_hr:{keep_hr}");
if keep_hr > (lhr as u64) {
keep_hr = lhr as u64;
}
if lhr < 1.0 {
default_spared_time
} else {
XVB_TIME_ALGO - (XVB_TIME_ALGO * (keep_hr as u32) / (lhr as u32)) XVB_TIME_ALGO - (XVB_TIME_ALGO * (keep_hr as u32) / (lhr as u32))
} }
}
}; };
info!("Final spared_time is {spared_time}"); info!("Final spared_time is {spared_time}");
@ -299,6 +283,7 @@ pub(crate) async fn algorithm(
gui_api_xvb, gui_api_xvb,
"At least one share is in current PPLNS window.", "At least one share is in current PPLNS window.",
); );
let hashrate_xmrig = { let hashrate_xmrig = {
if lock!(gui_api_xmrig).hashrate_raw_15m > 0.0 { if lock!(gui_api_xmrig).hashrate_raw_15m > 0.0 {
lock!(gui_api_xmrig).hashrate_raw_15m lock!(gui_api_xmrig).hashrate_raw_15m
@ -308,6 +293,7 @@ pub(crate) async fn algorithm(
lock!(gui_api_xmrig).hashrate_raw lock!(gui_api_xmrig).hashrate_raw
} }
}; };
*lock!(time_donated) = *lock!(time_donated) =
calcul_donated_time(hashrate_xmrig, gui_api_p2pool, gui_api_xvb, state_p2pool); calcul_donated_time(hashrate_xmrig, gui_api_p2pool, gui_api_xvb, state_p2pool);
let time_donated = *lock!(time_donated); let time_donated = *lock!(time_donated);

View file

@ -48,7 +48,7 @@ pub struct XvbPrivStats {
// so the hero mode can change between two decision of algorithm without restarting XvB. // so the hero mode can change between two decision of algorithm without restarting XvB.
pub runtime_mode: RuntimeMode, pub runtime_mode: RuntimeMode,
#[serde(skip)] #[serde(skip)]
pub runtime_manual_amount: u64 pub runtime_manual_amount: f64
} }
impl XvbPrivStats { impl XvbPrivStats {