fix: fix simple & advanced tab UI & modify tests

This commit is contained in:
mostafaei2002 2024-06-07 14:18:03 +03:30
parent dbbbcc3d15
commit 8a8904083e
4 changed files with 79 additions and 68 deletions

View file

@ -510,6 +510,32 @@ impl crate::app::App {
}
});
}
fn xvb_submenu(&mut self, ui: &mut Ui, size: Vec2) {
ui.group(|ui| {
let width = size.x / 1.5;
let size = vec2(width, size.y);
if ui
.add_sized(
size,
SelectableLabel::new(!self.state.xvb.simple, "Advanced"),
)
.clicked()
{
self.state.xvb.simple = false;
}
ui.separator();
if ui
.add_sized(
size,
SelectableLabel::new(self.state.xvb.simple, "Simple"),
)
.clicked()
{
self.state.xvb.simple = true;
}
});
}
fn xvb_run_actions(
&mut self,
ui: &mut Ui,
@ -588,31 +614,6 @@ impl crate::app::App {
});
}
fn xvb_submenu(&mut self, ui: &mut Ui, size: Vec2) {
ui.group(|ui| {
let width = size.x / 1.5;
let size = vec2(width, size.y);
if ui
.add_sized(
size,
SelectableLabel::new(!self.state.xvb.simple, "Advanced"),
)
.clicked()
{
self.state.xvb.simple = false;
}
ui.separator();
if ui
.add_sized(
size,
SelectableLabel::new(self.state.xvb.simple, "Simple"),
)
.clicked()
{
self.state.xvb.simple = true;
}
});
}
}
fn status_p2pool(state: ProcessState, ui: &mut Ui, size: Vec2) {

View file

@ -3,10 +3,12 @@ use std::sync::{Arc, Mutex};
use egui::TextStyle::{self, Name};
use egui::{vec2, Image, RichText, TextEdit, Ui, Vec2};
use log::debug;
use log::error;
use readable::num::Float;
use readable::up::Uptime;
use crate::disk::state::XvbMode;
use crate::helper::xvb::priv_stats::RuntimeMode;
use crate::helper::xvb::PubXvbApi;
use crate::regex::num_lines;
use crate::utils::constants::{
@ -37,19 +39,19 @@ impl crate::disk::state::Xvb {
let width = size.x;
let height = size.y;
let space_h = height / 48.0;
// if self.simple {
// // logo and website link
// ui.vertical_centered(|ui| {
// ui.add_sized(
// [width, website_height],
// Image::from_bytes("bytes:/xvb.png", BYTES_XVB),
// );
// ui.style_mut().override_text_style = Some(TextStyle::Heading);
// ui.add_space(space_h);
// ui.hyperlink_to("XMRvsBeast", XVB_URL);
// ui.add_space(space_h);
// });
// }
// logo and website link
ui.vertical_centered(|ui| {
ui.add_sized(
[width, website_height],
Image::from_bytes("bytes:/xvb.png", BYTES_XVB),
);
ui.style_mut().override_text_style = Some(TextStyle::Heading);
ui.add_space(space_h);
ui.hyperlink_to("XMRvsBeast", XVB_URL);
ui.add_space(space_h);
});
// console output for log
debug!("XvB Tab | Rendering [Console]");
ui.group(|ui| {
@ -121,18 +123,14 @@ impl crate::disk::state::Xvb {
// --------------------------- XVB Simple -------------------------------------------
if self.simple {
ui.group(|ui| {
ui.vertical_centered(|ui| {
ui.horizontal(|ui| {
egui::ComboBox::from_label("")
.selected_text(format!("{:?}", self.mode))
.show_ui(ui, |ui| {
ui.selectable_value(&mut self.mode, XvbMode::Auto, "Automatic");
ui.selectable_value(&mut self.mode, XvbMode::Hero, "Hero Mode");
});
});
});
});
if ui.checkbox(&mut self.simple_hero_mode, "Hero Mode").on_hover_text(XVB_HERO_SELECT).clicked() {
// also change hero mode of runtime.
lock!(api).stats_priv.runtime_mode = RuntimeMode::Hero;
} else {
lock!(api).stats_priv.runtime_mode = RuntimeMode::Auto;
}
}
// --------------------------- XVB Advanced -----------------------------------------
@ -178,6 +176,17 @@ 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
}
};
}

View file

@ -255,6 +255,7 @@ pub enum XvbMode {
pub struct Xvb {
pub simple: bool,
pub token: String,
pub simple_hero_mode: bool,
pub mode: XvbMode,
pub amount: String
}

View file

@ -3,7 +3,7 @@ mod test {
use crate::helper::{
p2pool::{PrivP2poolLocalApi, PrivP2poolNetworkApi},
xvb::{algorithm::calcul_donated_time, rounds::round_type},
xvb::{algorithm::calcul_donated_time, priv_stats::RuntimeMode, rounds::round_type},
Helper, Process, ProcessName, ProcessState,
};
@ -539,7 +539,7 @@ Uptime = 0h 2m 4s
// 15mn average HR of xmrig is 5kH/s
lock!(gui_api_xvb).stats_priv.donor_1hr_avg = 0.0;
lock!(gui_api_xmrig).hashrate_raw_15m = 5000.0;
lock!(gui_api_xvb).stats_priv.runtime_hero_mode = false;
lock!(gui_api_xvb).stats_priv.runtime_mode = RuntimeMode::Auto;
let given_time = calcul_donated_time(
lock!(gui_api_xmrig).hashrate_raw_15m,
&gui_api_p2pool,
@ -559,7 +559,7 @@ Uptime = 0h 2m 4s
/ 1000.0;
assert_eq!(round_type(share, &gui_api_xvb), Some(XvbRound::Vip));
// verify that hero mode will give x seconds
lock!(gui_api_xvb).stats_priv.runtime_hero_mode = true;
lock!(gui_api_xvb).stats_priv.runtime_mode = RuntimeMode::Hero;
let given_time = calcul_donated_time(
lock!(gui_api_xmrig).hashrate_raw_15m,
&gui_api_p2pool,
@ -578,7 +578,7 @@ Uptime = 0h 2m 4s
// verify that if one share and not enough for donor vip round (should be in donor round), right amount of time will be given to xvb for default and hero mode
lock!(gui_api_xvb).stats_priv.donor_1hr_avg = 0.0;
lock!(gui_api_xmrig).hashrate_raw_15m = 8000.0;
lock!(gui_api_xvb).stats_priv.runtime_hero_mode = false;
lock!(gui_api_xvb).stats_priv.runtime_mode = RuntimeMode::Auto;
let given_time = calcul_donated_time(
lock!(gui_api_xmrig).hashrate_raw_15m,
&gui_api_p2pool,
@ -598,7 +598,7 @@ Uptime = 0h 2m 4s
/ 1000.0;
assert_eq!(round_type(share, &gui_api_xvb), Some(XvbRound::Donor));
// verify that hero mode will give x seconds
lock!(gui_api_xvb).stats_priv.runtime_hero_mode = true;
lock!(gui_api_xvb).stats_priv.runtime_mode = RuntimeMode::Hero;
let given_time = calcul_donated_time(
lock!(gui_api_xmrig).hashrate_raw_15m,
&gui_api_p2pool,
@ -617,7 +617,7 @@ Uptime = 0h 2m 4s
// verify that if one share and not enough for donor whale round(should be in donor vip), right amount of time will be given to xvb for default and hero mode
lock!(gui_api_xvb).stats_priv.donor_1hr_avg = 0.0;
lock!(gui_api_xmrig).hashrate_raw_15m = 19000.0;
lock!(gui_api_xvb).stats_priv.runtime_hero_mode = false;
lock!(gui_api_xvb).stats_priv.runtime_mode = RuntimeMode::Auto;
let given_time = calcul_donated_time(
lock!(gui_api_xmrig).hashrate_raw_15m,
&gui_api_p2pool,
@ -637,7 +637,7 @@ Uptime = 0h 2m 4s
/ 1000.0;
assert_eq!(round_type(share, &gui_api_xvb), Some(XvbRound::DonorVip));
// verify that hero mode will give x seconds
lock!(gui_api_xvb).stats_priv.runtime_hero_mode = true;
lock!(gui_api_xvb).stats_priv.runtime_mode = RuntimeMode::Hero;
let given_time = calcul_donated_time(
lock!(gui_api_xmrig).hashrate_raw_15m,
&gui_api_p2pool,
@ -656,7 +656,7 @@ Uptime = 0h 2m 4s
// verify that if one share and not enough for donor mega round, right amount of time will be given to xvb for default and hero mode
lock!(gui_api_xvb).stats_priv.donor_1hr_avg = 0.0;
lock!(gui_api_xmrig).hashrate_raw_15m = 105000.0;
lock!(gui_api_xvb).stats_priv.runtime_hero_mode = false;
lock!(gui_api_xvb).stats_priv.runtime_mode = RuntimeMode::Auto;
let given_time = calcul_donated_time(
lock!(gui_api_xmrig).hashrate_raw_15m,
&gui_api_p2pool,
@ -676,7 +676,7 @@ Uptime = 0h 2m 4s
/ 1000.0;
assert_eq!(round_type(share, &gui_api_xvb), Some(XvbRound::DonorWhale));
// verify that hero mode will give x seconds
lock!(gui_api_xvb).stats_priv.runtime_hero_mode = true;
lock!(gui_api_xvb).stats_priv.runtime_mode = RuntimeMode::Hero;
let given_time = calcul_donated_time(
lock!(gui_api_xmrig).hashrate_raw_15m,
&gui_api_p2pool,
@ -695,7 +695,7 @@ Uptime = 0h 2m 4s
// verify that if one share and enough for donor mega round, right amount of time will be given to xvb for default and hero mode
lock!(gui_api_xvb).stats_priv.donor_1hr_avg = 0.0;
lock!(gui_api_xmrig).hashrate_raw_15m = 1205000.0;
lock!(gui_api_xvb).stats_priv.runtime_hero_mode = false;
lock!(gui_api_xvb).stats_priv.runtime_mode = RuntimeMode::Auto;
let given_time = calcul_donated_time(
lock!(gui_api_xmrig).hashrate_raw_15m,
&gui_api_p2pool,
@ -715,7 +715,7 @@ Uptime = 0h 2m 4s
/ 1000.0;
assert_eq!(round_type(share, &gui_api_xvb), Some(XvbRound::DonorMega));
// verify that hero mode will give x seconds
lock!(gui_api_xvb).stats_priv.runtime_hero_mode = true;
lock!(gui_api_xvb).stats_priv.runtime_mode = RuntimeMode::Hero;
let given_time = calcul_donated_time(
lock!(gui_api_xmrig).hashrate_raw_15m,
&gui_api_p2pool,
@ -735,7 +735,7 @@ Uptime = 0h 2m 4s
lock!(gui_api_xvb).output.clear();
lock!(gui_api_xmrig).hashrate_raw_15m = 12500.0;
lock!(gui_api_xvb).stats_priv.donor_1hr_avg = 5.0;
lock!(gui_api_xvb).stats_priv.runtime_hero_mode = false;
lock!(gui_api_xvb).stats_priv.runtime_mode = RuntimeMode::Auto;
let given_time = calcul_donated_time(
lock!(gui_api_xmrig).hashrate_raw_15m,
&gui_api_p2pool,
@ -758,7 +758,7 @@ Uptime = 0h 2m 4s
assert_eq!(round_type(share, &gui_api_xvb), Some(XvbRound::DonorVip));
// verify that hero mode will give x seconds
lock!(gui_api_xvb).stats_priv.donor_1hr_avg = 5.0;
lock!(gui_api_xvb).stats_priv.runtime_hero_mode = true;
lock!(gui_api_xvb).stats_priv.runtime_mode = RuntimeMode::Hero;
let given_time = calcul_donated_time(
lock!(gui_api_xmrig).hashrate_raw_15m,
&gui_api_p2pool,