diff --git a/crates/alkane-gui/src/fixtures.rs b/crates/alkane-gui/src/fixtures.rs index b9d8af5a..2077c59e 100644 --- a/crates/alkane-gui/src/fixtures.rs +++ b/crates/alkane-gui/src/fixtures.rs @@ -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 -//! MEMORY-SNAPSHOT), 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. +//! MEMORY-SNAPSHOT). 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 @@ -112,23 +111,14 @@ impl Board { } } -/// 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 { let boards = [ Board { ip: "10.255.1.112", model: "Antminer S17", firmware: "Stock", @@ -161,8 +151,5 @@ pub fn bench_fleet() -> Vec { hashrate: 0.0, expected: 0.0, power: 0.0, temp: 0.0, fan: 0.0, worker: "", mining: false, paused: true }, ]; - let mut rows: Vec = 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() } diff --git a/crates/alkane-gui/src/model.rs b/crates/alkane-gui/src/model.rs index cf1390a1..2847d4dd 100644 --- a/crates/alkane-gui/src/model.rs +++ b/crates/alkane-gui/src/model.rs @@ -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 { + 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 { 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, "- / " when only the expected is known, -/// and " / " 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, "-/" when only the expected is known, and +/// "/" 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}"), } } @@ -266,30 +270,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" @@ -800,9 +788,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 +814,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 +844,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 +859,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 +904,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 -> " / ". - assert_eq!(Column::Hashrate.cell(s21), "60.0 TH/s / 200 TH/s"); + // Combined hashrate cell: both known -> "/" (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"); } @@ -1448,7 +1431,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 +1441,7 @@ mod tests { expected_chips: Some(228), ..Default::default() }; - assert_eq!(Column::Hashrate.cell(&expected_only), "- / 200 TH/s", "only expected -> '- / '"); + assert_eq!(Column::Hashrate.cell(&expected_only), "-/200T", "only expected -> '-/'"); assert_eq!(Column::Hashboards.cell(&expected_only), "- / 3"); assert_eq!(Column::TotalChips.cell(&expected_only), "- / 228"); @@ -1471,7 +1454,7 @@ mod tests { expected_chips: Some(228), ..Default::default() }; - assert_eq!(Column::Hashrate.cell(&both), "60.0 TH/s / 200 TH/s", "both known -> ' / '"); + assert_eq!(Column::Hashrate.cell(&both), "60.0T/200T", "both known -> '/'"); assert_eq!(Column::Hashboards.cell(&both), "3 / 3"); assert_eq!(Column::TotalChips.cell(&both), "190 / 228"); } @@ -1538,18 +1521,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 +1532,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 +1552,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 = (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); } diff --git a/crates/alkane-gui/src/scan.rs b/crates/alkane-gui/src/scan.rs index ad8105a1..6b05f04b 100644 --- a/crates/alkane-gui/src/scan.rs +++ b/crates/alkane-gui/src/scan.rs @@ -120,6 +120,32 @@ pub fn parse_line(line: &str) -> Result, 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::>()?; + 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, 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) -> 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 = rows.iter().map(|r| r.ip.clone()).collect(); - targets.insert(offline_ip.clone()); - let total = rows.len() + 1; + let targets: HashSet = 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) -> 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) -> 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() }); @@ -451,8 +487,6 @@ async fn to_row(miner: &dyn Miner) -> MinerRow { MinerRow { ip: data.ip.to_string(), selected: false, - // A miner that responded to the scan is reachable. - offline: false, caps, model, mac: data.mac.map(|m| m.to_string()).unwrap_or_default(), @@ -507,8 +541,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 +898,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 +1139,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 +1155,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 diff --git a/crates/alkane-gui/src/ui.rs b/crates/alkane-gui/src/ui.rs index 5a476109..40d42d01 100644 --- a/crates/alkane-gui/src/ui.rs +++ b/crates/alkane-gui/src/ui.rs @@ -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,21 +125,37 @@ 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) -> 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, + expected: Option, + sep: &str, + ratio: Option, +) -> 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())]) } } @@ -199,7 +222,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 +231,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 +366,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 +378,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 +557,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) { // 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,34 +597,40 @@ 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 "- / " - // 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 + // "-/" 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), _ => continue, }; @@ -712,8 +754,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 +879,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 +2021,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 +2042,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 +2056,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) { decode_segments_plain(&raw) } else { raw @@ -2048,8 +2090,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 +2110,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 +2209,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 +2239,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]