2022-10-01 16:58:22 +00:00
// Gupax - GUI Uniting P2Pool And XMRig
//
// Copyright (c) 2022 hinto-janaiyo
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
2022-12-11 20:49:01 +00:00
use crate ::{
PubP2poolApi ,
PubXmrigApi ,
ImgP2pool ,
ImgXmrig ,
constants ::* ,
Sys ,
} ;
use std ::sync ::{ Arc , Mutex } ;
2022-12-12 19:34:17 +00:00
use log ::* ;
2022-12-11 20:49:01 +00:00
use egui ::{
Label , RichText , TextStyle
} ;
2022-10-01 16:58:22 +00:00
// Main data structure for the Status tab
#[ derive(Clone, Debug, Eq, PartialEq) ]
2022-12-11 20:49:01 +00:00
pub struct Status { }
2022-10-01 16:58:22 +00:00
impl Status {
2022-12-14 03:41:05 +00:00
pub fn show ( sys : & Arc < Mutex < Sys > > , p2pool_api : & Arc < Mutex < PubP2poolApi > > , xmrig_api : & Arc < Mutex < PubXmrigApi > > , _p2pool_img : & Arc < Mutex < ImgP2pool > > , _xmrig_img : & Arc < Mutex < ImgXmrig > > , p2pool_alive : bool , xmrig_alive : bool , width : f32 , height : f32 , _ctx : & egui ::Context , ui : & mut egui ::Ui ) {
2022-12-11 20:49:01 +00:00
let width = ( width / 3.0 ) - ( SPACE * 1.666 ) ;
let min_height = height / 1.14 ;
2022-12-12 01:43:34 +00:00
let height = height / 25.0 ;
2022-12-11 20:49:01 +00:00
ui . horizontal ( | ui | {
// [Gupax]
ui . group ( | ui | { ui . vertical ( | ui | {
2022-12-12 20:34:49 +00:00
debug! ( " Status Tab | Rendering [Gupax] " ) ;
2022-12-11 20:49:01 +00:00
ui . set_min_height ( min_height ) ;
2022-12-12 01:43:34 +00:00
ui . add_sized ( [ width , height * 2.0 ] , Label ::new ( RichText ::new ( " [Gupax] " ) . color ( LIGHT_GRAY ) . text_style ( TextStyle ::Name ( " MonospaceLarge " . into ( ) ) ) ) ) . on_hover_text ( " Gupax is online " ) ;
let sys = sys . lock ( ) . unwrap ( ) ;
2022-12-11 20:49:01 +00:00
ui . add_sized ( [ width , height ] , Label ::new ( RichText ::new ( " Uptime " ) . underline ( ) . color ( BONE ) ) ) . on_hover_text ( STATUS_GUPAX_UPTIME ) ;
2022-12-14 03:41:05 +00:00
ui . add_sized ( [ width , height ] , Label ::new ( sys . gupax_uptime . to_string ( ) ) ) ;
2022-12-11 20:49:01 +00:00
ui . add_sized ( [ width , height ] , Label ::new ( RichText ::new ( " Gupax CPU " ) . underline ( ) . color ( BONE ) ) ) . on_hover_text ( STATUS_GUPAX_CPU_USAGE ) ;
2022-12-14 03:41:05 +00:00
ui . add_sized ( [ width , height ] , Label ::new ( sys . gupax_cpu_usage . to_string ( ) ) ) ;
2022-12-11 20:49:01 +00:00
ui . add_sized ( [ width , height ] , Label ::new ( RichText ::new ( " Gupax Memory " ) . underline ( ) . color ( BONE ) ) ) . on_hover_text ( STATUS_GUPAX_MEMORY_USAGE ) ;
2022-12-14 03:41:05 +00:00
ui . add_sized ( [ width , height ] , Label ::new ( sys . gupax_memory_used_mb . to_string ( ) ) ) ;
2022-12-11 20:49:01 +00:00
ui . add_sized ( [ width , height ] , Label ::new ( RichText ::new ( " System CPU " ) . underline ( ) . color ( BONE ) ) ) . on_hover_text ( STATUS_GUPAX_SYSTEM_CPU_USAGE ) ;
2022-12-14 03:41:05 +00:00
ui . add_sized ( [ width , height ] , Label ::new ( sys . system_cpu_usage . to_string ( ) ) ) ;
2022-12-11 20:49:01 +00:00
ui . add_sized ( [ width , height ] , Label ::new ( RichText ::new ( " System Memory " ) . underline ( ) . color ( BONE ) ) ) . on_hover_text ( STATUS_GUPAX_SYSTEM_MEMORY ) ;
2022-12-14 03:41:05 +00:00
ui . add_sized ( [ width , height ] , Label ::new ( sys . system_memory . to_string ( ) ) ) ;
2022-12-11 20:49:01 +00:00
ui . add_sized ( [ width , height ] , Label ::new ( RichText ::new ( " System CPU Model " ) . underline ( ) . color ( BONE ) ) ) . on_hover_text ( STATUS_GUPAX_SYSTEM_CPU_MODEL ) ;
2022-12-14 03:41:05 +00:00
ui . add_sized ( [ width , height ] , Label ::new ( sys . system_cpu_model . to_string ( ) ) ) ;
2022-12-12 01:43:34 +00:00
drop ( sys ) ;
2022-12-11 20:49:01 +00:00
} ) } ) ;
// [P2Pool]
ui . group ( | ui | { ui . vertical ( | ui | {
2022-12-12 19:34:17 +00:00
debug! ( " Status Tab | Rendering [P2Pool] " ) ;
2022-12-13 14:39:09 +00:00
ui . set_enabled ( p2pool_alive ) ;
2022-12-11 20:49:01 +00:00
ui . set_min_height ( min_height ) ;
2022-12-12 01:43:34 +00:00
ui . add_sized ( [ width , height * 2.0 ] , Label ::new ( RichText ::new ( " [P2Pool] " ) . color ( LIGHT_GRAY ) . text_style ( TextStyle ::Name ( " MonospaceLarge " . into ( ) ) ) ) ) . on_hover_text ( " P2Pool is online " ) . on_disabled_hover_text ( " P2Pool is offline " ) ;
let api = p2pool_api . lock ( ) . unwrap ( ) ;
ui . add_sized ( [ width , height ] , Label ::new ( RichText ::new ( " Uptime " ) . underline ( ) . color ( BONE ) ) ) . on_hover_text ( STATUS_P2POOL_UPTIME ) ;
ui . add_sized ( [ width , height ] , Label ::new ( format! ( " {} " , api . uptime ) ) ) ;
ui . add_sized ( [ width , height ] , 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 ( RichText ::new ( " Payouts " ) . underline ( ) . color ( BONE ) ) ) . on_hover_text ( STATUS_P2POOL_PAYOUTS ) ;
ui . add_sized ( [ width , height ] , Label ::new ( format! ( " Total: {} " , api . payouts ) ) ) ;
2022-12-23 02:55:28 +00:00
ui . add_sized ( [ width , height ] , Label ::new ( format! ( " [ {:.7} /hour] \n [ {:.7} /day] \n [ {:.7} /month] " , api . payouts_hour , api . payouts_day , api . payouts_month ) ) ) ;
2022-12-12 01:43:34 +00:00
ui . add_sized ( [ width , height ] , Label ::new ( RichText ::new ( " XMR Mined " ) . underline ( ) . color ( BONE ) ) ) . on_hover_text ( STATUS_P2POOL_XMR ) ;
2022-12-19 01:17:32 +00:00
ui . add_sized ( [ width , height ] , Label ::new ( format! ( " Total: {:.13} XMR " , api . xmr ) ) ) ;
2022-12-23 02:55:28 +00:00
ui . add_sized ( [ width , height ] , Label ::new ( format! ( " [ {:.7} /hour] \n [ {:.7} /day] \n [ {:.7} /month] " , api . xmr_hour , api . xmr_day , api . xmr_month ) ) ) ;
2022-12-12 03:01:37 +00:00
ui . add_sized ( [ width , height ] , Label ::new ( RichText ::new ( " Hashrate [15m/1h/24h] " ) . underline ( ) . color ( BONE ) ) ) . on_hover_text ( STATUS_P2POOL_HASHRATE ) ;
2022-12-12 01:43:34 +00:00
ui . add_sized ( [ width , height ] , Label ::new ( format! ( " [ {} H/s] [ {} H/s] [ {} H/s] " , api . hashrate_15m , api . hashrate_1h , api . hashrate_24h ) ) ) ;
ui . add_sized ( [ width , height ] , Label ::new ( RichText ::new ( " Miners Connected " ) . underline ( ) . color ( BONE ) ) ) . on_hover_text ( STATUS_P2POOL_CONNECTIONS ) ;
ui . add_sized ( [ width , height ] , Label ::new ( format! ( " {} " , api . connections ) ) ) ;
ui . add_sized ( [ width , height ] , Label ::new ( RichText ::new ( " Effort " ) . underline ( ) . color ( BONE ) ) ) . on_hover_text ( STATUS_P2POOL_EFFORT ) ;
ui . add_sized ( [ width , height ] , Label ::new ( format! ( " [Average: {} ] [Current: {} ] " , api . average_effort , api . current_effort ) ) ) ;
2022-12-12 03:01:37 +00:00
drop ( api ) ;
2022-12-11 20:49:01 +00:00
} ) } ) ;
// [XMRig]
ui . group ( | ui | { ui . vertical ( | ui | {
2022-12-12 19:34:17 +00:00
debug! ( " Status Tab | Rendering [XMRig] " ) ;
2022-12-13 14:39:09 +00:00
ui . set_enabled ( xmrig_alive ) ;
2022-12-11 20:49:01 +00:00
ui . set_min_height ( min_height ) ;
2022-12-12 01:43:34 +00:00
ui . add_sized ( [ width , height * 2.0 ] , Label ::new ( RichText ::new ( " [XMRig] " ) . color ( LIGHT_GRAY ) . text_style ( TextStyle ::Name ( " MonospaceLarge " . into ( ) ) ) ) ) . on_hover_text ( " XMRig is online " ) . on_disabled_hover_text ( " XMRig is offline " ) ;
2022-12-12 03:01:37 +00:00
let api = xmrig_api . lock ( ) . unwrap ( ) ;
ui . add_sized ( [ width , height ] , 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 ( RichText ::new ( " CPU Load Averages " ) . underline ( ) . color ( BONE ) ) ) . on_hover_text ( STATUS_XMRIG_CPU ) ;
ui . add_sized ( [ width , height ] , Label ::new ( format! ( " {} " , api . resources ) ) ) ;
ui . add_sized ( [ width , height ] , Label ::new ( RichText ::new ( " Hashrate Averages " ) . underline ( ) . color ( BONE ) ) ) . on_hover_text ( STATUS_XMRIG_HASHRATE ) ;
ui . add_sized ( [ width , height ] , Label ::new ( format! ( " {} " , api . hashrate ) ) ) ;
ui . add_sized ( [ width , height ] , Label ::new ( RichText ::new ( " Difficulty " ) . underline ( ) . color ( BONE ) ) ) . on_hover_text ( STATUS_XMRIG_DIFFICULTY ) ;
ui . add_sized ( [ width , height ] , Label ::new ( format! ( " {} " , api . diff ) ) ) ;
ui . add_sized ( [ width , height ] , Label ::new ( RichText ::new ( " Shares " ) . underline ( ) . color ( BONE ) ) ) . on_hover_text ( STATUS_XMRIG_SHARES ) ;
2022-12-19 01:17:32 +00:00
ui . add_sized ( [ width , height ] , Label ::new ( format! ( " [Accepted: {} ] \n [Rejected: {} ] " , api . accepted , api . rejected ) ) ) ;
2022-12-12 03:01:37 +00:00
ui . add_sized ( [ width , height ] , Label ::new ( RichText ::new ( " Pool " ) . underline ( ) . color ( BONE ) ) ) . on_hover_text ( STATUS_XMRIG_POOL ) ;
2022-12-14 03:41:05 +00:00
ui . add_sized ( [ width , height ] , Label ::new ( api . pool . to_string ( ) ) ) ;
2022-12-12 03:01:37 +00:00
drop ( api ) ;
2022-12-11 20:49:01 +00:00
} ) } ) ;
} ) ;
}
2022-10-01 16:58:22 +00:00
}