diff --git a/CLAUDE.md b/CLAUDE.md index 1a5c2c5..42695d5 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -223,7 +223,8 @@ Read this first when picking the project back up. **Batch 1 fixed (2026-10-29):** #1 (`b320a53`, settings read after unescaping: mode −7, rate −6, interval −4, record time +6), #9 (`ce441a0`, one reconnect for the read-back), #8 (`9492e49`, downloads stored through `save_imported_bw` with - the unit's peaks/mic/vector sum overlaid and its range passed). #2 came with the + the unit's mic overlaid, its peaks/vector sum too unless Normal range is confirmed + -- since 2026-10-31, after the checker's histogram-PVS fix -- and its range passed). #2 came with the `dev` merge. **#15 retracted** -- `sent` NULL is "unknown", by design. Final review fixes: `dbd8a91` (wake before the reconnect's identity read), `3a1d34a` ("already stored" by Blastware name too), `a72d3a9` (the 1A write diff --git a/docs/superpowers/specs/2026-10-20-sfm-series4-parity-design.md b/docs/superpowers/specs/2026-10-20-sfm-series4-parity-design.md index 34506f2..5f2a769 100644 --- a/docs/superpowers/specs/2026-10-20-sfm-series4-parity-design.md +++ b/docs/superpowers/specs/2026-10-20-sfm-series4-parity-design.md @@ -685,10 +685,12 @@ a short plan; #14 waits for the line-hold decision above. 7. `/db/events` 500 "database is locked" on the first page load against a new DB. 8. ✅ **Fixed `9492e49`**, plus `3a1d34a` ("already stored" also matches the Blastware name: a histogram's row sits a second off its 0C time). The download carries the assembled Blastware file and is - stored through `save_imported_bw` (`source.kind` "sfm-live"); the unit's 0C peaks, - mic and vector sum are overlaid (the file path reads a histogram's vector sum as - 0.503 vs 0.385, the mic as 0, and no sensitive range yet), and its range scales - the samples. The "Waveform" label waits for #41 from the checker branch. + stored through `save_imported_bw` (`source.kind` "sfm-live"), and its range scales + the samples. The unit's 0C mic is overlaid (the file reads it as 0). Its channel + peaks and vector sum were overlaid too until 2026-10-31; since the checker's + histogram-PVS fix (625bc39, merged `6945009`) the file's are taken when the unit + confirms Normal range, and the unit's stand for Sensitive or an unread range (the + file reader assumes Normal: 8x off). The label came with #41 (`a1d2b61`). **S3 downloads are stored from the live waveform decoder** (`store.save`), not the file reader that Series 4 uses (`save_imported_idf`): a histogram gets no samples and is labelled Waveform. Fix: store S3 downloads through the diff --git a/sfm/event_ingest.py b/sfm/event_ingest.py index 8480d96..64a2bf9 100644 --- a/sfm/event_ingest.py +++ b/sfm/event_ingest.py @@ -66,15 +66,23 @@ def _already_stored(dl: DownloadedEvent, row: dict) -> EventDownload: ) -def _overlay_s3_record(ev: Any, unit_peaks: Any) -> None: - """The unit's own 0C peaks, mic and vector sum over the file's. +def _overlay_s3_record(ev: Any, unit_peaks: Any, geo_range: Any) -> None: + """The unit's own 0C values over the file's, where the file's are not yet right. - Measured 2026-10-29 on BE9441: the file path reads the channel peaks right but - a histogram's vector sum as 0.503 where Blastware and the unit say 0.385 (the - decode checker's open finding), the mic as 0, and it cannot scale a sensitive - range. The unit's values are the accurate ones until the file decoder reads - them. A vector sum below the largest channel peak is impossible -- BE9441's - 0C read -0.0 for some events (bench finding #4) -- so it is not kept. + * Mic: always the unit's -- the file reads it as 0 (its psi conversion is an + open checker finding). + * Channel peaks and vector sum: the file's when the unit's settings confirm + Normal range (`geo_range` 0). The file reads them as the unit stored them + -- K441LTON.900: 0.200 / 0.385 / 0.255 and 0.385, as Blastware's report, + since the decode checker's fix (625bc39, 2026-10-31) -- while the 0C summary + is read at fixed offsets and can shift (BE9441 read 0 and -0.0 for vector + sums, bench #4). But the file reader computes every peak as if the range + were Normal, so a Sensitive unit's come out 8x off (the checker's 33 + waveforms): for Sensitive, or a range not read (a monitoring unit's 1A + carries no settings), the unit's own peaks stand, as before -- a vector + sum below the largest channel peak is impossible and is not kept. + + The 0C peaks remain the download *check* (verify_s3_download) either way. """ from minimateplus.models import PeakValues @@ -83,7 +91,12 @@ def _overlay_s3_record(ev: Any, unit_peaks: Any) -> None: if ev.peak_values is None: ev.peak_values = PeakValues() pv = ev.peak_values - for name in ("tran", "vert", "long", "micl"): + micl = getattr(unit_peaks, "micl", None) + if micl is not None: + pv.micl = micl + if geo_range in (0, "normal"): + return + for name in ("tran", "vert", "long"): value = getattr(unit_peaks, name, None) if value is not None: setattr(pv, name, value) @@ -137,8 +150,9 @@ def persist_download(dl: DownloadedEvent, *, store: Any, db: Any) -> EventDownlo else: # The same path production's watcher uses for Blastware's own files: the # event is decoded from the file (samples, histogram, setup-block sample - # rate and record time), not from the live 5A decode. The unit's own 0C - # peaks, mic and vector sum then go over the file's (_overlay_s3_record). + # rate and record time), not from the live 5A decode. The unit's 0C mic + # goes over the file's, and its peaks too unless Normal range is + # confirmed (_overlay_s3_record). if not dl.bw_bytes: raise IngestError(f"{dl.filename}: the download carried no event file; nothing was stored") geo_range = getattr(dl.compliance, "geo_range", None) if dl.compliance else None @@ -146,7 +160,7 @@ def persist_download(dl: DownloadedEvent, *, store: Any, db: Any) -> EventDownlo serial_hint=dl.serial, source_kind="sfm-live", geo_range=geo_range if geo_range is not None else "normal") if ev is not None and dl.event is not None: - _overlay_s3_record(ev, getattr(dl.event, "peak_values", None)) + _overlay_s3_record(ev, getattr(dl.event, "peak_values", None), geo_range) family = "series3" if ev is None or ev._waveform_key is None: raise IngestError(f"{dl.filename}: stored the file but could not build a database row") diff --git a/tests/test_event_ingest.py b/tests/test_event_ingest.py index 271fefc..0d7021b 100644 --- a/tests/test_event_ingest.py +++ b/tests/test_event_ingest.py @@ -307,14 +307,26 @@ def _with_unit_peaks(dl, *, tran, vert, long, micl, pvs): return dl -def test_a_series3_download_keeps_the_units_peaks_mic_and_vector_sum(sdm): +def _range(geo_range): + cc = FakeMiniMateClient().compliance + cc.geo_range = geo_range + return cc + + +def test_a_series3_download_takes_its_peaks_from_the_file_and_its_mic_from_the_unit(sdm): + # 2026-10-31: the file now reads a histogram's vector sum as the unit stored it + # (0.385 here, as Blastware's report), so the row takes the file's peaks and + # vector sum. The unit's 0C summary is read at fixed offsets and can shift + # (bench #4 read 0 / -0.0); these believable-but-wrong values must not win. + # The mic still comes from the unit: the file reads it as 0. store, db = sdm dl = _with_unit_peaks(_hist_download("K441LTON.900", "0111f210", datetime.datetime(2026, 10, 26, 17, 0, 36)), - tran=0.2, vert=0.385, long=0.255, micl=0.00058, pvs=0.38516) + tran=0.21, vert=0.36, long=0.27, micl=0.00058, pvs=0.40) # clears the old guard + dl.compliance = _range(0) # Normal, confirmed by the unit row = db.get_event(persist_download(dl, store=store, db=db).db_event_id) - assert row["peak_vector_sum"] == pytest.approx(0.38516, abs=1e-5) # Blastware: 0.385; the file path says 0.503 - assert row["mic_ppv"] == pytest.approx(0.00058, abs=1e-6) + assert row["peak_vector_sum"] == pytest.approx(0.3852, abs=1e-4) # Blastware: 0.385 assert (row["tran_ppv"], row["vert_ppv"], row["long_ppv"]) == pytest.approx((0.2, 0.385, 0.255), abs=1e-4) + assert row["mic_ppv"] == pytest.approx(0.00058, abs=1e-6) def test_an_impossible_unit_vector_sum_is_not_kept(sdm): @@ -409,3 +421,21 @@ def test_a_letterless_stored_name_still_matches_a_lettered_download(sdm): store, db = sdm _stored_as(store, db, "K441LTOK.QZ0") assert db.find_event_by_blastware_name("BE9441", "K441LTOK.QZ0H")["blastware_filename"] == "K441LTOK.QZ0" + + + +# The file reader computes every peak as if the unit were in Normal range (10 in/s); +# a Sensitive (1.25 in/s) unit's file peaks come out 8x off (the checker's 33 +# waveforms). So the file's peaks are taken only when the unit's settings confirm +# Normal -- the download check's rule; Sensitive or unread keeps the unit's own. + +@pytest.mark.parametrize("compliance", [_range(1), None], ids=["sensitive", "range-unread"]) +def test_without_a_confirmed_normal_range_the_units_peaks_stand(sdm, compliance): + store, db = sdm + dl = _with_unit_peaks(_hist_download("K441LTON.900", "0111f210", datetime.datetime(2026, 10, 26, 17, 0, 36)), + tran=0.025, vert=0.048, long=0.032, micl=0.00058, pvs=0.0481) + dl.compliance = compliance + row = db.get_event(persist_download(dl, store=store, db=db).db_event_id) + assert (row["tran_ppv"], row["vert_ppv"], row["long_ppv"]) == pytest.approx((0.025, 0.048, 0.032), abs=1e-6) + assert row["peak_vector_sum"] == pytest.approx(0.0481, abs=1e-6) + assert row["mic_ppv"] == pytest.approx(0.00058, abs=1e-6)