src/main.js: two median functions, four passes over a target's history, thresholds written inline #102

Closed
opened 2026-10-04 03:43:24 +02:00 by clawbot · 1 comment
Collaborator

Split out of #29 (items 4 and 5 of that issue), so each change stays small. Behaviour must not change; the unit tests from #99 cover the thresholds, statistics and health states this touches.

Problem, on next

  • The median is written twice in src/main.js: HostState.medianLatency() and the median in AppState's summary statistics.
  • HostState.averageLatency(), minLatency(), maxLatency() and medianLatency() each filter the history again.
  • The latency colour thresholds (50, 100, 200, 500ms) are written out in both latencyHex() and latencyClass(), so changing one can leave the figure and the sparkline disagreeing.
  • Numbers written inline that belong with the other settings in CONFIG: the health thresholds in AppState.healthStatus() (10, 4, 1000ms, 3), the debug log cap (1000 entries), the gateway probe timeout (1500ms), the recovery probe's count of targets (4) and interval, the resize delay (100ms), and the sorting cadence in tick() (second round, then every tenth).

Definition of done

  • One median function, used by both.
  • A target's min, max, average and median come from one pass over its history (or one filtered list), not four.
  • The colour thresholds are defined once; latencyHex() and latencyClass() both read that one definition.
  • The numbers above live in CONFIG with short names in the existing style, each read where it was written inline. No new module, no other refactor.
  • Existing tests pass unchanged; add a test only where a moved value is not already covered.
  • make check passes; TODO.md updated in the same commit; commit title ends (closes #102).

Model: opus-5-5

Split out of https://git.eeqj.de/sneak/netwatch/issues/29 (items 4 and 5 of that issue), so each change stays small. Behaviour must not change; the unit tests from https://git.eeqj.de/sneak/netwatch/pulls/99 cover the thresholds, statistics and health states this touches. ## Problem, on `next` - The median is written twice in `src/main.js`: `HostState.medianLatency()` and the median in `AppState`'s summary statistics. - `HostState.averageLatency()`, `minLatency()`, `maxLatency()` and `medianLatency()` each filter the history again. - The latency colour thresholds (50, 100, 200, 500ms) are written out in both `latencyHex()` and `latencyClass()`, so changing one can leave the figure and the sparkline disagreeing. - Numbers written inline that belong with the other settings in `CONFIG`: the health thresholds in `AppState.healthStatus()` (10, 4, 1000ms, 3), the debug log cap (1000 entries), the gateway probe timeout (1500ms), the recovery probe's count of targets (4) and interval, the resize delay (100ms), and the sorting cadence in `tick()` (second round, then every tenth). ## Definition of done - One median function, used by both. - A target's min, max, average and median come from one pass over its history (or one filtered list), not four. - The colour thresholds are defined once; `latencyHex()` and `latencyClass()` both read that one definition. - The numbers above live in `CONFIG` with short names in the existing style, each read where it was written inline. No new module, no other refactor. - Existing tests pass unchanged; add a test only where a moved value is not already covered. - `make check` passes; `TODO.md` updated in the same commit; commit title ends ` (closes #102)`. Model: opus-5-5
clawbot self-assigned this 2026-10-04 03:43:24 +02:00
Author
Collaborator

Done in #108: one function computes the min, max, median and average for both a row and the summary, the color limits are one table in CONFIG that both color functions read, and the other numbers the issue lists are CONFIG entries. Nothing the page shows changes. The footer's color legend still writes the limits out as text; the PR says so, with three judgement calls.

Model: opus-5-5

Done in https://git.eeqj.de/sneak/netwatch/pulls/108: one function computes the min, max, median and average for both a row and the summary, the color limits are one table in `CONFIG` that both color functions read, and the other numbers the issue lists are `CONFIG` entries. Nothing the page shows changes. The footer's color legend still writes the limits out as text; the PR says so, with three judgement calls. Model: opus-5-5
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/netwatch#102