Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4fea3becf6 | ||
|
|
7781ff71d3 |
@@ -1,10 +1,9 @@
|
||||
//! Bench-fleet fixtures: the expected hardware output of the 9 boards on
|
||||
//! 10.255.1.0/24 (see ../../../HANDOFF.md section 7 and the parent project's
|
||||
//! [removed]), plus one synthetic unreachable IP rendered via
|
||||
//! `MinerRow::offline()` so the "offline" status/row shape is exercisable
|
||||
//! offline too (10 rows total). These are the reference values the workflow
|
||||
//! tests compare the application's actual output against, and the rows the
|
||||
//! offline `ALKANE_FAKE_SCAN` demo mode renders.
|
||||
//! [removed]). These are the reference values the workflow tests compare
|
||||
//! the application's actual output against, and the rows the offline
|
||||
//! `ALKANE_FAKE_SCAN` demo mode renders. Only miners that respond become rows,
|
||||
//! so there is no synthetic "offline" fixture.
|
||||
//!
|
||||
//! Hashrate/power/temp are representative per-model figures (the bench boards
|
||||
//! are not always energised); the point of the fixtures is a fixed, known input
|
||||
@@ -107,28 +106,50 @@ impl Board {
|
||||
tuning: self.mining,
|
||||
firmware_flash,
|
||||
},
|
||||
// Demo values for the round-8 columns (synthetic, so the columns
|
||||
// show variety offline).
|
||||
control_board: if self.model.contains("S17") {
|
||||
"Xilinx".to_string()
|
||||
} else if self.model.contains("S19j") || self.model.contains("S19k") {
|
||||
"AMLogic".to_string()
|
||||
} else if self.model.contains("S19") {
|
||||
"BeagleBone Black".to_string()
|
||||
} else if self.model.contains("S21") {
|
||||
"CVITek".to_string()
|
||||
} else {
|
||||
String::new()
|
||||
},
|
||||
pic_present: if self.model.contains("S21") {
|
||||
Some(false) // noPIC example
|
||||
} else if self.model.starts_with("Antminer") {
|
||||
Some(true)
|
||||
} else {
|
||||
None // WhatsMiner: unknown over the network
|
||||
},
|
||||
// Access: idle/view-only units (no worker) shown locked; the rest
|
||||
// unlocked. (Live rows infer this from control capabilities.)
|
||||
write_locked: Some(self.worker.is_empty()),
|
||||
errors: if self.model.contains("S21 Pro") {
|
||||
vec![
|
||||
"[Warning] hashrate 70% below expected".to_string(),
|
||||
"[Warning] chip temperature high (HashBoard 2)".to_string(),
|
||||
]
|
||||
} else {
|
||||
Vec::new()
|
||||
},
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The 9 bench boards plus one synthetic offline entry (10 rows total).
|
||||
/// One is idle/not-hashing (S17 stock, .112); one is paused (WardenOS dev,
|
||||
/// .115 - deliberately rebucketed from idle so the "paused" status/KPI
|
||||
/// bucket is exercisable offline); one is slow (S21 Pro aml stock at ~30%
|
||||
/// of expected); the other six hash normally; the last row is an
|
||||
/// unreachable IP rendered via `MinerRow::offline()` (blank fields,
|
||||
/// `offline: true`).
|
||||
/// The 9 bench boards (9 rows total). One is idle/not-hashing (S17 stock,
|
||||
/// .112); one is paused (WardenOS dev, .115 - deliberately rebucketed from idle
|
||||
/// so the "paused" status/KPI bucket is exercisable offline); one is slow (S21
|
||||
/// Pro aml stock at ~30% of expected); the other six hash normally.
|
||||
///
|
||||
/// Derived totals (used by the workflow tests):
|
||||
/// total = 10, hashing = 6, slow = 1, not hashing = 1, paused = 1, offline = 1,
|
||||
/// total hashrate = 685.0 TH/s, total power = 21300 W (offline row is all zero).
|
||||
///
|
||||
/// Note: `compute_kpis` has no separate "offline" bucket - an offline row is
|
||||
/// `!is_mining && !paused && !slow`, so it folds into the "not hashing" KPI
|
||||
/// alongside the idle S17, giving `Kpis.not_hashing == 2`. The per-row
|
||||
/// `status()` text still distinguishes them ("not hashing" for .112 vs.
|
||||
/// "offline" for .199).
|
||||
/// total = 9, hashing = 6, slow = 1, not hashing = 1, paused = 1,
|
||||
/// total hashrate = 685.0 TH/s, total power = 21300 W.
|
||||
pub fn bench_fleet() -> Vec<MinerRow> {
|
||||
let boards = [
|
||||
Board { ip: "10.255.1.112", model: "Antminer S17", firmware: "Stock",
|
||||
@@ -161,8 +182,5 @@ pub fn bench_fleet() -> Vec<MinerRow> {
|
||||
hashrate: 0.0, expected: 0.0, power: 0.0, temp: 0.0, fan: 0.0,
|
||||
worker: "", mining: false, paused: true },
|
||||
];
|
||||
let mut rows: Vec<MinerRow> = boards.into_iter().map(Board::into_row).collect();
|
||||
// Synthetic offline board: unreachable IP, blank/zeroed fields, offline: true.
|
||||
rows.push(MinerRow::offline("10.255.1.199".into()));
|
||||
rows
|
||||
boards.into_iter().map(Board::into_row).collect()
|
||||
}
|
||||
|
||||
+136
-81
@@ -68,6 +68,13 @@ pub fn format_fan_rpm(rpm: f64) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
/// A hashrate reading (in TH/s) for the combined Hashrate column: mantissa + SI
|
||||
/// prefix only, no unit and no space (80.5 TH/s -> "80.5T", 102 TH/s -> "102T"),
|
||||
/// or `None` for an absent/non-positive reading.
|
||||
pub fn format_hashrate_ths(ths: f64) -> Option<String> {
|
||||
si_mantissa_and_prefix(ths * 1e12).map(|(num, prefix)| format!("{num}{prefix}"))
|
||||
}
|
||||
|
||||
/// The actual/expected ratio, or `None` when the expected value is unknown
|
||||
/// (<= 0.0) so a ratio-based color/warning never divides by zero or treats an
|
||||
/// unknown expectation as a 0% shortfall.
|
||||
@@ -75,19 +82,16 @@ pub fn actual_expected_ratio(actual: f64, expected: f64) -> Option<f64> {
|
||||
if expected > 0.0 { Some(actual / expected) } else { None }
|
||||
}
|
||||
|
||||
/// Render a combined "actual / expected" cell for a value shown against its
|
||||
/// model-expected counterpart (UI-SPEC combined columns: Hashrate,
|
||||
/// Hashboards, TotalChips): blank when neither is known, the bare actual
|
||||
/// when only it is known, "- / <expected>" when only the expected is known,
|
||||
/// and "<actual> / <expected>" when both are.
|
||||
/// Render the combined Hashrate cell "actual/expected" (no spaces around the
|
||||
/// slash, prefix-only unit): blank when neither is known, the bare actual when
|
||||
/// only it is known, "-/<expected>" when only the expected is known, and
|
||||
/// "<actual>/<expected>" when both are (e.g. "80.5T/95.0T").
|
||||
fn combined_si(actual_ths: f64, expected_ths: f64) -> String {
|
||||
let actual = (actual_ths > 0.0).then(|| format_si(actual_ths * 1e12, "H/s"));
|
||||
let expected = (expected_ths > 0.0).then(|| format_si(expected_ths * 1e12, "H/s"));
|
||||
match (actual, expected) {
|
||||
match (format_hashrate_ths(actual_ths), format_hashrate_ths(expected_ths)) {
|
||||
(None, None) => String::new(),
|
||||
(Some(a), None) => a,
|
||||
(None, Some(e)) => format!("- / {e}"),
|
||||
(Some(a), Some(e)) => format!("{a} / {e}"),
|
||||
(None, Some(e)) => format!("-/{e}"),
|
||||
(Some(a), Some(e)) => format!("{a}/{e}"),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,6 +212,18 @@ impl MinerCaps {
|
||||
pub fn is_empty(self) -> bool {
|
||||
self == MinerCaps::default()
|
||||
}
|
||||
|
||||
/// Whether the miner exposes any writable control action at all. Used to
|
||||
/// infer the "Access" (locked/unlocked) column: no control -> view-only.
|
||||
pub fn any_control(self) -> bool {
|
||||
self.fault_light
|
||||
|| self.restart
|
||||
|| self.pause
|
||||
|| self.resume
|
||||
|| self.power_limit
|
||||
|| self.tuning
|
||||
|| self.firmware_flash
|
||||
}
|
||||
}
|
||||
|
||||
/// One miner's telemetry snapshot, flattened from asic-rs `MinerData` into the
|
||||
@@ -227,6 +243,19 @@ pub struct MinerRow {
|
||||
pub firmware: String,
|
||||
pub api_version: String,
|
||||
pub control_board: String,
|
||||
/// Whether the hashboards carry a PIC MCU. asic-rs does not report this over
|
||||
/// the network, so it is a best-effort inference (model-string heuristic):
|
||||
/// `None` = unknown, `Some(true)` = PIC, `Some(false)` = noPIC. True
|
||||
/// detection needs an on-board SSH/I2C probe (a separate feature).
|
||||
pub pic_present: Option<bool>,
|
||||
/// Whether this miner is locked to view-only (no command writes). Inferred
|
||||
/// from whether any control capability is available: `None` = unknown,
|
||||
/// `Some(true)` = locked, `Some(false)` = unlocked/writable.
|
||||
pub write_locked: Option<bool>,
|
||||
/// Structured error/event lines from the miner (severity + text), most
|
||||
/// severe first. Empty means none. The Error column shows a summary; the
|
||||
/// full list is the hover tooltip (added with the tooltip bridge support).
|
||||
pub errors: Vec<String>,
|
||||
// performance
|
||||
pub hashrate_ths: f64,
|
||||
pub expected_ths: f64,
|
||||
@@ -266,30 +295,14 @@ pub struct MinerRow {
|
||||
/// Not-mining because an operator paused it (distinct from simply idle);
|
||||
/// see `is_paused`.
|
||||
pub paused: bool,
|
||||
/// Whether this miner FAILED to respond to the scan. Stored as `offline`
|
||||
/// (not `online`) so `Default` gives `false` -- i.e. a plain
|
||||
/// `MinerRow { ..Default::default() }` is a reachable row, and only
|
||||
/// `MinerRow::offline` deliberately marks a row unreachable. This removes
|
||||
/// the old footgun where a struct-update literal that forgot `online: true`
|
||||
/// silently read back as offline.
|
||||
pub offline: bool,
|
||||
}
|
||||
|
||||
impl MinerRow {
|
||||
/// A miner that did not respond to this scan attempt: ip only, every
|
||||
/// other field blank/zero/false, `offline: true` so `status()` reports
|
||||
/// "offline".
|
||||
pub fn offline(ip: String) -> MinerRow {
|
||||
let mut r = MinerRow::default();
|
||||
r.ip = ip;
|
||||
r.offline = true;
|
||||
r
|
||||
}
|
||||
|
||||
/// The row's status label. Only miners that actually responded to a scan
|
||||
/// become rows, so there is no "offline" state: a responding miner that is
|
||||
/// not mining is "not hashing".
|
||||
pub fn status(&self) -> &'static str {
|
||||
if self.offline {
|
||||
"offline"
|
||||
} else if self.slow {
|
||||
if self.slow {
|
||||
"slow"
|
||||
} else if self.paused {
|
||||
"paused"
|
||||
@@ -356,6 +369,9 @@ pub enum Column {
|
||||
Serial,
|
||||
ApiVersion,
|
||||
ControlBoard,
|
||||
Pic,
|
||||
Locked,
|
||||
Error,
|
||||
Uptime,
|
||||
Light,
|
||||
OperatingState,
|
||||
@@ -373,7 +389,7 @@ pub enum Column {
|
||||
|
||||
/// Every column, in registry order. Ip first, then the default-visible set
|
||||
/// (UI-SPEC order), then all remaining metrics.
|
||||
pub const ALL_COLUMNS: [Column; 35] = [
|
||||
pub const ALL_COLUMNS: [Column; 38] = [
|
||||
Column::Ip,
|
||||
Column::Hashrate,
|
||||
Column::Power,
|
||||
@@ -396,6 +412,9 @@ pub const ALL_COLUMNS: [Column; 35] = [
|
||||
Column::Serial,
|
||||
Column::ApiVersion,
|
||||
Column::ControlBoard,
|
||||
Column::Pic,
|
||||
Column::Locked,
|
||||
Column::Error,
|
||||
Column::Uptime,
|
||||
Column::Light,
|
||||
Column::OperatingState,
|
||||
@@ -448,8 +467,11 @@ impl Column {
|
||||
Column::Serial => "Serial",
|
||||
Column::ApiVersion => "API ver",
|
||||
Column::ControlBoard => "Control board",
|
||||
Column::Pic => "PIC",
|
||||
Column::Locked => "Access",
|
||||
Column::Error => "Errors",
|
||||
Column::Uptime => "Uptime",
|
||||
Column::Light => "Fault light",
|
||||
Column::Light => "Light",
|
||||
Column::OperatingState => "State",
|
||||
Column::BestShare => "Best share",
|
||||
Column::SessionBestShare => "Session best",
|
||||
@@ -481,6 +503,9 @@ impl Column {
|
||||
Column::Mac | Column::Hostname | Column::Serial => 150,
|
||||
Column::ApiVersion | Column::Light => 90,
|
||||
Column::ControlBoard => 130,
|
||||
Column::Pic => 70,
|
||||
Column::Locked => 90,
|
||||
Column::Error => 160,
|
||||
Column::Uptime => 100,
|
||||
Column::OperatingState => 100,
|
||||
Column::BestShare | Column::SessionBestShare => 110,
|
||||
@@ -619,6 +644,21 @@ impl Column {
|
||||
Column::Serial => r.serial.clone(),
|
||||
Column::ApiVersion => r.api_version.clone(),
|
||||
Column::ControlBoard => r.control_board.clone(),
|
||||
Column::Pic => match r.pic_present {
|
||||
Some(true) => "PIC".to_string(),
|
||||
Some(false) => "noPIC".to_string(),
|
||||
None => "?".to_string(),
|
||||
},
|
||||
Column::Locked => match r.write_locked {
|
||||
Some(true) => "locked".to_string(),
|
||||
Some(false) => "unlocked".to_string(),
|
||||
None => "?".to_string(),
|
||||
},
|
||||
Column::Error => match r.errors.len() {
|
||||
0 => String::new(),
|
||||
1 => r.errors[0].clone(),
|
||||
n => format!("{n} errors"),
|
||||
},
|
||||
Column::Status => r.status().to_string(),
|
||||
Column::Uptime => format_uptime(r.uptime_secs),
|
||||
Column::Light => match r.light_flashing {
|
||||
@@ -800,9 +840,9 @@ impl ViewState {
|
||||
}
|
||||
}
|
||||
|
||||
/// The KPIs (UI-SPEC header), derived from the filtered view. There is no
|
||||
/// separate "offline" bucket: an offline row is (by construction) neither
|
||||
/// slow, paused, nor mining, so it folds into `not_hashing`.
|
||||
/// The KPIs (UI-SPEC header), derived from the filtered view. Every row is a
|
||||
/// miner that responded to a scan; a responding non-mining miner counts as
|
||||
/// `not_hashing`.
|
||||
pub struct Kpis {
|
||||
pub total: usize,
|
||||
pub hashing: usize,
|
||||
@@ -826,8 +866,7 @@ pub fn compute_kpis(rows: &[MinerRow], view_idx: &[usize]) -> Kpis {
|
||||
for &i in view_idx {
|
||||
let r = &rows[i];
|
||||
// Bucket by the same precedence status() uses, so the KPI header can
|
||||
// never disagree with a row's own status text. There is no separate
|
||||
// "offline" KPI, so offline folds into not_hashing (the `_` arm).
|
||||
// never disagree with a row's own status text.
|
||||
match r.status() {
|
||||
"slow" => k.slow += 1,
|
||||
"paused" => k.paused += 1,
|
||||
@@ -857,12 +896,9 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn kpis_match_expected_hardware_output() {
|
||||
// Round-6 fixtures are being rebucketed concurrently (an idle board
|
||||
// moved into "paused", a new offline row added), so this does not
|
||||
// hardcode fixture counts: it independently recomputes each expected
|
||||
// KPI bucket and sum straight from the rows (via `status()`, a
|
||||
// separate code path from `compute_kpis`'s own if/else chain) and
|
||||
// cross-checks `compute_kpis`'s output against that.
|
||||
// This does not hardcode fixture counts: it independently recomputes
|
||||
// each expected KPI bucket and sum straight from the rows (via
|
||||
// `status()`) and cross-checks `compute_kpis`'s output against that.
|
||||
let (rows, _v, idx) = full_view();
|
||||
let k = compute_kpis(&rows, &idx);
|
||||
|
||||
@@ -875,8 +911,7 @@ mod tests {
|
||||
"slow" => exp_slow += 1,
|
||||
"paused" => exp_paused += 1,
|
||||
"hashing" => exp_hashing += 1,
|
||||
// offline folds into not_hashing for KPIs (no separate bucket).
|
||||
"not hashing" | "offline" => exp_not_hashing += 1,
|
||||
"not hashing" => exp_not_hashing += 1,
|
||||
other => panic!("unexpected status: {other}"),
|
||||
}
|
||||
}
|
||||
@@ -921,8 +956,8 @@ mod tests {
|
||||
assert_eq!(Column::Status.cell(s17), "not hashing");
|
||||
|
||||
let s21 = rows.iter().find(|r| r.ip == "10.255.1.149").unwrap();
|
||||
// Combined actual/expected cell: both known -> "<actual> / <expected>".
|
||||
assert_eq!(Column::Hashrate.cell(s21), "60.0 TH/s / 200 TH/s");
|
||||
// Combined hashrate cell: both known -> "<actual>/<expected>" (no spaces).
|
||||
assert_eq!(Column::Hashrate.cell(s21), "60.0T/200T");
|
||||
assert_eq!(Column::Power.cell(s21), "1.5 kW");
|
||||
assert_eq!(Column::Status.cell(s21), "slow");
|
||||
}
|
||||
@@ -1151,6 +1186,39 @@ mod tests {
|
||||
assert_eq!(format_uptime(90_061), "1d 1h");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pic_locked_error_columns_render() {
|
||||
// PIC (best-effort): known -> PIC/noPIC, unknown -> "?".
|
||||
let pic = MinerRow { pic_present: Some(true), ..Default::default() };
|
||||
let nopic = MinerRow { pic_present: Some(false), ..Default::default() };
|
||||
let pic_unknown = MinerRow { pic_present: None, ..Default::default() };
|
||||
assert_eq!(Column::Pic.cell(&pic), "PIC");
|
||||
assert_eq!(Column::Pic.cell(&nopic), "noPIC");
|
||||
assert_eq!(Column::Pic.cell(&pic_unknown), "?");
|
||||
|
||||
// Access column.
|
||||
let locked = MinerRow { write_locked: Some(true), ..Default::default() };
|
||||
let unlocked = MinerRow { write_locked: Some(false), ..Default::default() };
|
||||
assert_eq!(Column::Locked.cell(&locked), "locked");
|
||||
assert_eq!(Column::Locked.cell(&unlocked), "unlocked");
|
||||
assert_eq!(Column::Locked.cell(&MinerRow::default()), "?");
|
||||
|
||||
// Error column: blank / single message / count.
|
||||
let none = MinerRow { errors: vec![], ..Default::default() };
|
||||
let one = MinerRow { errors: vec!["[Error] boom".into()], ..Default::default() };
|
||||
let many = MinerRow { errors: vec!["a".into(), "b".into(), "c".into()], ..Default::default() };
|
||||
assert_eq!(Column::Error.cell(&none), "");
|
||||
assert_eq!(Column::Error.cell(&one), "[Error] boom");
|
||||
assert_eq!(Column::Error.cell(&many), "3 errors");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn caps_any_control() {
|
||||
assert!(!MinerCaps::default().any_control(), "no caps -> view-only");
|
||||
assert!(MinerCaps { restart: true, ..Default::default() }.any_control());
|
||||
assert!(MinerCaps { firmware_flash: true, ..Default::default() }.any_control());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ip_column_sorts_numerically() {
|
||||
// A plain string sort puts "10.255.1.10" before "10.255.1.2"; the IP
|
||||
@@ -1448,7 +1516,7 @@ mod tests {
|
||||
total_chips: Some(210),
|
||||
..Default::default()
|
||||
};
|
||||
assert_eq!(Column::Hashrate.cell(&actual_only), "60.0 TH/s", "only actual -> bare actual");
|
||||
assert_eq!(Column::Hashrate.cell(&actual_only), "60.0T", "only actual -> bare actual");
|
||||
assert_eq!(Column::Hashboards.cell(&actual_only), "3");
|
||||
assert_eq!(Column::TotalChips.cell(&actual_only), "210");
|
||||
|
||||
@@ -1458,7 +1526,7 @@ mod tests {
|
||||
expected_chips: Some(228),
|
||||
..Default::default()
|
||||
};
|
||||
assert_eq!(Column::Hashrate.cell(&expected_only), "- / 200 TH/s", "only expected -> '- / <expected>'");
|
||||
assert_eq!(Column::Hashrate.cell(&expected_only), "-/200T", "only expected -> '-/<expected>'");
|
||||
assert_eq!(Column::Hashboards.cell(&expected_only), "- / 3");
|
||||
assert_eq!(Column::TotalChips.cell(&expected_only), "- / 228");
|
||||
|
||||
@@ -1471,7 +1539,7 @@ mod tests {
|
||||
expected_chips: Some(228),
|
||||
..Default::default()
|
||||
};
|
||||
assert_eq!(Column::Hashrate.cell(&both), "60.0 TH/s / 200 TH/s", "both known -> '<actual> / <expected>'");
|
||||
assert_eq!(Column::Hashrate.cell(&both), "60.0T/200T", "both known -> '<actual>/<expected>'");
|
||||
assert_eq!(Column::Hashboards.cell(&both), "3 / 3");
|
||||
assert_eq!(Column::TotalChips.cell(&both), "190 / 228");
|
||||
}
|
||||
@@ -1538,18 +1606,10 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn status_offline_and_paused() {
|
||||
let offline = MinerRow::offline("10.1.2.3".into());
|
||||
assert_eq!(offline.status(), "offline");
|
||||
assert!(offline.offline);
|
||||
assert_eq!(offline.ip, "10.1.2.3");
|
||||
assert_eq!(offline.hashrate_ths, 0.0, "offline row is otherwise blank");
|
||||
|
||||
// A plain default row is online (offline: false), so a struct-update
|
||||
// literal that forgets to say so is reachable, not silently offline.
|
||||
let default_is_online = MinerRow { ..Default::default() };
|
||||
assert!(!default_is_online.offline, "Default row must be online");
|
||||
assert_eq!(default_is_online.status(), "not hashing");
|
||||
fn status_precedence() {
|
||||
// A plain default row is a reachable, non-mining miner.
|
||||
let default_row = MinerRow { ..Default::default() };
|
||||
assert_eq!(default_row.status(), "not hashing");
|
||||
|
||||
let paused = MinerRow { paused: true, ..Default::default() };
|
||||
assert_eq!(paused.status(), "paused");
|
||||
@@ -1557,17 +1617,13 @@ mod tests {
|
||||
let hashing = MinerRow { is_mining: true, ..Default::default() };
|
||||
assert_eq!(hashing.status(), "hashing");
|
||||
|
||||
let not_hashing = MinerRow { ..Default::default() };
|
||||
assert_eq!(not_hashing.status(), "not hashing");
|
||||
|
||||
// offline outranks slow/paused/hashing in the precedence order.
|
||||
let offline_but_flagged =
|
||||
MinerRow { offline: true, slow: true, paused: true, is_mining: true, ..Default::default() };
|
||||
assert_eq!(offline_but_flagged.status(), "offline");
|
||||
|
||||
// slow outranks paused (and hashing).
|
||||
let slow_and_paused = MinerRow { slow: true, paused: true, ..Default::default() };
|
||||
let slow_and_paused = MinerRow { slow: true, paused: true, is_mining: true, ..Default::default() };
|
||||
assert_eq!(slow_and_paused.status(), "slow");
|
||||
|
||||
// paused outranks hashing.
|
||||
let paused_but_mining = MinerRow { paused: true, is_mining: true, ..Default::default() };
|
||||
assert_eq!(paused_but_mining.status(), "paused");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1581,21 +1637,20 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn kpis_bucket_by_status_not_raw_flags() {
|
||||
// An offline row that also carries stale slow/paused/mining flags must
|
||||
// count as not_hashing (matching status() == "offline"), never as slow
|
||||
// or paused -- i.e. compute_kpis and status() can't diverge.
|
||||
// compute_kpis must bucket by status()'s precedence, so a row's KPI
|
||||
// bucket can never disagree with its status text.
|
||||
let rows = vec![
|
||||
MinerRow { offline: true, slow: true, paused: true, is_mining: true, ..Default::default() },
|
||||
MinerRow { slow: true, ..Default::default() },
|
||||
MinerRow { paused: true, ..Default::default() },
|
||||
MinerRow { is_mining: true, ..Default::default() },
|
||||
MinerRow { slow: true, paused: true, is_mining: true, ..Default::default() }, // slow wins
|
||||
MinerRow { paused: true, is_mining: true, ..Default::default() }, // paused over hashing
|
||||
MinerRow { is_mining: true, ..Default::default() }, // hashing
|
||||
MinerRow { ..Default::default() }, // not hashing
|
||||
];
|
||||
let idx: Vec<usize> = (0..rows.len()).collect();
|
||||
let k = compute_kpis(&rows, &idx);
|
||||
assert_eq!(k.slow, 1, "only the genuinely-slow row");
|
||||
assert_eq!(k.paused, 1, "only the genuinely-paused row");
|
||||
assert_eq!(k.slow, 1);
|
||||
assert_eq!(k.paused, 1, "paused outranks the mining flag");
|
||||
assert_eq!(k.hashing, 1);
|
||||
assert_eq!(k.not_hashing, 1, "the offline-but-flagged row folds here, not into slow");
|
||||
assert_eq!(k.not_hashing, 1);
|
||||
assert_eq!(k.total, 4);
|
||||
}
|
||||
|
||||
|
||||
+132
-36
@@ -120,6 +120,32 @@ pub fn parse_line(line: &str) -> Result<Vec<Ipv4Addr>, String> {
|
||||
}
|
||||
return Ok((0..count).map(|i| Ipv4Addr::from(base + i as u32)).collect());
|
||||
}
|
||||
// Per-octet ranges: each of the four octets may be a single number or an
|
||||
// inclusive `a-b` range, e.g. "10.1-9.1.1-255" scans the cartesian product
|
||||
// (the 9 /24s: 10.1.1.x .. 10.9.1.x). This also subsumes a plain single
|
||||
// address and a bare last-octet range like "10.253.1.3-234".
|
||||
let parts: Vec<&str> = line.split('.').collect();
|
||||
if parts.len() == 4 && parts.iter().all(|p| is_octet_spec(p)) {
|
||||
let r: Vec<(u8, u8)> =
|
||||
parts.iter().map(|p| parse_octet_spec(p)).collect::<Result<_, String>>()?;
|
||||
let count: u64 = r.iter().map(|(lo, hi)| (*hi as u64 - *lo as u64 + 1)).product();
|
||||
if count > MAX_ADDRS {
|
||||
return Err(format!("range too large (> {MAX_ADDRS} addresses): {line}"));
|
||||
}
|
||||
let mut out = Vec::with_capacity(count as usize);
|
||||
for a in r[0].0..=r[0].1 {
|
||||
for b in r[1].0..=r[1].1 {
|
||||
for c in r[2].0..=r[2].1 {
|
||||
for d in r[3].0..=r[3].1 {
|
||||
out.push(Ipv4Addr::new(a, b, c, d));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return Ok(out);
|
||||
}
|
||||
// Full A-B range across two dotted addresses (e.g. "10.0.0.1-10.7.255.254"),
|
||||
// which the per-octet form above cannot express.
|
||||
if let Some((start_s, end_s)) = line.split_once('-') {
|
||||
let start: Ipv4Addr = start_s
|
||||
.trim()
|
||||
@@ -148,6 +174,27 @@ pub fn parse_line(line: &str) -> Result<Vec<Ipv4Addr>, String> {
|
||||
Ok(vec![addr])
|
||||
}
|
||||
|
||||
/// Parse one octet spec: `"n"` -> `(n, n)`, or `"a-b"` -> `(a, b)` inclusive
|
||||
/// (rejecting `a > b`). Used by the per-octet range form in `parse_line`.
|
||||
fn parse_octet_spec(s: &str) -> Result<(u8, u8), String> {
|
||||
let s = s.trim();
|
||||
if let Some((lo, hi)) = s.split_once('-') {
|
||||
let lo: u8 = lo.trim().parse().map_err(|_| format!("bad octet range: {s}"))?;
|
||||
let hi: u8 = hi.trim().parse().map_err(|_| format!("bad octet range: {s}"))?;
|
||||
if lo > hi {
|
||||
return Err(format!("octet range start after end: {s}"));
|
||||
}
|
||||
Ok((lo, hi))
|
||||
} else {
|
||||
let n: u8 = s.parse().map_err(|_| format!("bad octet: {s}"))?;
|
||||
Ok((n, n))
|
||||
}
|
||||
}
|
||||
|
||||
fn is_octet_spec(s: &str) -> bool {
|
||||
parse_octet_spec(s).is_ok()
|
||||
}
|
||||
|
||||
fn prefix_mask(prefix: u8) -> u32 {
|
||||
if prefix == 0 {
|
||||
0
|
||||
@@ -258,13 +305,8 @@ pub fn start_scan(lines: Vec<String>) -> ScanHandle {
|
||||
let err_tx = tx.clone();
|
||||
let res = std::thread::Builder::new().name("fake-scan".into()).spawn(move || {
|
||||
let rows = crate::fixtures::bench_fleet();
|
||||
// A synthetic unreachable host, so the offline-recognition path
|
||||
// (a probed address with no miner behind it) is exercised even
|
||||
// when running fully offline against fixtures.
|
||||
let offline_ip = "10.255.1.254".to_string();
|
||||
let mut targets: HashSet<String> = rows.iter().map(|r| r.ip.clone()).collect();
|
||||
targets.insert(offline_ip.clone());
|
||||
let total = rows.len() + 1;
|
||||
let targets: HashSet<String> = rows.iter().map(|r| r.ip.clone()).collect();
|
||||
let total = rows.len();
|
||||
let _ = tx.send(ScanMsg::Started { total, targets });
|
||||
for (i, row) in rows.into_iter().enumerate() {
|
||||
if thread_cancel.load(Ordering::Relaxed) {
|
||||
@@ -275,13 +317,6 @@ pub fn start_scan(lines: Vec<String>) -> ScanHandle {
|
||||
}
|
||||
let _ = tx.send(ScanMsg::Progress { done: i + 1, total, ip: String::new() });
|
||||
}
|
||||
if thread_cancel.load(Ordering::Relaxed) {
|
||||
return;
|
||||
}
|
||||
if tx.send(ScanMsg::Row(MinerRow::offline(offline_ip))).is_err() {
|
||||
return;
|
||||
}
|
||||
let _ = tx.send(ScanMsg::Progress { done: total, total, ip: String::new() });
|
||||
let _ = tx.send(ScanMsg::Done("fixtures".into()));
|
||||
});
|
||||
if let Err(e) = res {
|
||||
@@ -338,15 +373,16 @@ pub fn start_scan(lines: Vec<String>) -> ScanHandle {
|
||||
return; // Stop / re-scan requested
|
||||
}
|
||||
done += 1;
|
||||
// Always report a row, even for an address that answered no
|
||||
// miner protocol: `MinerRow::offline` keeps it visible (and
|
||||
// distinct from a row the scan simply never reached).
|
||||
let row = match miner {
|
||||
Some(m) => to_row(&*m).await,
|
||||
None => MinerRow::offline(ip.to_string()),
|
||||
};
|
||||
if tx.send(ScanMsg::Row(row)).is_err() {
|
||||
return; // UI gone
|
||||
// Only surface a row for an address that actually has a miner
|
||||
// behind it. A non-responding address is not shown -- we never
|
||||
// fabricate a phantom "offline" row for an empty IP; a miner is
|
||||
// reported as "not hashing" only when it responds and we can see
|
||||
// it is not mining.
|
||||
if let Some(m) = miner {
|
||||
let row = to_row(&*m).await;
|
||||
if tx.send(ScanMsg::Row(row)).is_err() {
|
||||
return; // UI gone
|
||||
}
|
||||
}
|
||||
if done % step == 0 || done == total {
|
||||
let _ = tx.send(ScanMsg::Progress { done, total, ip: ip.to_string() });
|
||||
@@ -361,6 +397,34 @@ pub fn start_scan(lines: Vec<String>) -> ScanHandle {
|
||||
ScanHandle { rx, cancel }
|
||||
}
|
||||
|
||||
/// Flatten a miner's structured messages into display lines, most severe first
|
||||
/// ("[Error] text (component)"), for the Errors column + hover tooltip.
|
||||
fn summarize_messages(messages: &[asic_rs::core::data::message::MinerMessage]) -> Vec<String> {
|
||||
use asic_rs::core::data::message::MessageSeverity;
|
||||
let rank = |s: &MessageSeverity| match s {
|
||||
MessageSeverity::Error => 0u8,
|
||||
MessageSeverity::Warning => 1,
|
||||
MessageSeverity::Info => 2,
|
||||
};
|
||||
let mut ranked: Vec<(u8, String)> = messages
|
||||
.iter()
|
||||
.map(|m| {
|
||||
let sev = match m.severity {
|
||||
MessageSeverity::Error => "Error",
|
||||
MessageSeverity::Warning => "Warning",
|
||||
MessageSeverity::Info => "Info",
|
||||
};
|
||||
let line = match &m.component {
|
||||
Some(c) => format!("[{sev}] {} ({c})", m.message),
|
||||
None => format!("[{sev}] {}", m.message),
|
||||
};
|
||||
(rank(&m.severity), line)
|
||||
})
|
||||
.collect();
|
||||
ranked.sort_by_key(|(r, _)| *r);
|
||||
ranked.into_iter().map(|(_, s)| s).collect()
|
||||
}
|
||||
|
||||
async fn to_row(miner: &dyn Miner) -> MinerRow {
|
||||
let data = miner.get_data().await;
|
||||
let hashrate_ths = data
|
||||
@@ -448,12 +512,22 @@ async fn to_row(miner: &dyn Miner) -> MinerRow {
|
||||
tuning: miner.supports_set_tuning_percent(),
|
||||
firmware_flash: miner.supports_upgrade_firmware(),
|
||||
};
|
||||
// PIC vs noPIC is not reported over the network by asic-rs; best-effort
|
||||
// heuristic from the model string, else unknown (true detection needs an
|
||||
// on-board SSH/I2C probe -- a separate feature).
|
||||
let pic_present = if model.to_lowercase().contains("nopic") { Some(false) } else { None };
|
||||
// Access: locked/view-only when the miner exposes no writable control at
|
||||
// all, otherwise unlocked. Inferred from capabilities (asic-rs has no direct
|
||||
// lock-state field).
|
||||
let write_locked = Some(!caps.any_control());
|
||||
let errors = summarize_messages(&data.messages);
|
||||
MinerRow {
|
||||
ip: data.ip.to_string(),
|
||||
selected: false,
|
||||
// A miner that responded to the scan is reachable.
|
||||
offline: false,
|
||||
caps,
|
||||
pic_present,
|
||||
write_locked,
|
||||
errors,
|
||||
model,
|
||||
mac: data.mac.map(|m| m.to_string()).unwrap_or_default(),
|
||||
hostname: data.hostname.clone().unwrap_or_default(),
|
||||
@@ -507,8 +581,8 @@ impl ConfigAction {
|
||||
/// Short label for status text and summaries.
|
||||
pub fn label(&self) -> String {
|
||||
match self {
|
||||
ConfigAction::FaultLight(true) => "fault light on".into(),
|
||||
ConfigAction::FaultLight(false) => "fault light off".into(),
|
||||
ConfigAction::FaultLight(true) => "flash lights on".into(),
|
||||
ConfigAction::FaultLight(false) => "flash lights off".into(),
|
||||
ConfigAction::Restart => "restart".into(),
|
||||
ConfigAction::Pause => "pause".into(),
|
||||
ConfigAction::Resume => "resume".into(),
|
||||
@@ -864,6 +938,31 @@ mod tests {
|
||||
assert_eq!(*ips.last().unwrap(), Ipv4Addr::new(10, 253, 1, 234));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_per_octet_ranges() {
|
||||
// The user's example: 9 /24s (octet2 1..9), each with .1.1-255.
|
||||
let ips = parse_line("10.1-9.1.1-255").unwrap();
|
||||
assert_eq!(ips.len(), 9 * 255, "9 /24 ranges of 255 addresses each");
|
||||
assert_eq!(ips[0], Ipv4Addr::new(10, 1, 1, 1), "ascending, first combo");
|
||||
assert_eq!(*ips.last().unwrap(), Ipv4Addr::new(10, 9, 1, 255));
|
||||
// Ordered by octet: the second address is .1.1.2, the 256th is .2.1.1.
|
||||
assert_eq!(ips[1], Ipv4Addr::new(10, 1, 1, 2));
|
||||
assert_eq!(ips[255], Ipv4Addr::new(10, 2, 1, 1));
|
||||
|
||||
// Ranges in more than one octet.
|
||||
let ips = parse_line("192.168.0-1.10-12").unwrap();
|
||||
assert_eq!(ips.len(), 2 * 3);
|
||||
assert_eq!(ips[0], Ipv4Addr::new(192, 168, 0, 10));
|
||||
assert_eq!(*ips.last().unwrap(), Ipv4Addr::new(192, 168, 1, 12));
|
||||
|
||||
// A single address still works through the per-octet path.
|
||||
assert_eq!(parse_line("10.0.0.5").unwrap(), vec![Ipv4Addr::new(10, 0, 0, 5)]);
|
||||
// Reversed octet range is an error.
|
||||
assert!(parse_line("10.9-1.1.1").is_err());
|
||||
// Out-of-range octet falls through and is reported.
|
||||
assert!(parse_line("10.1.1.999").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_cross_octet_range() {
|
||||
let ips = parse_line("10.253.1.250-10.253.2.5").unwrap();
|
||||
@@ -1080,8 +1179,8 @@ mod tests {
|
||||
let deadline = Duration::from_secs(5);
|
||||
std::env::set_var(FAKE_SCAN_ENV, "1");
|
||||
|
||||
// start_scan: every probed IP produces a Row, including a synthetic
|
||||
// unreachable host that must come back as an offline row.
|
||||
// start_scan (fake): streams exactly the bench-fleet fixtures, one Row
|
||||
// per fixture, and no fabricated rows for empty addresses.
|
||||
{
|
||||
let h = start_scan(vec!["10.255.1.0/30".into()]);
|
||||
let mut rows = Vec::new();
|
||||
@@ -1096,13 +1195,10 @@ mod tests {
|
||||
Err(RecvTimeoutError::Disconnected) => break,
|
||||
}
|
||||
}
|
||||
assert_eq!(rows.len(), total, "one Row per probed target, incl. the offline host");
|
||||
let offline = rows
|
||||
.iter()
|
||||
.find(|r| r.ip == "10.255.1.254")
|
||||
.expect("synthetic offline row must be emitted");
|
||||
assert!(offline.offline);
|
||||
assert_eq!(offline.status(), "offline");
|
||||
let fleet = crate::fixtures::bench_fleet();
|
||||
assert_eq!(rows.len(), fleet.len(), "one Row per fixture, no phantom offline rows");
|
||||
assert_eq!(total, fleet.len());
|
||||
assert!(rows.iter().all(|r| r.status() != "offline"), "no 'offline' status exists");
|
||||
}
|
||||
|
||||
// start_refresh: a known fixture IP re-reads as a Row, an unknown IP is
|
||||
|
||||
+135
-65
@@ -100,10 +100,11 @@ fn tint_toward(base: (u8, u8, u8), target: (u8, u8, u8), f: f64) -> (u8, u8, u8)
|
||||
}
|
||||
|
||||
/// Colour for a combined actual/expected ratio (Hashrate/Hashboards/
|
||||
/// TotalChips): red at 0, amber at 0.5, green at 1.0+, clamped and
|
||||
/// interpolated linearly between those stops.
|
||||
/// TotalChips): full red at 50% (or below), amber at 75%, green at 100%+,
|
||||
/// interpolated linearly -- calibrated so a miner running at half its expected
|
||||
/// output reads as clearly bad, and 100% reads green.
|
||||
fn ratio_color(pal: &Palette, ratio: f64) -> (u8, u8, u8) {
|
||||
let t = ratio.clamp(0.0, 1.0);
|
||||
let t = ((ratio - 0.5) / 0.5).clamp(0.0, 1.0);
|
||||
if t <= 0.5 {
|
||||
tint_toward(pal.red, pal.amber, t / 0.5)
|
||||
} else {
|
||||
@@ -111,6 +112,12 @@ fn ratio_color(pal: &Palette, ratio: f64) -> (u8, u8, u8) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Colour for a chip-temperature reading: cool blue at/below 40 C fading to hot
|
||||
/// red at/above 90 C, so a hot miner reads red at a glance.
|
||||
fn temp_color(pal: &Palette, temp_c: f64) -> (u8, u8, u8) {
|
||||
tint_toward(pal.accent, pal.red, ((temp_c - 40.0) / 50.0).clamp(0.0, 1.0))
|
||||
}
|
||||
|
||||
/// Colour for one cooling-fan RPM: muted grey (stopped/unknown) fading to
|
||||
/// accent blue as the RPM approaches 6000 (comfortably above a healthy fan's
|
||||
/// typical ceiling, so a spinning fan reads as a clear, saturated blue).
|
||||
@@ -118,24 +125,46 @@ fn fan_color(pal: &Palette, rpm: f64) -> (u8, u8, u8) {
|
||||
tint_toward(pal.label, pal.accent, (rpm / 6000.0).clamp(0.0, 1.0))
|
||||
}
|
||||
|
||||
/// Build the segment-encoded cell text for a combined actual/expected column
|
||||
/// (Hashrate/Hashboards/TotalChips): when both halves are known (`plain`
|
||||
/// contains " / " and a ratio was computable), colour just the actual half by
|
||||
/// how it compares to expected and leave the separator + expected half in the
|
||||
/// default colour. Anything else (blank, actual-only, or no ratio) falls back
|
||||
/// to one plain, uncoloured segment so the encoding always round-trips to the
|
||||
/// same text `decode_segments_plain` would read back.
|
||||
fn encode_combined_cell(pal: &Palette, plain: &str, ratio: Option<f64>) -> String {
|
||||
match (plain.split_once(" / "), ratio) {
|
||||
(Some((actual, expected)), Some(ratio)) => encode_segments(&[
|
||||
(Some(ratio_color(pal, ratio)), actual.to_string()),
|
||||
(None, " / ".to_string()),
|
||||
(None, expected.to_string()),
|
||||
/// Build the segment-encoded cell for a combined actual/expected column
|
||||
/// (Hashrate/Hashboards/TotalChips) from its already-formatted parts: the
|
||||
/// actual half is coloured by `ratio` when both halves are known, the separator
|
||||
/// `sep` and the expected half stay the default text colour, and an unknown
|
||||
/// actual shows "-". Round-trips (via decode_segments_plain) to the same plain
|
||||
/// text the model's combined cell produces.
|
||||
fn encode_combined_cell(
|
||||
pal: &Palette,
|
||||
actual: Option<String>,
|
||||
expected: Option<String>,
|
||||
sep: &str,
|
||||
ratio: Option<f64>,
|
||||
) -> String {
|
||||
match (actual, expected) {
|
||||
(None, None) => encode_segments(&[(None, String::new())]),
|
||||
(Some(a), None) => encode_segments(&[(None, a)]),
|
||||
(a, Some(e)) => encode_segments(&[
|
||||
(ratio.map(|r| ratio_color(pal, r)), a.unwrap_or_else(|| "-".to_string())),
|
||||
(None, sep.to_string()),
|
||||
(None, e),
|
||||
]),
|
||||
_ => encode_segments(&[(None, plain.to_string())]),
|
||||
}
|
||||
}
|
||||
|
||||
/// Segment-encoded Chip-temp cell: the reading coloured on the blue-to-red
|
||||
/// temperature scale (blank cell stays blank).
|
||||
fn encode_temp_cell(pal: &Palette, plain: &str, temp_c: f64) -> String {
|
||||
if plain.is_empty() {
|
||||
encode_segments(&[(None, String::new())])
|
||||
} else {
|
||||
encode_segments(&[(Some(temp_color(pal, temp_c)), plain.to_string())])
|
||||
}
|
||||
}
|
||||
|
||||
/// Segment-encoded single-colour cell (Access/Errors): `plain` in `color`, or
|
||||
/// the default text colour when `color` is None.
|
||||
fn encode_flag_cell(plain: &str, color: Option<(u8, u8, u8)>) -> String {
|
||||
encode_segments(&[(color, plain.to_string())])
|
||||
}
|
||||
|
||||
/// Build the segment-encoded cell text for the Cooling column: each fan's RPM
|
||||
/// gets its own grey-to-blue colour by speed, and the "/" separators between
|
||||
/// them stay in the default text colour.
|
||||
@@ -199,7 +228,7 @@ fn kind_color(pal: &Palette, k: ColorKind) -> (u8, u8, u8) {
|
||||
/// what each status "looks like".
|
||||
fn status_kind_color(pal: &Palette, status: &str) -> (u8, u8, u8) {
|
||||
match status {
|
||||
"offline" | "not hashing" => pal.red,
|
||||
"not hashing" => pal.red,
|
||||
"paused" => pal.accent,
|
||||
"slow" => pal.amber,
|
||||
"hashing" => pal.green,
|
||||
@@ -208,8 +237,8 @@ fn status_kind_color(pal: &Palette, status: &str) -> (u8, u8, u8) {
|
||||
}
|
||||
|
||||
/// A miner row's text colour, by status: green = hashing, amber = slow, blue =
|
||||
/// paused, red = offline/not hashing. This both conveys status and separates
|
||||
/// rows visually (GTK's native zebra/alt-row support is unreliable and fights
|
||||
/// paused, red = not hashing. This both conveys status and separates rows
|
||||
/// visually (GTK's native zebra/alt-row support is unreliable and fights
|
||||
/// selection).
|
||||
fn status_color(pal: &Palette, r: &MinerRow) -> (u8, u8, u8) {
|
||||
status_kind_color(pal, r.status())
|
||||
@@ -343,6 +372,8 @@ pub fn build(frame: Widget) -> App {
|
||||
let vc = kind_color(&pal, kind);
|
||||
let card = Widget::panel(panel);
|
||||
card.set_bg(pal.card_bg.0, pal.card_bg.1, pal.card_bg.2);
|
||||
// Uniform size so every KPI box is identical regardless of its content.
|
||||
card.set_min_size(128, 62);
|
||||
let cs = Widget::box_sizer(true);
|
||||
let value = Widget::static_text(card, "0");
|
||||
value.set_font_size(19);
|
||||
@@ -353,10 +384,21 @@ pub fn build(frame: Widget) -> App {
|
||||
lbl.set_font_size(9);
|
||||
lbl.set_fg(pal.label.0, pal.label.1, pal.label.2);
|
||||
lbl.set_bg(pal.card_bg.0, pal.card_bg.1, pal.card_bg.2);
|
||||
cs.add(value, 0, sf::BORDER_LEFT | sf::BORDER_TOP | sf::BORDER_RIGHT, 12);
|
||||
cs.add(lbl, 0, sf::BORDER_LEFT | sf::BORDER_BOTTOM | sf::BORDER_RIGHT, 12);
|
||||
// Centre both texts horizontally: a stretch spacer on each side (no
|
||||
// ALIGN_CENTRE_HORIZONTAL flag exists in the bridge).
|
||||
let centre = |w: Widget| {
|
||||
let row = Widget::box_sizer(false);
|
||||
row.add_stretch(1);
|
||||
row.add(w, 0, sf::ALIGN_CENTRE_VERTICAL, 0);
|
||||
row.add_stretch(1);
|
||||
row
|
||||
};
|
||||
cs.add_stretch(1);
|
||||
cs.add_sizer(centre(value), 0, sf::EXPAND | sf::BORDER_LEFT | sf::BORDER_TOP | sf::BORDER_RIGHT, 8);
|
||||
cs.add_sizer(centre(lbl), 0, sf::EXPAND | sf::BORDER_LEFT | sf::BORDER_BOTTOM | sf::BORDER_RIGHT, 8);
|
||||
cs.add_stretch(1);
|
||||
cs.set_sizer_on(card);
|
||||
kpi_row.add(card, 1, sf::EXPAND | sf::BORDER_ALL, 4);
|
||||
kpi_row.add(card, 0, sf::BORDER_ALL, 4);
|
||||
kpi_cards.push((card, value, lbl, kind));
|
||||
(card, value)
|
||||
};
|
||||
@@ -521,7 +563,7 @@ impl App {
|
||||
Some((sc, false)) if sc == c => title.push_str(" v"),
|
||||
_ => {}
|
||||
}
|
||||
if matches!(c, Column::Hashrate | Column::Hashboards | Column::TotalChips | Column::Cooling) {
|
||||
if matches!(c, Column::Hashrate | Column::Hashboards | Column::TotalChips | Column::ChipTemp | Column::Cooling | Column::Locked | Column::Error) {
|
||||
// These columns show two-tone / multi-tone text (actual vs.
|
||||
// expected, or one colour per fan) via a custom renderer that
|
||||
// parses the segment-encoded cell value fill_rows writes.
|
||||
@@ -561,35 +603,54 @@ impl App {
|
||||
let r = &self.rows[ri];
|
||||
for (ci, c) in cols.iter().enumerate() {
|
||||
let encoded = match c {
|
||||
// Gate the ratio on the ACTUAL being known: an unknown actual
|
||||
// (hashrate 0.0 sentinel / None count) renders as "- / <expected>"
|
||||
// and must fall through to the plain, uncoloured segment rather
|
||||
// than paint the "-" solid red as if the miner were at 0%.
|
||||
// Combined columns are built from parts: the ratio is gated
|
||||
// on the ACTUAL being known, so an unknown actual renders as
|
||||
// "-/<expected>" in the default colour rather than a red 0%.
|
||||
Column::Hashrate => {
|
||||
let actual = format_hashrate_ths(r.hashrate_ths);
|
||||
let expected = format_hashrate_ths(r.expected_ths);
|
||||
let ratio = (r.hashrate_ths > 0.0)
|
||||
.then(|| actual_expected_ratio(r.hashrate_ths, r.expected_ths))
|
||||
.flatten();
|
||||
encode_combined_cell(&self.pal, &c.cell(r), ratio)
|
||||
encode_combined_cell(&self.pal, actual, expected, "/", ratio)
|
||||
}
|
||||
Column::Hashboards => {
|
||||
let actual = r.hashboards.map(|v| v.to_string());
|
||||
let expected = r.expected_hashboards.map(|v| v.to_string());
|
||||
let ratio = r.hashboards.and_then(|a| {
|
||||
actual_expected_ratio(
|
||||
a as f64,
|
||||
r.expected_hashboards.map(|v| v as f64).unwrap_or(0.0),
|
||||
)
|
||||
});
|
||||
encode_combined_cell(&self.pal, &c.cell(r), ratio)
|
||||
encode_combined_cell(&self.pal, actual, expected, " / ", ratio)
|
||||
}
|
||||
Column::TotalChips => {
|
||||
let actual = r.total_chips.map(|v| v.to_string());
|
||||
let expected = r.expected_chips.map(|v| v.to_string());
|
||||
let ratio = r.total_chips.and_then(|a| {
|
||||
actual_expected_ratio(
|
||||
a as f64,
|
||||
r.expected_chips.map(|v| v as f64).unwrap_or(0.0),
|
||||
)
|
||||
});
|
||||
encode_combined_cell(&self.pal, &c.cell(r), ratio)
|
||||
encode_combined_cell(&self.pal, actual, expected, " / ", ratio)
|
||||
}
|
||||
Column::ChipTemp => encode_temp_cell(&self.pal, &c.cell(r), r.chip_temp_c),
|
||||
Column::Cooling => encode_cooling_cell(&self.pal, &r.fan_rpms),
|
||||
Column::Locked => {
|
||||
// green = unlocked/writable, red = locked/view-only.
|
||||
let color = match r.write_locked {
|
||||
Some(true) => Some(self.pal.red),
|
||||
Some(false) => Some(self.pal.green),
|
||||
None => None,
|
||||
};
|
||||
encode_flag_cell(&c.cell(r), color)
|
||||
}
|
||||
Column::Error => {
|
||||
let color = (!r.errors.is_empty()).then_some(self.pal.red);
|
||||
encode_flag_cell(&c.cell(r), color)
|
||||
}
|
||||
_ => continue,
|
||||
};
|
||||
t.dvlc_set_cell(disp, ci, &encoded);
|
||||
@@ -712,8 +773,8 @@ impl App {
|
||||
if !caps.is_empty() {
|
||||
let sfx = if n == 1 { String::new() } else { format!(" ({n})") };
|
||||
if caps.fault_light {
|
||||
menu.menu_append(ID_CTX_LIGHT_ON, &format!("Fault light on{sfx}"));
|
||||
menu.menu_append(ID_CTX_LIGHT_OFF, &format!("Fault light off{sfx}"));
|
||||
menu.menu_append(ID_CTX_LIGHT_ON, &format!("Flash lights on{sfx}"));
|
||||
menu.menu_append(ID_CTX_LIGHT_OFF, &format!("Flash lights off{sfx}"));
|
||||
}
|
||||
if caps.pause {
|
||||
menu.menu_append(ID_CTX_PAUSE, &format!("Pause mining{sfx}"));
|
||||
@@ -837,7 +898,7 @@ impl App {
|
||||
Err(e) => wx_rs::set_status_text(&format!("failed to read firmware image: {e}")),
|
||||
}
|
||||
}
|
||||
// Fault light is harmless -> apply immediately.
|
||||
// Flashing the identify light is harmless -> apply immediately.
|
||||
ID_CTX_LIGHT_ON => self.start_action(self.selected_ip_list(), scan::ConfigAction::FaultLight(true)),
|
||||
ID_CTX_LIGHT_OFF => self.start_action(self.selected_ip_list(), scan::ConfigAction::FaultLight(false)),
|
||||
// Disruptive to running hardware -> confirm first.
|
||||
@@ -1979,10 +2040,10 @@ impl App {
|
||||
// 1. KPI values: independent, hand-computed from the fixtures. The
|
||||
// labels are static; the value widgets carry the numbers.
|
||||
let want_kpis = [
|
||||
(self.kpi_total, "Total", "10"),
|
||||
(self.kpi_total, "Total", "9"),
|
||||
(self.kpi_hashing, "Hashing", "6"),
|
||||
(self.kpi_slow, "Slow", "1"),
|
||||
(self.kpi_not, "Not hashing", "2"),
|
||||
(self.kpi_not, "Not hashing", "1"),
|
||||
(self.kpi_paused, "Paused", "1"),
|
||||
(self.kpi_hashrate, "Hashrate", "685 TH/s"),
|
||||
(self.kpi_power, "Est. power", "21.3 kW"),
|
||||
@@ -2000,8 +2061,8 @@ impl App {
|
||||
|
||||
// 2. Row count in the store matches the (unfiltered) fixture count.
|
||||
let want_rows = self.view_idx.len();
|
||||
check("table row count == 10",
|
||||
t.dvlc_row_count() == 10 && want_rows == 10,
|
||||
check("table row count == 9",
|
||||
t.dvlc_row_count() == 9 && want_rows == 9,
|
||||
format!("store={}, view={}", t.dvlc_row_count(), want_rows));
|
||||
|
||||
// 3. Every store cell equals what the model produced for that row/col
|
||||
@@ -2014,7 +2075,7 @@ impl App {
|
||||
for (j, c) in cols.iter().enumerate() {
|
||||
let want = c.cell(r);
|
||||
let raw = t.dvlc_get_cell(disp_row, j).unwrap_or_default();
|
||||
let got = if matches!(c, Column::Hashrate | Column::Hashboards | Column::TotalChips | Column::Cooling) {
|
||||
let got = if matches!(c, Column::Hashrate | Column::Hashboards | Column::TotalChips | Column::ChipTemp | Column::Cooling | Column::Locked | Column::Error) {
|
||||
decode_segments_plain(&raw)
|
||||
} else {
|
||||
raw
|
||||
@@ -2048,8 +2109,8 @@ impl App {
|
||||
if let (Some(row), Some(_)) = (find("10.255.1.149"), status_col) {
|
||||
check("S21 Pro (.149) is slow", cell(row, status_col) == "slow",
|
||||
format!("status=\"{}\"", cell(row, status_col)));
|
||||
check("S21 Pro (.149) hashrate == 60.0 TH/s / 200 TH/s",
|
||||
cell(row, hr_col) == "60.0 TH/s / 200 TH/s",
|
||||
check("S21 Pro (.149) hashrate == 60.0T/200T",
|
||||
cell(row, hr_col) == "60.0T/200T",
|
||||
format!("hashrate=\"{}\"", cell(row, hr_col)));
|
||||
} else {
|
||||
check("S21 Pro (.149) present", false, "row not found".into());
|
||||
@@ -2068,16 +2129,6 @@ impl App {
|
||||
} else {
|
||||
check("WardenOS-dev (.115) present", false, "row not found".into());
|
||||
}
|
||||
// The synthetic unreachable row must classify as offline with a blank
|
||||
// hashrate (round-6 offline-recognition path).
|
||||
if let Some(row) = find("10.255.1.199") {
|
||||
check("offline row (.199) is offline", cell(row, status_col) == "offline",
|
||||
format!("status=\"{}\"", cell(row, status_col)));
|
||||
check("offline row (.199) blank hashrate", cell(row, hr_col).is_empty(),
|
||||
format!("hashrate=\"{}\"", cell(row, hr_col)));
|
||||
} else {
|
||||
check("offline row (.199) present", false, "row not found".into());
|
||||
}
|
||||
check("IP is the first column", ip_col == Some(0),
|
||||
format!("ip col index = {ip_col:?}"));
|
||||
// default view is IP-ascending -- compare against the model's own
|
||||
@@ -2177,13 +2228,24 @@ mod tests {
|
||||
#[test]
|
||||
fn ratio_color_stops_and_clamping() {
|
||||
let p = test_pal();
|
||||
assert_eq!(ratio_color(&p, 0.0), p.red, "0% -> red");
|
||||
assert_eq!(ratio_color(&p, 0.5), p.amber, "50% -> amber");
|
||||
// Scale bottoms out at 50%: red at/below 0.5, amber at 0.75, green at 1.0+.
|
||||
assert_eq!(ratio_color(&p, 0.5), p.red, "50% -> full red");
|
||||
assert_eq!(ratio_color(&p, 0.25), p.red, "below 50% -> still full red");
|
||||
assert_eq!(ratio_color(&p, 0.75), p.amber, "75% -> amber");
|
||||
assert_eq!(ratio_color(&p, 1.0), p.green, "100% -> green");
|
||||
assert_eq!(ratio_color(&p, -3.0), p.red, "clamped below 0");
|
||||
assert_eq!(ratio_color(&p, 9.0), p.green, "clamped above 1 (overperforming -> green)");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn temp_color_blue_to_red_scale() {
|
||||
let p = test_pal();
|
||||
assert_eq!(temp_color(&p, 40.0), p.accent, "cool -> blue");
|
||||
assert_eq!(temp_color(&p, 20.0), p.accent, "clamped below 40 C");
|
||||
assert_eq!(temp_color(&p, 90.0), p.red, "hot -> red");
|
||||
assert_eq!(temp_color(&p, 110.0), p.red, "clamped above 90 C");
|
||||
assert_eq!(temp_color(&p, 65.0), tint_toward(p.accent, p.red, 0.5), "midpoint blend");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fan_color_grey_to_blue_scale() {
|
||||
let p = test_pal();
|
||||
@@ -2196,22 +2258,30 @@ mod tests {
|
||||
#[test]
|
||||
fn combined_cell_unknown_actual_is_not_coloured_red() {
|
||||
let p = test_pal();
|
||||
// Unknown actual ("-") with no ratio must take the plain, uncoloured
|
||||
// branch -- not paint the "-" solid red as a 0% miner would be.
|
||||
let unknown = encode_combined_cell(&p, "- / 200 TH/s", None);
|
||||
assert_eq!(unknown, encode_segments(&[(None, "- / 200 TH/s".to_string())]));
|
||||
assert_eq!(decode_segments_plain(&unknown), "- / 200 TH/s");
|
||||
// Unknown actual with a known expected shows "-" in the DEFAULT colour
|
||||
// (no ratio) -- not a red 0%. Hashrate uses a no-space "/" separator.
|
||||
let unknown = encode_combined_cell(&p, None, Some("200T".to_string()), "/", None);
|
||||
assert_eq!(
|
||||
unknown,
|
||||
encode_segments(&[(None, "-".to_string()), (None, "/".to_string()), (None, "200T".to_string())])
|
||||
);
|
||||
assert_eq!(decode_segments_plain(&unknown), "-/200T");
|
||||
|
||||
// A known ratio colours only the actual half; the slash + expected stay
|
||||
// uncoloured, and it still round-trips to the same plain text.
|
||||
let known = encode_combined_cell(&p, "60.0 TH/s / 200 TH/s", Some(0.3));
|
||||
// the default colour, and it round-trips to the plain "actual/expected".
|
||||
let known =
|
||||
encode_combined_cell(&p, Some("60.0T".to_string()), Some("200T".to_string()), "/", Some(0.3));
|
||||
let expected = encode_segments(&[
|
||||
(Some(ratio_color(&p, 0.3)), "60.0 TH/s".to_string()),
|
||||
(None, " / ".to_string()),
|
||||
(None, "200 TH/s".to_string()),
|
||||
(Some(ratio_color(&p, 0.3)), "60.0T".to_string()),
|
||||
(None, "/".to_string()),
|
||||
(None, "200T".to_string()),
|
||||
]);
|
||||
assert_eq!(known, expected);
|
||||
assert_eq!(decode_segments_plain(&known), "60.0 TH/s / 200 TH/s");
|
||||
assert_eq!(decode_segments_plain(&known), "60.0T/200T");
|
||||
|
||||
// Actual-only (no expected) is a single uncoloured segment.
|
||||
let actual_only = encode_combined_cell(&p, Some("95.0T".to_string()), None, "/", None);
|
||||
assert_eq!(decode_segments_plain(&actual_only), "95.0T");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user