round 19: columns, scan speed, per-firmware logs, more scanned fields

Table/columns:
- Fix the "columns shrink to tiny" bug on language change / add / hide (#3, #24):
  the rebuild-time capped autosize read column widths before GTK's measurement
  landed. Columns keep their default widths; autosize is on-demand only.
- Right-align every column except IP (#21): new alignment param on the bridge
  append calls; the SegmentRenderer and the tooltip hit-test honour it.
- "Auto-size all columns" header menu item; Ctrl+A selects all rows (#4).
- Remove the Boards (dots) column (#7).
- Split the slash-joined Fan column into per-fan columns Fan 1-4 (#8).
- Efficiency: unit moved into the value and made algorithm-aware (J/TH for
  SHA256 families, J/kSol for Equihash), fixing the blank/garbage figure on
  non-SHA256 miners (#9, #23).
- Pool account column before Worker by default (#22).

Scan:
- Fast scan (#18): emit a lightweight identity row the instant a miner is
  identified, then upsert the full telemetry row when get_data completes.
- User-adjustable scan concurrency with a bounded max (#25).
- Surface more scanned values as columns (#10): current tuning target, accepted
  / rejected shares + reject %, and per-hashboard hashrate / voltage / frequency.

Logs (#11-16): fetch the miner log through asic-rs's per-backend read_logs()
instead of the narrow curl paths, fixing Braiins / LuxOS / Z15 / BixBit / stock
Antminer; WhatsMiner keeps the fault-code fallback (no API log). Removed the
summary tidbits from the log viewer (#13).

Misc: fix per-icon health tooltips (advance math matched to the renderer) (#2);
paused miners show blue hashboard icons, healthy stays green (#19); state-aware
Pause/Resume in the right-click menu (#20); export opens a column-picker dialog
(#6) and the default filename carries a UTC timestamp (#5); the scan status bar
says "Scan Paused" / "Scan Stopped" and no longer overwrites Stop with paused
(#17); the bench badge shows the weighted-average microbench delta vs the
previous release (#1).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Djv3oncM4LxTS5tb61Ako6
This commit is contained in:
2026-09-23 11:40:21 -06:00
co-authored by Claude Opus 4.8
parent 4154a50ed0
commit 42e3bf8f5b
12 changed files with 808 additions and 568 deletions
+181 -154
View File
@@ -43,6 +43,11 @@ const ID_COLS_CATEGORIES: i32 = 232;
const ID_FILTER_OK: i32 = 205;
const ID_FILTER_CANCEL: i32 = 206;
const ID_FILTER_RESET: i32 = 210;
// Export column-picker dialog (round 19 #6).
const ID_EXPORT_OK: i32 = 207;
const ID_EXPORT_CANCEL: i32 = 208;
const ID_EXPORT_ALL: i32 = 209;
const ID_EXPORT_NONE: i32 = 211;
// Per-column "All"/"None" buttons in the filter panel are ID_FILTER_ALL_BASE +
// column index (and the None equivalent). 100 columns of headroom each.
const ID_FILTER_ALL_BASE: i32 = 300;
@@ -133,6 +138,8 @@ const ID_HDR_COLUMNS: i32 = 764;
// (round 11 #16).
const ID_HDR_SORT_REL_ASC: i32 = 765;
const ID_HDR_SORT_REL_DESC: i32 = 766;
// Auto-size every column at once (round 19 #4).
const ID_HDR_AUTOSIZE_ALL: i32 = 767;
// Ticks (~seconds) to keep an action's result on the status bar before the
// idle/countdown status takes over again.
// Filter dialog: the column-selector dropdown + the comparator dropdown.
@@ -189,8 +196,8 @@ fn tint_toward(base: (u8, u8, u8), target: (u8, u8, u8), f: f64) -> (u8, u8, u8)
(lerp(base.0, target.0), lerp(base.1, target.1), lerp(base.2, target.2))
}
/// Colour for a combined actual/expected ratio (Hashrate/Hashboards/
/// TotalChips): full red at 50% (or below), amber at 75%, green at 100%+,
/// Colour for a combined actual/expected ratio (Hashrate/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) {
@@ -238,15 +245,9 @@ 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).
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 for a combined actual/expected column
/// (Hashrate/Hashboards/TotalChips) from its already-formatted parts: the
/// (Hashrate/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
@@ -313,7 +314,6 @@ fn encode_flag_cell(plain: &str, color: Option<(u8, u8, u8)>) -> String {
/// Shape-sentinel strings the SegmentRenderer draws as small vector icons rather
/// than text (round 11 #10/#13). These byte values MUST match the SHAPE_* set in
/// widgets_bridge.cpp. They are control characters, never emoji/pictographs.
const SHAPE_DOT: &str = "\u{0007}";
const SHAPE_LOCK: &str = "\u{0002}";
const SHAPE_UNLOCK: &str = "\u{0003}";
// Status-column KPI icons (round 12 #11): one sentinel per status, each drawn
@@ -376,28 +376,6 @@ fn svg_viewbox(svg: &str) -> (i32, i32) {
.unwrap_or((1, 1))
}
/// Boards column: one status dot per hashboard (round 11 #10). Board 1 is the
/// rightmost dot, so boards render high-position-first (left to right). green =
/// present and hashing, red = present but idle/faulty, grey = not detected.
fn encode_board_dots(pal: &Palette, status: &[crate::model::BoardHealth]) -> String {
use crate::model::BoardHealth;
if status.is_empty() {
return encode_segments(&[(None, String::new())]);
}
let segs: Vec<Segment> = status
.iter()
.rev()
.map(|h| {
let color = match h {
BoardHealth::Ok => pal.green,
BoardHealth::Fault => pal.red,
BoardHealth::Missing => pal.label,
};
(Some(color), SHAPE_DOT.to_string())
})
.collect();
encode_segments(&segs)
}
/// Access column: a green open padlock (writable) or red closed padlock
/// (view-only); blank when the lock state is unknown (round 11 #13).
@@ -472,7 +450,16 @@ fn encode_component_health(
}
let boards = r.board_healths();
for h in &boards {
segs.push((Some(health_color(pal, *h)), SHAPE_CHIP.to_string()));
// A paused miner's boards are intentionally idle, not faulty: show every
// detected board blue instead of its (red) health colour, while every
// other component keeps its normal colour. A genuinely undetected board
// stays grey (round 19 #19).
let color = if r.paused && *h != crate::model::CompHealth::Unreachable {
pal.accent
} else {
health_color(pal, *h)
};
segs.push((Some(color), SHAPE_CHIP.to_string()));
}
for _ in boards.len()..max_boards {
segs.push((None, SHAPE_GAP.to_string()));
@@ -533,23 +520,6 @@ fn svg_width_for_height(svg: &str, h: i32) -> i32 {
.max(1)
}
/// 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.
fn encode_cooling_cell(pal: &Palette, fans: &[f64]) -> String {
if fans.is_empty() {
return encode_segments(&[(None, String::new())]);
}
let mut segs: Vec<Segment> = Vec::with_capacity(fans.len() * 2 - 1);
for (i, &rpm) in fans.iter().enumerate() {
if i > 0 {
segs.push((None, "/".to_string()));
}
segs.push((Some(fan_color(pal, rpm)), format_fan_rpm(rpm)));
}
encode_segments(&segs)
}
/// Format a filter's numeric bound without a trailing ".0" for whole numbers.
fn fmt_num(v: f64) -> String {
if v.is_finite() && v == v.trunc() && v.abs() < 1e15 {
@@ -642,11 +612,6 @@ pub struct App {
kpi_power: Widget,
progress: Widget,
pub table: Option<Widget>,
// Whether the columns have had their one-time content-fit autosize applied
// since the table was last (re)built (round 18 #10). Reset on rebuild; set
// the first time fill_rows runs with rows present, so the default widths fit
// their contents (capped) once and manual resizes afterwards are preserved.
columns_autosized: bool,
// Set when a scan streamed new rows this drain; flushed by tick() at most once
// per second (or immediately once the scan ends) so the full table refill runs
// ~1 Hz during a scan instead of every fast tick (round 18 #12).
@@ -668,6 +633,10 @@ pub struct App {
refresh: Option<scan::RefreshHandle>,
// scan loop (play/pause/stop + auto-rescan)
playing: bool,
// True when the user explicitly Stopped the scan (as opposed to Paused the
// auto-rescan loop). Distinguishes the idle status line "Scan Stopped" from
// "Scan Paused"; cleared when a scan starts (round 19 #17).
scan_stopped: bool,
auto_secs: u64,
// Per-miner scan timeout in seconds (round 14 #2).
scan_timeout_secs: u64,
@@ -793,10 +762,15 @@ pub struct App {
ranges_edit: Widget,
ranges_auto: Widget,
ranges_timeout: Widget,
/// Scan-concurrency (in-flight probes) input in the ranges dialog (round 19 #25).
ranges_concurrency: Widget,
columns_dialog: Widget,
columns_list: Widget,
/// The columns-dialog "hide empty columns" checkbox, read at Apply.
columns_hide_empty_cb: Widget,
/// Export column-picker dialog + its checklist (round 19 #6).
export_dialog: Widget,
export_list: Widget,
/// When set, columns with no scanned value in any row are hidden from the
/// table (non-destructively -- clearing it restores them) (round 11 #9).
auto_hide_empty: bool,
@@ -1029,7 +1003,6 @@ pub fn build(frame: Widget) -> App {
kpi_power,
progress,
table: None,
columns_autosized: false,
rows_dirty: false,
built_columns: Vec::new(),
table_parent,
@@ -1040,6 +1013,7 @@ pub fn build(frame: Widget) -> App {
target_ips: HashSet::new(),
refresh: None,
playing: true,
scan_stopped: false,
auto_secs: scan::load_auto_secs(),
scan_timeout_secs: scan::load_scan_timeout(),
countdown: 0,
@@ -1103,9 +1077,12 @@ pub fn build(frame: Widget) -> App {
ranges_edit: frame,
ranges_auto: frame,
ranges_timeout: frame,
ranges_concurrency: frame,
columns_dialog: frame,
columns_list: frame,
columns_hide_empty_cb: frame,
export_dialog: frame,
export_list: frame,
auto_hide_empty: false,
filter_dialog: frame,
filter_col_choice: frame,
@@ -1211,13 +1188,15 @@ impl App {
Some((sc, false)) if sc == c => title.push_str(" v"),
_ => {}
}
if matches!(c, Column::Hashrate | Column::Health | Column::Hashboards | Column::TotalChips | Column::ChipTemp | Column::Cooling | Column::Locked | Column::Light | Column::Error | Column::Status | Column::Firmware) {
// Every column except IP is right-aligned (round 19 #21).
let align = if c == Column::Ip { wx_rs::ALIGN_LEFT } else { wx_rs::ALIGN_RIGHT };
if matches!(c, Column::Hashrate | Column::Health | Column::TotalChips | Column::ChipTemp | Column::Locked | Column::Light | Column::Error | Column::Status | Column::Firmware) {
// 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.
t.dvlc_append_colored_col(&title, c.width(), !fixed);
// expected) via a custom renderer that parses the segment-encoded
// cell value fill_rows writes.
t.dvlc_append_colored_col(&title, c.width(), !fixed, align);
} else {
t.dvlc_append_text_col(&title, c.width(), !fixed);
t.dvlc_append_text_col(&title, c.width(), !fixed, align);
}
}
// Add the table to the root sizer (proportion 1 => fills the area under
@@ -1233,9 +1212,6 @@ impl App {
// detect an auto-hide-empty set change and rebuild rather than render
// against stale columns (round 18 #12).
self.built_columns = self.table_columns();
// Fresh columns come back at their configured default widths; let the
// next fill_rows shrink them to fit their contents (round 18 #10).
self.columns_autosized = false;
self.fill_rows();
}
@@ -1300,8 +1276,6 @@ impl App {
Some(op) => encode_segments(&[(Some(self.pal.amber), op.clone())]),
None => encode_component_health(&self.pal, r, max_fans, max_boards),
},
// Boards column: per-hashboard health dots (round 11 #10).
Column::Hashboards => encode_board_dots(&self.pal, &r.board_status),
Column::TotalChips => {
let actual = r.total_chips.map(|v| v.to_string());
let expected = r.expected_chips.map(|v| v.to_string());
@@ -1314,7 +1288,6 @@ impl App {
encode_combined_cell(&self.pal, actual, expected, " / ", ratio)
}
Column::ChipTemp => encode_board_temps_cell(&self.pal, &r.board_temps, r.chip_temp_c),
Column::Cooling => encode_cooling_cell(&self.pal, &r.fan_rpms),
// Access column: a padlock icon, green open (writable) / red
// closed (view-only) (round 11 #13).
Column::Locked => encode_access_icon(&self.pal, r.write_locked),
@@ -1353,17 +1326,14 @@ impl App {
}
}
}
// Item 10: the first time we have rows to measure after a (re)build, set
// each column's width to the smaller of its content-fit width and its
// configured default (the cap), so columns are no wider than needed. Done
// once per rebuild; the user's later manual resizes are then preserved
// because subsequent fill_rows calls (scan updates) skip this.
if !self.columns_autosized && !self.view_idx.is_empty() {
for (pos, c) in cols.iter().enumerate() {
t.dvlc_autosize_col_capped(pos, c.width());
}
self.columns_autosized = true;
}
// Columns keep their configured default widths (scaled by the table zoom
// via table_zoom_reapply). A previous build re-ran a content-fit autosize
// on every rebuild, but on GTK reading a column's width immediately after
// SetWidth(AUTOSIZE) returns a value from before the native measurement
// lands, so a rebuild (language change, hide/show, reorder) collapsed every
// column to the floor (round 19 #3/#24). Autosize is now on-demand only
// (the header menu's "Auto-size" items), where the columns are realised so
// the measurement is valid.
if let Some(row) = top {
t.dvlc_ensure_visible(row.min(self.view_idx.len().saturating_sub(1)));
}
@@ -1572,10 +1542,14 @@ impl App {
menu.menu_append(ID_CTX_LIGHT_ON, &format!("Flash lights{sfx}"));
}
}
if caps.pause {
// State-aware (round 19 #20): only offer Pause when at least one
// selected miner is actually running, and Resume only when at least
// one is paused, so a paused miner never shows "Pause" and a running
// one never shows "Resume". On a mixed selection both can appear.
if caps.pause && selected.iter().any(|r| !r.paused) {
menu.menu_append(ID_CTX_PAUSE, &format!("Pause mining{sfx}"));
}
if caps.resume {
if caps.resume && selected.iter().any(|r| r.paused) {
menu.menu_append(ID_CTX_RESUME, &format!("Resume mining{sfx}"));
}
if caps.tuning {
@@ -2001,24 +1975,16 @@ impl App {
}
let rows = self.selected_rows();
let Some(r) = rows.first() else { return };
let (ip, brand, firmware) = (r.ip.clone(), r.brand.clone(), r.firmware.clone());
// VNish unlock password + Antminer web login: a per-firmware override
// (round 12 #13) wins, else the shipped default / saved global creds.
let vnish_pass = credentials::load_firmware_credentials()
.get("VNish")
.map(|(_, p)| p.clone())
.filter(|p| !p.is_empty())
.unwrap_or_else(|| credentials::firmware_default_for("VNish").1);
let vnish_pass = if vnish_pass.is_empty() { "admin".to_string() } else { vnish_pass };
let (am_user, am_pass) =
credentials::load_credentials().unwrap_or_else(|| ("root".into(), "root".into()));
let (ip, brand) = (r.ip.clone(), r.brand.clone());
// asic-rs read_logs() authenticates through configured_factory() (the saved
// scan credentials), so no per-firmware creds are threaded here (round 19
// #11-16). WhatsMiner's fault-code fallback is unauthenticated.
let timeout = self.scan_timeout_secs;
wx_rs::set_status_text(&format!("fetching log from {ip}..."));
let (tx, rx) = std::sync::mpsc::channel();
let ip_thread = ip.clone();
let spawned = std::thread::Builder::new().name("log-fetch".into()).spawn(move || {
let res = crate::log_scan::scan_log(
&ip_thread, &brand, &firmware, &vnish_pass, &am_user, &am_pass,
);
let res = crate::log_scan::scan_log(&ip_thread, &brand, timeout);
let _ = tx.send(res);
});
if spawned.is_err() {
@@ -2064,12 +2030,6 @@ impl App {
let frame = Widget::main_frame();
let dlg = Widget::dialog(frame, &format!("Miner log (API) -- {ip}"));
let root = Widget::box_sizer(true);
let summary = if scan.summary.is_empty() {
"(no summary)".to_string()
} else {
scan.summary.join("\n")
};
root.add(Widget::static_text(dlg, &summary), 0, sf::BORDER_ALL, 8);
let text = Widget::text_ctrl(dlg, true);
text.set_min_size(760, 420);
text.set_value(&scan.text);
@@ -2342,7 +2302,9 @@ impl App {
ID_SCAN_CREDS => return Some(self.build_firmware_creds_dialog()),
ID_LOGS_OPEN => return Some(self.build_logs_dialog()),
ID_HDR_SORT_ASC | ID_HDR_SORT_DESC | ID_HDR_SORT_REL_ASC | ID_HDR_SORT_REL_DESC
| ID_HDR_HIDE | ID_HDR_AUTOSIZE | ID_HDR_COLUMNS => return self.on_header_menu(id),
| ID_HDR_HIDE | ID_HDR_AUTOSIZE | ID_HDR_AUTOSIZE_ALL | ID_HDR_COLUMNS => {
return self.on_header_menu(id)
}
ID_CTX_OPEN => {
for ip in self.selected_ip_list() {
wx_rs::launch_browser(&format!("http://{ip}"));
@@ -3130,6 +3092,7 @@ impl App {
self.selected_ips = keep.into_iter().filter(|ip| self.target_ips.contains(ip)).collect();
self.scan_total = total;
self.scanning = true;
self.scan_stopped = false;
self.progress.gauge_set_range(total.max(1) as i32);
self.progress.gauge_set_value(0);
self.progress.show(true);
@@ -3250,11 +3213,16 @@ impl App {
self.start_new_scan();
}
} else {
wx_rs::set_status_text(&format!(
"{} miners - {}",
self.rows.len(),
if self.playing { "auto-rescan off" } else { "paused" }
));
// Distinguish an explicit Stop from a Pause so the idle tick doesn't
// overwrite "Scan Stopped" with "paused" (round 19 #17).
let tail = if self.playing {
"auto-rescan off"
} else if self.scan_stopped {
"Scan Stopped"
} else {
"Scan Paused"
};
wx_rs::set_status_text(&format!("{} miners - {}", self.rows.len(), tail));
}
to_show
}
@@ -3393,6 +3361,7 @@ impl App {
}
menu.menu_append_separator();
menu.menu_append(ID_HDR_AUTOSIZE, "Auto-size this column");
menu.menu_append(ID_HDR_AUTOSIZE_ALL, "Auto-size all columns");
// The fixed IP column can't be hidden.
if !self.view.is_fixed(col) {
menu.menu_append(ID_HDR_HIDE, &format!("Hide {}", col.title()));
@@ -3437,6 +3406,17 @@ impl App {
t.dvlc_autosize_col(pos);
}
}
// Auto-size every column to its content (round 19 #4). Done on demand
// (the columns are realised here, so the measurement is valid, unlike a
// rebuild-time autosize -- see rebuild_table). Ctrl+A selects all rows
// natively on the GtkTreeView, so this is the "resize all" companion.
ID_HDR_AUTOSIZE_ALL => {
if let Some(t) = self.table {
for pos in 0..t.dvlc_col_count() {
t.dvlc_autosize_col(pos);
}
}
}
ID_HDR_COLUMNS => return Some(self.build_columns_dialog()),
_ => {}
}
@@ -3530,6 +3510,19 @@ impl App {
to_edit.set_value(&self.scan_timeout_secs.to_string());
to_edit.set_min_size(60, -1);
auto_row.add(to_edit, 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL, 6);
// Scan concurrency (in-flight probes): higher scans faster but can starve
// per-miner telemetry; clamped to [MIN, MAX] on apply (round 19 #25).
auto_row.add_stretch(1);
let cc_lbl = Widget::static_text(dlg, "Concurrency:");
auto_row.add(cc_lbl, 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL, 6);
let cc_edit = Widget::text_ctrl(dlg, false);
cc_edit.set_value(&scan::load_scan_concurrency().to_string());
cc_edit.set_min_size(60, -1);
cc_edit.set_tool_tip(&format!(
"In-flight probes per scan ({}-{}). Higher is faster but can drop values on slow miners; default {}.",
scan::MIN_SCAN_CONCURRENCY, scan::MAX_SCAN_CONCURRENCY, scan::SCAN_CONCURRENCY_LIMIT
));
auto_row.add(cc_edit, 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL, 6);
root.add_sizer(auto_row, 0, sf::EXPAND | sf::BORDER_LEFT | sf::BORDER_RIGHT, 6);
let btns = Widget::box_sizer(false);
let apply = Widget::button(dlg, "Apply", ID_RANGES_APPLY);
@@ -3542,6 +3535,7 @@ impl App {
self.ranges_edit = edit;
self.ranges_auto = auto_edit;
self.ranges_timeout = to_edit;
self.ranges_concurrency = cc_edit;
dlg
}
@@ -3572,6 +3566,10 @@ impl App {
self.scan_timeout_secs = secs.max(1);
let _ = scan::save_scan_timeout(self.scan_timeout_secs);
}
// Save the scan concurrency (round 19 #25), clamped in save_scan_concurrency.
if let Ok(n) = self.ranges_concurrency.get_value().trim().parse::<usize>() {
let _ = scan::save_scan_concurrency(n);
}
let _ = scan::save_ranges(&lines);
self.begin_scan(lines);
wx_rs::set_status_text("scanning...");
@@ -3699,20 +3697,81 @@ impl App {
/// Export the full scan data to a CSV the user picks (round 15 #14). Every
/// scanned data point is exported, one value per cell -- more complete and
/// machine-readable than the on-screen table.
fn apply_export(&mut self) {
/// Export toolbar button: open the column-picker dialog (round 19 #6), unless
/// there is nothing to export yet. Returns the dialog to show modally.
fn open_export_dialog(&mut self) -> Option<Widget> {
if self.rows.is_empty() {
wx_rs::set_status_text("nothing to export yet -- run a scan first");
return None;
}
Some(self.build_export_dialog())
}
/// A checklist of every export field (all on by default), with All/None and
/// Export/Cancel. OK -> do_export (round 19 #6).
fn build_export_dialog(&mut self) -> Widget {
let frame = Widget::main_frame();
let dlg = Widget::dialog(frame, "Export columns");
let root = Widget::box_sizer(true);
root.add(Widget::static_text(dlg, "Choose the columns to export:"), 0, sf::BORDER_ALL, 8);
let clb = Widget::check_list_box(dlg);
for name in crate::export::export_field_names() {
clb.clb_append(&name);
clb.clb_set_checked(clb.clb_count() - 1, true);
}
root.add(clb, 1, sf::EXPAND | sf::BORDER_ALL, 8);
let sel = Widget::box_sizer(false);
sel.add(Widget::button(dlg, "All", ID_EXPORT_ALL), 0, sf::BORDER_ALL, 4);
sel.add(Widget::button(dlg, "None", ID_EXPORT_NONE), 0, sf::BORDER_ALL, 4);
root.add_sizer(sel, 0, sf::BORDER_LEFT | sf::BORDER_RIGHT, 4);
let btns = Widget::box_sizer(false);
btns.add_stretch(1);
btns.add(Widget::button(dlg, "Export", ID_EXPORT_OK), 0, sf::BORDER_ALL, 6);
btns.add(Widget::button(dlg, "Cancel", ID_EXPORT_CANCEL), 0, sf::BORDER_ALL, 6);
root.add_sizer(btns, 0, sf::EXPAND | sf::BORDER_ALL, 6);
root.set_sizer_on(dlg);
dlg.set_min_size(360, 480);
dlg.fit(dlg);
self.export_dialog = dlg;
self.export_list = clb;
dlg
}
fn export_check_all(&self, checked: bool) {
let clb = self.export_list;
for i in 0..clb.clb_count() {
clb.clb_set_checked(i, checked);
}
}
/// Read the checked export fields, then save the filtered CSV. Default filename
/// carries a UTC date+time so successive exports don't collide (round 19 #5).
fn do_export(&mut self) {
let names = crate::export::export_field_names();
let clb = self.export_list;
let mut selected: HashSet<String> = HashSet::new();
for i in 0..clb.clb_count() {
if clb.clb_checked(i) {
if let Some(n) = names.get(i) {
selected.insert(n.clone());
}
}
}
self.export_dialog.close(1);
if selected.is_empty() {
wx_rs::set_status_text("no columns selected -- export cancelled");
return;
}
let default_name = format!("alkane-export-{}.csv", crate::export::timestamp_utc());
let Some(path) = Widget::save_file_dialog(
Widget::main_frame(),
"Export scan data",
"alkane-export.csv",
&default_name,
"CSV files (*.csv)|*.csv|All files (*.*)|*.*",
) else {
return; // cancelled
};
let csv = crate::export::rows_to_csv(&self.rows);
let csv = crate::export::rows_to_csv_selected(&self.rows, &selected);
match std::fs::write(&path, csv) {
Ok(()) => {
crate::logs::log(format!("exported {} miner(s) to {path}", self.rows.len()));
@@ -4224,7 +4283,11 @@ impl App {
ID_RANGES => return Some(self.build_ranges_dialog()),
ID_RANGES_APPLY => self.apply_ranges(),
ID_RANGES_CANCEL => self.ranges_dialog.close(0),
ID_EXPORT => self.apply_export(),
ID_EXPORT => return self.open_export_dialog(),
ID_EXPORT_OK => self.do_export(),
ID_EXPORT_CANCEL => self.export_dialog.close(0),
ID_EXPORT_ALL => self.export_check_all(true),
ID_EXPORT_NONE => self.export_check_all(false),
ID_SETTINGS => self.open_settings_menu(),
ID_LOGS_REFRESH => self.logs_text.set_value(&crate::logs::dump()),
ID_LOGS_CLEAR => {
@@ -4294,6 +4357,7 @@ impl App {
// Resume/start the scan loop: scan now (unless one is
// already running) + auto-rescan on.
self.playing = true;
self.scan_stopped = false;
if !self.scanning {
self.start_new_scan();
}
@@ -4301,12 +4365,14 @@ impl App {
ID_PAUSE => {
// Stop the auto-rescan loop (a scan in flight finishes).
self.playing = false;
wx_rs::set_status_text(&format!("{} miners - paused", self.rows.len()));
self.scan_stopped = false;
wx_rs::set_status_text(&format!("{} miners - Scan Paused", self.rows.len()));
}
ID_STOP => {
// Halt the loop and cancel any in-flight scan (dropping
// the receiver alone would leave the thread probing).
self.playing = false;
self.scan_stopped = true;
self.countdown = 0;
self.scanning = false;
if let Some(old) = self.scan.take() {
@@ -4314,7 +4380,7 @@ impl App {
}
self.progress.show(false);
self.table_parent.layout();
wx_rs::set_status_text(&format!("{} miners - stopped", self.rows.len()));
wx_rs::set_status_text(&format!("{} miners - Scan Stopped", self.rows.len()));
}
ID_FILTER_ALL_BASE => self.filter_check_all(true),
ID_FILTER_NONE_BASE => self.filter_check_all(false),
@@ -4345,11 +4411,6 @@ impl App {
pub fn run_fixture_selftest(&mut self) -> bool {
self.rows = crate::fixtures::bench_fleet();
self.view = ViewState::default();
// Show the detailed per-board Boards column so its dot-sentinel rendering
// is actually exercised (round 18 #12: it is opt-in, not default-visible,
// so without this the Boards check below was dead). rebuild_table (not
// fill_rows) so the widget's columns match the changed visible set.
self.view.visible.insert(crate::model::Column::Hashboards);
self.rebuild_table();
let mut ok = true;
@@ -4398,12 +4459,12 @@ impl App {
// Icon/dot columns (round 11 #10/#13) render shape sentinels, not
// text, so they don't round-trip to c.cell(r); they're verified
// structurally in the icon-column spot-check below.
if matches!(c, Column::Health | Column::Hashboards | Column::Locked | Column::Light | Column::Status) {
if matches!(c, Column::Health | Column::Locked | Column::Light | Column::Status) {
continue;
}
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::TotalChips | Column::ChipTemp | Column::Cooling | Column::Error | Column::Firmware) {
let got = if matches!(c, Column::Hashrate | Column::TotalChips | Column::ChipTemp | Column::Error | Column::Firmware) {
decode_segments_plain(&raw)
} else {
raw
@@ -4438,15 +4499,9 @@ impl App {
// displayed cell.
let status_of = |row: usize| -> &'static str { self.rows[self.view_idx[row]].status() };
// Icon columns (round 11 #10/#13): the store carries shape sentinels
// (dots / padlock), not text -- verify they are present.
let boards_col = cols.iter().position(|c| *c == Column::Hashboards);
// (padlock), not text -- verify they are present.
let access_col = cols.iter().position(|c| *c == Column::Locked);
let health_col = cols.iter().position(|c| *c == Column::Health);
if let (Some(bc), Some(row)) = (boards_col, find("10.255.1.166")) {
let raw = t.dvlc_get_cell(row, bc).unwrap_or_default();
check("Boards column renders dot sentinels for a mining miner",
raw.contains('\u{0007}'), format!("cell={raw:?}"));
}
// Health column (round 13 #3): the power (bolt) and control-board (brain)
// icons are always emitted, plus a chip icon per hashboard for a mining
// miner; verify the sentinels are present.
@@ -4632,15 +4687,6 @@ mod tests {
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();
assert_eq!(fan_color(&p, 0.0), p.label, "stopped fan -> grey label colour");
assert_eq!(fan_color(&p, 6000.0), p.accent, "at/above ceiling -> saturated accent blue");
assert_eq!(fan_color(&p, 12000.0), p.accent, "clamped above the ceiling");
assert_eq!(fan_color(&p, 3000.0), tint_toward(p.label, p.accent, 0.5), "halfway blend");
}
#[test]
fn combined_cell_unknown_actual_is_not_coloured_red() {
let p = test_pal();
@@ -4669,23 +4715,4 @@ mod tests {
let actual_only = encode_combined_cell(&p, Some("95.0T".to_string()), None, "/", None);
assert_eq!(decode_segments_plain(&actual_only), "95.0T");
}
#[test]
fn cooling_cell_colours_each_fan_with_black_slashes() {
let p = test_pal();
assert_eq!(
decode_segments_plain(&encode_cooling_cell(&p, &[4800.0, 4600.0])),
"4.8k/4.6k",
);
// Slash segments carry no colour (they render in the default text colour).
let encoded = encode_cooling_cell(&p, &[4800.0, 4600.0]);
let expected = encode_segments(&[
(Some(fan_color(&p, 4800.0)), format_fan_rpm(4800.0)),
(None, "/".to_string()),
(Some(fan_color(&p, 4600.0)), format_fan_rpm(4600.0)),
]);
assert_eq!(encoded, expected);
// No fans -> a single empty segment that decodes to "".
assert_eq!(decode_segments_plain(&encode_cooling_cell(&p, &[])), "");
}
}