Six enhancements: recompute, markers, vendoring, tests, nerd stats, DS18B20

1. POST /api/recompute re-derives every compensated column from the untouched
   raw values, removing the step a calibration otherwise leaves through the
   history. Possible because temp_raw, cpu_temp and hum are never overwritten.
   Idempotent by construction and tested per row: 0 of 6051 rows change on a
   second run. 6069 rows in 0.25 s here, so a few seconds on the Pi.

2. Calibration now emits a 'discontinuity' event alongside the calibration log,
   so downstream views can find the boundary without parsing prose.

3. Vendored Tailwind, Chart.js, hammer, the zoom plugin, KaTeX with its 20
   woff2 faces, and both Google fonts into ashvale/static, served by the
   station. 1.4 MB. Verified with every non-localhost request aborted in the
   browser: zero external requests, equations still render, fonts still load.
   The dashboard no longer needs internet.

4. 54 pytest cases over the pure numerics: physics closed forms and round
   trips, both compensator inverse properties, the Kalman covariance
   invariants and NIS consistency, the RLS trace cap under a deliberately
   unexcited regressor, conformal coverage, and the Zambretti ordering. Wired
   into CI after the seed step so the recompute cases have history. Writing
   them caught my own sign error on the conformal update: a hit raises alpha
   and narrows the band, which reads backwards until you follow it through.

5. Stats for Nerds gains the condition number of each head's covariance, a
   standardised innovation histogram per Kalman filter from a bounded 600
   sample ring buffer, and a reliability strip of realised against nominal
   coverage. All arithmetic on data already in memory.

6. OutdoorProbe reads a DS18B20 over the kernel 1-Wire driver, no new
   dependency. Polled on its own slower cadence because the sensor blocks for
   up to 750 ms during conversion, which would eat a third of the 2 s sample
   budget. Rejects the 85000 power-on sentinel and out-of-range values, and
   reports age so a dead probe cannot masquerade as fresh.
This commit is contained in:
2026-08-15 22:39:37 +01:00
parent 9d2e884b74
commit 98210bff8f
49 changed files with 1437 additions and 12 deletions
+16
View File
@@ -30,6 +30,7 @@ Two jobs here, both familiar from soft-sensor work:
from __future__ import annotations
from collections import deque
from dataclasses import dataclass, field
from typing import Dict, Optional
@@ -54,6 +55,7 @@ class KalmanCV:
P: np.ndarray = field(default_factory=lambda: np.eye(2) * 1e3)
initialised: bool = False
nis: float = 0.0 # normalised innovation squared, for health monitoring
innovation_z: float = 0.0
def update(self, z: float, dt: float) -> tuple[float, float]:
if not np.isfinite(z):
@@ -83,6 +85,11 @@ class KalmanCV:
self.P = I_KH @ self.P @ I_KH.T + K @ K.T * self.r # Joseph form, stays PSD
self.nis = (y * y) / S
# y/sqrt(S) is the innovation in units of its own predicted spread, so it
# is comparable across signals and should look standard normal when the
# filter is consistent. Cheap to keep, and the only honest way to see
# skew or fat tails rather than inferring them from a single NIS value.
self.innovation_z = float(y / np.sqrt(S)) if S > 0 else 0.0
return float(self.x[0]), float(self.x[1])
@property
@@ -265,6 +272,12 @@ class SignalTracker:
"pressure": KalmanCV(cfg.sensor.kalman_q_press, cfg.sensor.kalman_r_press),
}
self.last_ts: Optional[float] = None
# 600 samples per signal is 20 minutes at the live 2 s cadence, about
# 14 kB total. Bounded on purpose: this board has 512 MB and an
# unbounded diagnostic buffer is a slow memory leak with a nice name.
self.innovations: Dict[str, deque] = {
k: deque(maxlen=600) for k in self.filters
}
def step(self, ts: float, temp_raw: float, hum: float, press: float,
cpu_temp: float) -> Dict[str, float]:
@@ -278,6 +291,9 @@ class SignalTracker:
t_lvl, t_rate = self.filters["temperature"].update(temp_c, dt)
h_lvl, h_rate = self.filters["humidity"].update(hum_c, dt)
p_lvl, p_rate = self.filters["pressure"].update(press, dt)
for name, kf in self.filters.items():
if kf.initialised:
self.innovations[name].append(kf.innovation_z)
return {
"temp_c": temp_c,