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.
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_manual_amount = match app.state.xvb.amount.parse() {
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
}
};
app.xvb_api.lock().unwrap().stats_priv.runtime_manual_amount = app.state.xvb.amount;
// Check if [P2pool.node] exists
info!("App Init | Checking if saved remote node still exists...");
app.state.p2pool.node = RemoteNode::check_exists(&app.state.p2pool.node);

View file

@ -162,7 +162,7 @@ path_xmr: {:#?}\n
}
Tab::Xvb => {
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 crate::disk::state::XvbMode;
use crate::helper::xmrig::PubXmrigApi;
use crate::helper::xvb::priv_stats::RuntimeMode;
use crate::helper::xvb::PubXvbApi;
use crate::regex::num_lines;
@ -33,6 +34,7 @@ impl crate::disk::state::Xvb {
_ctx: &egui::Context,
ui: &mut egui::Ui,
api: &Arc<Mutex<PubXvbApi>>,
gui_api_xmrig: &Arc<Mutex<PubXmrigApi>>,
private_stats: bool,
) {
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");
});
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.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(
TextEdit::singleline(&mut self.amount)
.vertical_align(egui::Align::Center)
egui::Slider::new(&mut self.amount, 0.0..=(hashrate_xmrig as f64)).text("H/s")
).on_hover_text(XVB_MANUAL_HASHRATE_HELP);
}
@ -178,15 +175,7 @@ impl crate::disk::state::Xvb {
// Set runtime_mode & runtime_manual_amount
lock!(api).stats_priv.runtime_mode = self.mode.clone().into();
lock!(api).stats_priv.runtime_manual_amount = match self.amount.parse() {
Ok(n) => n,
Err(e) => {
error!("Error parsing int {}", e);
lock!(api).stats_priv.runtime_mode = RuntimeMode::Auto;
0
}
};
lock!(api).stats_priv.runtime_manual_amount = self.amount;
}

View file

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

View file

@ -83,32 +83,16 @@ pub(crate) fn calcul_donated_time(
default_spared_time
},
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}");
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 => {
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}");
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))
}
};
@ -299,6 +283,7 @@ pub(crate) async fn algorithm(
gui_api_xvb,
"At least one share is in current PPLNS window.",
);
let hashrate_xmrig = {
if lock!(gui_api_xmrig).hashrate_raw_15m > 0.0 {
lock!(gui_api_xmrig).hashrate_raw_15m
@ -308,6 +293,7 @@ pub(crate) async fn algorithm(
lock!(gui_api_xmrig).hashrate_raw
}
};
*lock!(time_donated) =
calcul_donated_time(hashrate_xmrig, gui_api_p2pool, gui_api_xvb, state_p2pool);
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.
pub runtime_mode: RuntimeMode,
#[serde(skip)]
pub runtime_manual_amount: u64
pub runtime_manual_amount: f64
}
impl XvbPrivStats {