GUI round 8a: no phantom-offline rows, hashrate/temp conditional formatting, multi-range parse, uniform KPI cards
build-test-release / release (push) Successful in 10m18s

First slice of the round-8 batch (Linux; Windows/macOS builds deferred to a
dedicated platform round per the design discussion). Feature/format changes
with no C++ bridge dependency; the bridge-dependent items (scroll-hold, zebra +
default-colour rework, header menu, rubber-band select, tooltips, presets,
frozen columns, plus the new asic-rs columns) follow in 8b/8c.

- Offline recognition (reverses the round-6 interpretation): the scanner no
  longer fabricates a row for an address with no miner. Only miners that
  actually respond become rows; a responding non-mining miner is "not hashing".
  Removed the MinerRow.offline field, MinerRow::offline(), the "offline" status,
  and the synthetic fixture/fake-scan offline rows. The bench fleet is now 9
  rows (was 10); KPI not-hashing is 1.
- Hashrate conditional format: the scale now bottoms out at 50% (full red at
  <=50% of expected, amber at 75%, green at 100%+), matching "green = 100%,
  red = 50% or lower".
- Hashrate cell format: prefix-only unit, no space, no spaces around the slash
  (e.g. "60.0T/200T", "80.5T/95.0T") instead of "60.0 TH/s / 200 TH/s". The
  combined-cell encoder now builds from formatted parts rather than re-splitting
  a joined string on " / ", so hashrate ("/") and count columns (" / ") each
  keep their own separator.
- Chip temperature: new blue-to-red conditional scale (cool blue at/below 40 C
  to hot red at/above 90 C); the Chip temp column is now a coloured cell.
- Multi-range scan input: each octet may be a range, so "10.1-9.1.1-255" expands
  to the 9 /24s (cartesian per-octet parse). CIDR / full-range / short-range
  forms are preserved.
- KPI header: every card is now a uniform size with its value + label centred.
- Right-click menu: "Fault light on/off" relabelled to "Flash lights on/off"
  (the underlying asic-rs set_fault_light call is unchanged).

Tests updated for the new formats/counts; new unit tests for the 50%-100% ratio
scale, the blue-to-red temp scale, the parts-based combined encoder, and the
per-octet range parser. cargo check --release --tests is clean; CI runs the
release build + tests + headless self-test.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y8h447BPyJR4fioYZvQ9bh
This commit is contained in:
2026-09-17 16:26:19 -06:00
co-authored by Claude Opus 4.8
parent cdd605c189
commit 9dc4e25a28
4 changed files with 268 additions and 204 deletions
+49 -79
View File
@@ -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}"),
}
}
@@ -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 -> "<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");
}
@@ -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 -> '- / <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 +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 -> '<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 +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<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);
}