Fix GUI layout/crash bugs; add operator features, tests, and dev loop
Round 1 (bug fixes + test harness): - Fix table rendering in the top-left corner: the dvlc was never added to the sizer; add it (proportion 1) and re-run layout; drop the space-eating stretch. - Fix abort on dialog buttons: the dialog root sizers passed ALIGN_CENTRE_VERTICAL to a vertical sizer, tripping a wx consistency assert whose handler pumps a nested event loop, re-entering dispatch while it held the App RefCell borrow. Remove the invalid flags; split dispatch into two phases with try_borrow_mut. - Fix header-click sort mapping when columns are hidden (use display_columns); drag-reorder splices back into the full order without dropping hidden columns. - Add offline fixtures + ALKANE_FAKE_SCAN and ALKANE_SELFTEST modes; scripts ui-selftest.sh and ui-screenshot.sh; AGENTS.md documents the dev loop. Round 2 (operator requests): - Redesigned color-coded KPI cards; light/dark mode follows the system theme. - SI-formatted hashrate/power on the KPIs and columns (685 TH/s, 21.3 kW). - Scan ranges accept CIDR, single IP, and A.B.C.D-E.F.G.H / A.B.C.D-N ranges; oversized ranges (> 1,000,000 addresses) are rejected. - Scan progress bar over the table + status-bar text; out-of-range miners are dropped when a scan starts. - Columns panel exposes every scannable MinerData metric (All / None / Defaults). - Excel-style filter panel: per-category value checklists, per-column All/None, Apply / Reset / Cancel, blank handling. - Sort direction marker in the header (updated in place); double-click a row opens the miner in the default browser. wx-rs: extend the widget bridge (gauge, in-place column title, sort indicator, browser launch, system appearance/colours, widget colours, item-activated); patches 0002/0003 regenerated and round-trip validated. Verified: 22 unit tests + a 13-check headless UI self-test, plus a live scan against the bench fleet. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Y8h447BPyJR4fioYZvQ9bh
This commit is contained in:
+509
-91
@@ -2,19 +2,106 @@
|
||||
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
/// A miner counts as "slow" when it is mining but running below this fraction
|
||||
/// of its model's expected hashrate (UI-SPEC "Slow" band). A missing expected
|
||||
/// hashrate (0.0) means the band is unknown, so the miner is never "slow".
|
||||
pub const SLOW_THRESHOLD: f64 = 0.8;
|
||||
|
||||
/// The single source of truth for the "slow" classification, shared by the
|
||||
/// live scan (`scan::to_row`) and the fixtures/tests, so the expected-vs-actual
|
||||
/// comparison exercises the same rule the app uses.
|
||||
pub fn is_slow(is_mining: bool, hashrate_ths: f64, expected_ths: f64) -> bool {
|
||||
is_mining && expected_ths > 0.0 && hashrate_ths < SLOW_THRESHOLD * expected_ths
|
||||
}
|
||||
|
||||
/// Format a value in its base unit with an SI prefix chosen so the number stays
|
||||
/// compact: the prefix puts the mantissa in [1, 1000), then it is shown with 1
|
||||
/// decimal below 100 and no decimal from 100 up (so 21300 W -> "21.3 kW",
|
||||
/// 685e12 H/s -> "685 TH/s", 6.8e12 -> "6.8 TH/s"). Zero renders as "0 <unit>".
|
||||
pub fn format_si(value_base: f64, unit: &str) -> String {
|
||||
if !value_base.is_finite() || value_base <= 0.0 {
|
||||
return format!("0 {unit}");
|
||||
}
|
||||
const PREFIXES: [&str; 8] = ["", "k", "M", "G", "T", "P", "E", "Z"];
|
||||
let mut v = value_base;
|
||||
let mut i = 0usize;
|
||||
while v >= 1000.0 && i < PREFIXES.len() - 1 {
|
||||
v /= 1000.0;
|
||||
i += 1;
|
||||
}
|
||||
let num = if v >= 100.0 {
|
||||
format!("{v:.0}")
|
||||
} else {
|
||||
format!("{v:.1}")
|
||||
};
|
||||
format!("{num} {}{unit}", PREFIXES[i])
|
||||
}
|
||||
|
||||
/// Compact human duration (e.g. "3d 4h", "5h 12m", "42m", "18s").
|
||||
pub fn format_uptime(secs: u64) -> String {
|
||||
if secs == 0 {
|
||||
return String::new();
|
||||
}
|
||||
let d = secs / 86_400;
|
||||
let h = (secs % 86_400) / 3600;
|
||||
let m = (secs % 3600) / 60;
|
||||
let s = secs % 60;
|
||||
if d > 0 {
|
||||
format!("{d}d {h}h")
|
||||
} else if h > 0 {
|
||||
format!("{h}h {m}m")
|
||||
} else if m > 0 {
|
||||
format!("{m}m")
|
||||
} else {
|
||||
format!("{s}s")
|
||||
}
|
||||
}
|
||||
|
||||
/// One miner's telemetry snapshot, flattened from asic-rs `MinerData` into the
|
||||
/// scalar fields the table can display. Absent metrics are `None` / empty /
|
||||
/// 0.0 and render as a blank cell.
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct MinerRow {
|
||||
pub ip: String,
|
||||
pub selected: bool,
|
||||
// identity
|
||||
pub model: String,
|
||||
pub mac: String,
|
||||
pub hostname: String,
|
||||
pub serial: String,
|
||||
pub firmware: String,
|
||||
pub api_version: String,
|
||||
pub control_board: String,
|
||||
// performance
|
||||
pub hashrate_ths: f64,
|
||||
#[allow(dead_code)] // used by the "slow" band view in later milestones
|
||||
pub expected_ths: f64,
|
||||
#[allow(dead_code)] // retained for the "slow" band; not shown as its own column
|
||||
pub efficiency: f64,
|
||||
pub power_w: f64,
|
||||
pub tuning_percent: Option<u8>,
|
||||
// thermal / cooling
|
||||
pub chip_temp_c: f64,
|
||||
pub fluid_temp_c: f64,
|
||||
pub outlet_temp_c: f64,
|
||||
pub fan_rpm: f64,
|
||||
pub psu_fan_rpm: f64,
|
||||
pub fan_count: Option<u32>,
|
||||
pub expected_fans: Option<u32>,
|
||||
// hardware counts
|
||||
pub total_chips: Option<u32>,
|
||||
pub expected_chips: Option<u32>,
|
||||
pub hashboards: Option<u32>,
|
||||
pub expected_hashboards: Option<u32>,
|
||||
// pool
|
||||
pub worker: String,
|
||||
pub pool_url: String,
|
||||
// shares
|
||||
pub best_share: Option<f64>,
|
||||
pub session_best_share: Option<f64>,
|
||||
// state
|
||||
pub uptime_secs: u64,
|
||||
pub light_flashing: Option<bool>,
|
||||
pub operating_state: String,
|
||||
pub is_mining: bool,
|
||||
pub slow: bool,
|
||||
}
|
||||
@@ -43,7 +130,8 @@ impl MinerRow {
|
||||
}
|
||||
}
|
||||
|
||||
/// Model columns. Sel and Ip are fixed (checkbox + always-on IP column).
|
||||
/// Model columns. Sel and Ip are fixed (checkbox + always-on IP column); the
|
||||
/// rest map 1:1 to a scannable metric and can be shown/hidden/reordered.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum Column {
|
||||
Sel,
|
||||
@@ -56,9 +144,34 @@ pub enum Column {
|
||||
Worker,
|
||||
Model,
|
||||
Status,
|
||||
ExpectedHashrate,
|
||||
Efficiency,
|
||||
FluidTemp,
|
||||
OutletTemp,
|
||||
PsuFan,
|
||||
FanCount,
|
||||
ExpectedFans,
|
||||
TotalChips,
|
||||
ExpectedChips,
|
||||
Hashboards,
|
||||
ExpectedHashboards,
|
||||
Mac,
|
||||
Hostname,
|
||||
Serial,
|
||||
ApiVersion,
|
||||
ControlBoard,
|
||||
Uptime,
|
||||
Light,
|
||||
OperatingState,
|
||||
BestShare,
|
||||
SessionBestShare,
|
||||
TuningPercent,
|
||||
PoolUrl,
|
||||
}
|
||||
|
||||
pub const ALL_COLUMNS: [Column; 10] = [
|
||||
/// Every column, in registry order. Sel + Ip first, then the default-visible
|
||||
/// set (UI-SPEC order), then all remaining metrics.
|
||||
pub const ALL_COLUMNS: [Column; 33] = [
|
||||
Column::Sel,
|
||||
Column::Ip,
|
||||
Column::Hashrate,
|
||||
@@ -69,6 +182,41 @@ pub const ALL_COLUMNS: [Column; 10] = [
|
||||
Column::Worker,
|
||||
Column::Model,
|
||||
Column::Status,
|
||||
Column::ExpectedHashrate,
|
||||
Column::Efficiency,
|
||||
Column::FluidTemp,
|
||||
Column::OutletTemp,
|
||||
Column::PsuFan,
|
||||
Column::FanCount,
|
||||
Column::ExpectedFans,
|
||||
Column::TotalChips,
|
||||
Column::ExpectedChips,
|
||||
Column::Hashboards,
|
||||
Column::ExpectedHashboards,
|
||||
Column::Mac,
|
||||
Column::Hostname,
|
||||
Column::Serial,
|
||||
Column::ApiVersion,
|
||||
Column::ControlBoard,
|
||||
Column::Uptime,
|
||||
Column::Light,
|
||||
Column::OperatingState,
|
||||
Column::BestShare,
|
||||
Column::SessionBestShare,
|
||||
Column::TuningPercent,
|
||||
Column::PoolUrl,
|
||||
];
|
||||
|
||||
/// The columns shown by default (UI-SPEC), after Sel + Ip.
|
||||
pub const DEFAULT_VISIBLE: [Column; 8] = [
|
||||
Column::Hashrate,
|
||||
Column::Power,
|
||||
Column::ChipTemp,
|
||||
Column::Cooling,
|
||||
Column::Firmware,
|
||||
Column::Worker,
|
||||
Column::Model,
|
||||
Column::Status,
|
||||
];
|
||||
|
||||
impl Column {
|
||||
@@ -76,84 +224,200 @@ impl Column {
|
||||
match self {
|
||||
Column::Sel => "",
|
||||
Column::Ip => "IP",
|
||||
Column::Hashrate => "Hashrate (TH/s)",
|
||||
Column::Power => "Power (W)",
|
||||
Column::ChipTemp => "Chip temp (C)",
|
||||
Column::Cooling => "Cooling (RPM)",
|
||||
Column::Hashrate => "Hashrate",
|
||||
Column::Power => "Power",
|
||||
Column::ChipTemp => "Chip temp",
|
||||
Column::Cooling => "Fan (RPM)",
|
||||
Column::Firmware => "Firmware",
|
||||
Column::Worker => "Pool worker",
|
||||
Column::Model => "Model",
|
||||
Column::Status => "Status",
|
||||
Column::ExpectedHashrate => "Expected HR",
|
||||
Column::Efficiency => "Efficiency (J/TH)",
|
||||
Column::FluidTemp => "Fluid temp",
|
||||
Column::OutletTemp => "Outlet temp",
|
||||
Column::PsuFan => "PSU fan (RPM)",
|
||||
Column::FanCount => "Fans",
|
||||
Column::ExpectedFans => "Fans (exp)",
|
||||
Column::TotalChips => "Chips",
|
||||
Column::ExpectedChips => "Chips (exp)",
|
||||
Column::Hashboards => "Boards",
|
||||
Column::ExpectedHashboards => "Boards (exp)",
|
||||
Column::Mac => "MAC",
|
||||
Column::Hostname => "Hostname",
|
||||
Column::Serial => "Serial",
|
||||
Column::ApiVersion => "API ver",
|
||||
Column::ControlBoard => "Control board",
|
||||
Column::Uptime => "Uptime",
|
||||
Column::Light => "Fault light",
|
||||
Column::OperatingState => "State",
|
||||
Column::BestShare => "Best share",
|
||||
Column::SessionBestShare => "Session best",
|
||||
Column::TuningPercent => "Tuning %",
|
||||
Column::PoolUrl => "Pool URL",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn width(self) -> i32 {
|
||||
match self {
|
||||
Column::Sel => 30,
|
||||
Column::Ip => 120,
|
||||
Column::Hashrate => 110,
|
||||
Column::Sel => 28,
|
||||
Column::Ip => 130,
|
||||
Column::Hashrate | Column::ExpectedHashrate => 110,
|
||||
Column::Power => 90,
|
||||
Column::ChipTemp => 100,
|
||||
Column::Cooling => 100,
|
||||
Column::Firmware => 180,
|
||||
Column::Worker => 160,
|
||||
Column::Model => 140,
|
||||
Column::Status => 100,
|
||||
Column::ChipTemp | Column::FluidTemp | Column::OutletTemp => 95,
|
||||
Column::Cooling | Column::PsuFan => 100,
|
||||
Column::Firmware => 160,
|
||||
Column::Worker => 150,
|
||||
Column::Model => 150,
|
||||
Column::Status => 95,
|
||||
Column::Efficiency => 120,
|
||||
Column::FanCount | Column::TotalChips | Column::Hashboards => 70,
|
||||
Column::ExpectedFans
|
||||
| Column::ExpectedChips
|
||||
| Column::ExpectedHashboards
|
||||
| Column::TuningPercent => 90,
|
||||
Column::Mac | Column::Hostname | Column::Serial => 150,
|
||||
Column::ApiVersion | Column::Light => 90,
|
||||
Column::ControlBoard => 130,
|
||||
Column::Uptime => 100,
|
||||
Column::OperatingState => 100,
|
||||
Column::BestShare | Column::SessionBestShare => 110,
|
||||
Column::PoolUrl => 220,
|
||||
}
|
||||
}
|
||||
|
||||
/// Sort key (numeric columns compare as f64; others as lowercase strings).
|
||||
/// Whether the column holds a continuous numeric value. Such columns sort
|
||||
/// numerically and are excluded from the Excel-style value filter (a
|
||||
/// per-value checklist only makes sense for categorical data).
|
||||
pub fn is_numeric(self) -> bool {
|
||||
matches!(
|
||||
self,
|
||||
Column::Hashrate
|
||||
| Column::ExpectedHashrate
|
||||
| Column::Power
|
||||
| Column::Efficiency
|
||||
| Column::ChipTemp
|
||||
| Column::FluidTemp
|
||||
| Column::OutletTemp
|
||||
| Column::Cooling
|
||||
| Column::PsuFan
|
||||
| Column::FanCount
|
||||
| Column::ExpectedFans
|
||||
| Column::TotalChips
|
||||
| Column::ExpectedChips
|
||||
| Column::Hashboards
|
||||
| Column::ExpectedHashboards
|
||||
| Column::Uptime
|
||||
| Column::BestShare
|
||||
| Column::SessionBestShare
|
||||
| Column::TuningPercent
|
||||
)
|
||||
}
|
||||
|
||||
/// Sort key. Numeric columns compare by their underlying number (absent =
|
||||
/// -inf so blanks sort to the bottom of a descending sort); others compare
|
||||
/// as lowercase strings.
|
||||
pub fn sort_key(&self, r: &MinerRow) -> SortKey {
|
||||
let none = f64::NEG_INFINITY;
|
||||
match self {
|
||||
Column::Sel => SortKey::Num(if r.selected { 1.0 } else { 0.0 }),
|
||||
Column::Ip => SortKey::Str(r.ip.clone()),
|
||||
Column::Hashrate => SortKey::Num(r.hashrate_ths),
|
||||
Column::ExpectedHashrate => SortKey::Num(r.expected_ths),
|
||||
Column::Power => SortKey::Num(r.power_w),
|
||||
Column::Efficiency => SortKey::Num(if r.efficiency > 0.0 { r.efficiency } else { none }),
|
||||
Column::ChipTemp => SortKey::Num(r.chip_temp_c),
|
||||
Column::FluidTemp => SortKey::Num(r.fluid_temp_c),
|
||||
Column::OutletTemp => SortKey::Num(r.outlet_temp_c),
|
||||
Column::Cooling => SortKey::Num(r.fan_rpm),
|
||||
Column::Firmware => SortKey::Str(r.firmware.to_lowercase()),
|
||||
Column::Worker => SortKey::Str(r.worker.to_lowercase()),
|
||||
Column::Model => SortKey::Str(r.model.to_lowercase()),
|
||||
Column::Status => SortKey::Str(r.status().to_string()),
|
||||
Column::PsuFan => SortKey::Num(r.psu_fan_rpm),
|
||||
Column::FanCount => SortKey::Num(r.fan_count.map(|v| v as f64).unwrap_or(none)),
|
||||
Column::ExpectedFans => SortKey::Num(r.expected_fans.map(|v| v as f64).unwrap_or(none)),
|
||||
Column::TotalChips => SortKey::Num(r.total_chips.map(|v| v as f64).unwrap_or(none)),
|
||||
Column::ExpectedChips => SortKey::Num(r.expected_chips.map(|v| v as f64).unwrap_or(none)),
|
||||
Column::Hashboards => SortKey::Num(r.hashboards.map(|v| v as f64).unwrap_or(none)),
|
||||
Column::ExpectedHashboards => {
|
||||
SortKey::Num(r.expected_hashboards.map(|v| v as f64).unwrap_or(none))
|
||||
}
|
||||
Column::Uptime => SortKey::Num(if r.uptime_secs > 0 { r.uptime_secs as f64 } else { none }),
|
||||
Column::BestShare => SortKey::Num(r.best_share.unwrap_or(none)),
|
||||
Column::SessionBestShare => SortKey::Num(r.session_best_share.unwrap_or(none)),
|
||||
Column::TuningPercent => {
|
||||
SortKey::Num(r.tuning_percent.map(|v| v as f64).unwrap_or(none))
|
||||
}
|
||||
_ => SortKey::Str(self.cell(r).to_lowercase()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cell(&self, r: &MinerRow) -> String {
|
||||
let num = |v: f64, dp: usize, suffix: &str| -> String {
|
||||
if v > 0.0 {
|
||||
match dp {
|
||||
0 => format!("{v:.0}{suffix}"),
|
||||
_ => format!("{v:.1}{suffix}"),
|
||||
}
|
||||
} else {
|
||||
String::new()
|
||||
}
|
||||
};
|
||||
let count = |v: Option<u32>| -> String { v.map(|n| n.to_string()).unwrap_or_default() };
|
||||
match self {
|
||||
Column::Sel => String::new(),
|
||||
Column::Ip => r.ip.clone(),
|
||||
Column::Hashrate => {
|
||||
if r.hashrate_ths > 0.0 {
|
||||
format!("{:.1}", r.hashrate_ths)
|
||||
format_si(r.hashrate_ths * 1e12, "H/s")
|
||||
} else {
|
||||
String::new()
|
||||
}
|
||||
}
|
||||
Column::ExpectedHashrate => {
|
||||
if r.expected_ths > 0.0 {
|
||||
format_si(r.expected_ths * 1e12, "H/s")
|
||||
} else {
|
||||
String::new()
|
||||
}
|
||||
}
|
||||
Column::Power => {
|
||||
if r.power_w > 0.0 {
|
||||
format!("{:.0}", r.power_w)
|
||||
} else {
|
||||
String::new()
|
||||
}
|
||||
}
|
||||
Column::ChipTemp => {
|
||||
if r.chip_temp_c > 0.0 {
|
||||
format!("{:.1}", r.chip_temp_c)
|
||||
} else {
|
||||
String::new()
|
||||
}
|
||||
}
|
||||
Column::Cooling => {
|
||||
if r.fan_rpm > 0.0 {
|
||||
format!("{:.0}", r.fan_rpm)
|
||||
format_si(r.power_w, "W")
|
||||
} else {
|
||||
String::new()
|
||||
}
|
||||
}
|
||||
Column::Efficiency => num(r.efficiency, 1, ""),
|
||||
Column::ChipTemp => num(r.chip_temp_c, 1, " C"),
|
||||
Column::FluidTemp => num(r.fluid_temp_c, 1, " C"),
|
||||
Column::OutletTemp => num(r.outlet_temp_c, 1, " C"),
|
||||
Column::Cooling => num(r.fan_rpm, 0, ""),
|
||||
Column::PsuFan => num(r.psu_fan_rpm, 0, ""),
|
||||
Column::FanCount => count(r.fan_count),
|
||||
Column::ExpectedFans => count(r.expected_fans),
|
||||
Column::TotalChips => count(r.total_chips),
|
||||
Column::ExpectedChips => count(r.expected_chips),
|
||||
Column::Hashboards => count(r.hashboards),
|
||||
Column::ExpectedHashboards => count(r.expected_hashboards),
|
||||
Column::Firmware => r.firmware.clone(),
|
||||
Column::Worker => r.worker.clone(),
|
||||
Column::PoolUrl => r.pool_url.clone(),
|
||||
Column::Model => r.model.clone(),
|
||||
Column::Mac => r.mac.clone(),
|
||||
Column::Hostname => r.hostname.clone(),
|
||||
Column::Serial => r.serial.clone(),
|
||||
Column::ApiVersion => r.api_version.clone(),
|
||||
Column::ControlBoard => r.control_board.clone(),
|
||||
Column::Status => r.status().to_string(),
|
||||
Column::Uptime => format_uptime(r.uptime_secs),
|
||||
Column::Light => match r.light_flashing {
|
||||
Some(true) => "on".to_string(),
|
||||
Some(false) => "off".to_string(),
|
||||
None => String::new(),
|
||||
},
|
||||
Column::OperatingState => r.operating_state.clone(),
|
||||
Column::BestShare => r.best_share.map(|v| format_si(v, "")).unwrap_or_default(),
|
||||
Column::SessionBestShare => {
|
||||
r.session_best_share.map(|v| format_si(v, "")).unwrap_or_default()
|
||||
}
|
||||
Column::TuningPercent => r.tuning_percent.map(|v| format!("{v}%")).unwrap_or_default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -175,21 +439,11 @@ pub struct ViewState {
|
||||
|
||||
impl Default for ViewState {
|
||||
fn default() -> Self {
|
||||
// UI-SPEC default order: checkbox, IP, hashrate, power, chip temp,
|
||||
// cooling, firmware, pool worker, then the rest.
|
||||
let order = vec![
|
||||
Column::Sel,
|
||||
Column::Ip,
|
||||
Column::Hashrate,
|
||||
Column::Power,
|
||||
Column::ChipTemp,
|
||||
Column::Cooling,
|
||||
Column::Firmware,
|
||||
Column::Worker,
|
||||
Column::Model,
|
||||
Column::Status,
|
||||
];
|
||||
let visible: HashSet<Column> = order.iter().copied().collect();
|
||||
// Registry order for `order`; only Sel + Ip + DEFAULT_VISIBLE are shown.
|
||||
let order: Vec<Column> = ALL_COLUMNS.to_vec();
|
||||
let mut visible: HashSet<Column> = DEFAULT_VISIBLE.iter().copied().collect();
|
||||
visible.insert(Column::Sel);
|
||||
visible.insert(Column::Ip);
|
||||
ViewState { order, visible, sort: None, filters: HashMap::new() }
|
||||
}
|
||||
}
|
||||
@@ -207,46 +461,36 @@ impl ViewState {
|
||||
c == Column::Sel || c == Column::Ip
|
||||
}
|
||||
|
||||
/// Rows that pass every active filter (AND across, OR within).
|
||||
/// Apply a drag-reorder of the visible columns. `new_visible` is the visible
|
||||
/// columns in their new display order; it must be a permutation of the
|
||||
/// currently-visible set with Sel still first. The new order is spliced back
|
||||
/// into `order`, leaving hidden columns in their existing slots, so a
|
||||
/// reorder while some column is hidden never drops or duplicates a column.
|
||||
pub fn apply_visible_reorder(&mut self, new_visible: &[Column]) {
|
||||
let disp = self.display_columns();
|
||||
if new_visible.len() != disp.len() || new_visible.first() != Some(&Column::Sel) {
|
||||
return;
|
||||
}
|
||||
let want: HashSet<Column> = disp.iter().copied().collect();
|
||||
let got: HashSet<Column> = new_visible.iter().copied().collect();
|
||||
if want != got {
|
||||
return; // not a permutation of the visible columns: ignore
|
||||
}
|
||||
let mut next = new_visible.iter().copied();
|
||||
self.order = self
|
||||
.order
|
||||
.iter()
|
||||
.map(|&c| if want.contains(&c) { next.next().unwrap_or(c) } else { c })
|
||||
.collect();
|
||||
}
|
||||
|
||||
/// Rows that pass every active filter (AND across columns, OR within one).
|
||||
pub fn passes_filters(&self, r: &MinerRow) -> bool {
|
||||
self.filters.iter().all(|(col, allowed)| {
|
||||
let v = match col {
|
||||
Column::Sel => return true,
|
||||
Column::Ip => r.ip.clone(),
|
||||
Column::Hashrate => {
|
||||
if r.hashrate_ths > 0.0 {
|
||||
format!("{:.1}", r.hashrate_ths)
|
||||
} else {
|
||||
String::new()
|
||||
}
|
||||
}
|
||||
Column::Power => {
|
||||
if r.power_w > 0.0 {
|
||||
format!("{:.0}", r.power_w)
|
||||
} else {
|
||||
String::new()
|
||||
}
|
||||
}
|
||||
Column::ChipTemp => {
|
||||
if r.chip_temp_c > 0.0 {
|
||||
format!("{:.1}", r.chip_temp_c)
|
||||
} else {
|
||||
String::new()
|
||||
}
|
||||
}
|
||||
Column::Cooling => {
|
||||
if r.fan_rpm > 0.0 {
|
||||
format!("{:.0}", r.fan_rpm)
|
||||
} else {
|
||||
String::new()
|
||||
}
|
||||
}
|
||||
Column::Firmware => r.firmware.clone(),
|
||||
Column::Worker => r.worker.clone(),
|
||||
Column::Model => r.model.clone(),
|
||||
Column::Status => r.status().to_string(),
|
||||
};
|
||||
allowed.contains(&v)
|
||||
if *col == Column::Sel {
|
||||
return true;
|
||||
}
|
||||
allowed.contains(&col.cell(r))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -297,3 +541,177 @@ pub fn compute_kpis(rows: &[MinerRow], view_idx: &[usize]) -> Kpis {
|
||||
}
|
||||
k
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
//! Offline workflow tests: feed the bench-fleet fixtures (the expected
|
||||
//! hardware output) through the app's transforms and assert the produced
|
||||
//! result. These need no display and run under plain `cargo test`.
|
||||
use super::*;
|
||||
use crate::fixtures::bench_fleet;
|
||||
|
||||
fn full_view() -> (Vec<MinerRow>, ViewState, Vec<usize>) {
|
||||
let rows = bench_fleet();
|
||||
let view = ViewState::default();
|
||||
let idx = view.view(&rows);
|
||||
(rows, view, idx)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn kpis_match_expected_hardware_output() {
|
||||
let (rows, _v, idx) = full_view();
|
||||
let k = compute_kpis(&rows, &idx);
|
||||
assert_eq!(k.total, 9, "total miners");
|
||||
assert_eq!(k.hashing, 6, "hashing");
|
||||
assert_eq!(k.slow, 1, "slow");
|
||||
assert_eq!(k.not_hashing, 2, "not hashing");
|
||||
assert!((k.total_hashrate_ths - 685.0).abs() < 1e-9, "hashrate {}", k.total_hashrate_ths);
|
||||
assert!((k.total_power_w - 21300.0).abs() < 1e-9, "power {}", k.total_power_w);
|
||||
assert_eq!(k.total, k.hashing + k.slow + k.not_hashing);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn slow_band_classification() {
|
||||
assert!(is_slow(true, 60.0, 200.0));
|
||||
assert!(!is_slow(true, 90.0, 100.0));
|
||||
assert!(!is_slow(true, 80.0, 100.0));
|
||||
assert!(!is_slow(false, 0.0, 200.0));
|
||||
assert!(!is_slow(true, 1.0, 0.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn si_formatting() {
|
||||
assert_eq!(format_si(21300.0, "W"), "21.3 kW");
|
||||
assert_eq!(format_si(685e12, "H/s"), "685 TH/s");
|
||||
assert_eq!(format_si(95e12, "H/s"), "95.0 TH/s");
|
||||
assert_eq!(format_si(6.8e12, "H/s"), "6.8 TH/s");
|
||||
assert_eq!(format_si(3250.0, "W"), "3.2 kW");
|
||||
assert_eq!(format_si(0.0, "W"), "0 W");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cell_formatting_blanks_zeroes() {
|
||||
let rows = bench_fleet();
|
||||
let s17 = rows.iter().find(|r| r.ip == "10.255.1.112").unwrap();
|
||||
assert_eq!(Column::Hashrate.cell(s17), "");
|
||||
assert_eq!(Column::Power.cell(s17), "");
|
||||
assert_eq!(Column::ChipTemp.cell(s17), "");
|
||||
assert_eq!(Column::Status.cell(s17), "not hashing");
|
||||
|
||||
let s21 = rows.iter().find(|r| r.ip == "10.255.1.149").unwrap();
|
||||
assert_eq!(Column::Hashrate.cell(s21), "60.0 TH/s");
|
||||
assert_eq!(Column::Power.cell(s21), "1.5 kW");
|
||||
assert_eq!(Column::Status.cell(s21), "slow");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn default_view_is_insertion_order() {
|
||||
let (rows, _v, idx) = full_view();
|
||||
let ips: Vec<&str> = idx.iter().map(|&i| rows[i].ip.as_str()).collect();
|
||||
assert_eq!(ips[0], "10.255.1.112");
|
||||
assert_eq!(ips.len(), 9);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sort_by_hashrate() {
|
||||
let rows = bench_fleet();
|
||||
let mut view = ViewState::default();
|
||||
view.sort = Some((Column::Hashrate, false));
|
||||
let idx = view.view(&rows);
|
||||
assert_eq!(rows[idx[0]].ip, "10.255.1.167");
|
||||
assert!(rows[idx[0]].hashrate_ths >= rows[idx[1]].hashrate_ths);
|
||||
view.sort = Some((Column::Hashrate, true));
|
||||
let idx = view.view(&rows);
|
||||
assert_eq!(rows[idx[0]].hashrate_ths, 0.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn filter_by_status_slow() {
|
||||
let rows = bench_fleet();
|
||||
let mut view = ViewState::default();
|
||||
let mut allowed = HashSet::new();
|
||||
allowed.insert("slow".to_string());
|
||||
view.filters.insert(Column::Status, allowed);
|
||||
let idx = view.view(&rows);
|
||||
assert_eq!(idx.len(), 1);
|
||||
assert_eq!(rows[idx[0]].ip, "10.255.1.149");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn default_visible_is_the_ui_spec_set() {
|
||||
let view = ViewState::default();
|
||||
let disp = view.display_columns();
|
||||
// Sel, Ip, then the 8 default columns in order.
|
||||
assert_eq!(disp[0], Column::Sel);
|
||||
assert_eq!(disp[1], Column::Ip);
|
||||
assert_eq!(&disp[2..], &DEFAULT_VISIBLE[..]);
|
||||
// hidden-by-default metrics are still selectable (present in order).
|
||||
assert!(view.order.contains(&Column::Mac));
|
||||
assert!(view.order.contains(&Column::Uptime));
|
||||
assert!(!view.visible.contains(&Column::Mac));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hiding_a_column_shifts_display_columns() {
|
||||
let mut view = ViewState::default();
|
||||
let before = view.display_columns();
|
||||
assert!(before.contains(&Column::Power));
|
||||
view.visible.remove(&Column::Power);
|
||||
let after = view.display_columns();
|
||||
assert!(!after.contains(&Column::Power));
|
||||
assert_eq!(after[0], Column::Sel);
|
||||
assert_eq!(after[1], Column::Ip);
|
||||
assert_eq!(after.len(), before.len() - 1);
|
||||
let hr = after.iter().position(|c| *c == Column::Hashrate).unwrap();
|
||||
assert_eq!(after[hr + 1], Column::ChipTemp);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn showing_a_hidden_metric_adds_a_column() {
|
||||
let mut view = ViewState::default();
|
||||
assert!(!view.display_columns().contains(&Column::Uptime));
|
||||
view.visible.insert(Column::Uptime);
|
||||
assert!(view.display_columns().contains(&Column::Uptime));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reorder_with_hidden_column_keeps_all_columns() {
|
||||
let mut view = ViewState::default();
|
||||
view.visible.remove(&Column::Power);
|
||||
let mut vis = view.display_columns();
|
||||
vis.swap(2, 3); // swap Hashrate and ChipTemp
|
||||
view.apply_visible_reorder(&vis);
|
||||
assert!(view.order.contains(&Column::Power), "hidden column dropped!");
|
||||
assert_eq!(view.order.len(), ALL_COLUMNS.len());
|
||||
let set: HashSet<Column> = view.order.iter().copied().collect();
|
||||
assert_eq!(set.len(), ALL_COLUMNS.len());
|
||||
let disp = view.display_columns();
|
||||
let hr = disp.iter().position(|c| *c == Column::Hashrate).unwrap();
|
||||
let ct = disp.iter().position(|c| *c == Column::ChipTemp).unwrap();
|
||||
assert!(ct < hr, "reorder not applied");
|
||||
assert_eq!(view.order[0], Column::Sel);
|
||||
assert_eq!(view.order[1], Column::Ip);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reorder_rejects_non_permutation() {
|
||||
let mut view = ViewState::default();
|
||||
let before = view.order.clone();
|
||||
view.apply_visible_reorder(&[Column::Ip, Column::Sel, Column::Hashrate]);
|
||||
assert_eq!(view.order, before);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn selection_survives_upsert() {
|
||||
let mut rows = bench_fleet();
|
||||
rows[1].selected = true;
|
||||
let ip = rows[1].ip.clone();
|
||||
let mut update = bench_fleet()[1].clone();
|
||||
update.hashrate_ths = 12.3;
|
||||
let new = update.upsert_into(&mut rows);
|
||||
assert!(!new, "same IP is an update, not an insert");
|
||||
let r = rows.iter().find(|r| r.ip == ip).unwrap();
|
||||
assert!(r.selected, "selection preserved across upsert");
|
||||
assert_eq!(r.hashrate_ths, 12.3, "data updated");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user