fix(sfm): a MiniMate download's peaks come from its file when the unit confirms Normal range

Since the decode checker's histogram-PVS fix (625bc39, merged 6945009) the file
reads a histogram's vector sum as the unit stored it: K441LTON.900 stores
0.200 / 0.385 / 0.255 and a vector sum of 0.3852, as Blastware's report (was
0.503).  The 0C summary, read at fixed offsets, can shift (BE9441 read 0 and
-0.0, bench #4) -- and a shifted value can look plausible and pass the
impossible-value guard.  So the row now takes the file's channel peaks and
vector sum.

Only when the unit's settings confirm Normal range: the file reader computes
every peak as if the range were Normal (_GEO_SENSITIVE_FS_INS is defined but
unused), so a Sensitive unit's file peaks are 8x off (the checker's 33
waveforms).  For Sensitive, or a range not read (a monitoring unit's 1A has no
settings), the unit's own peaks stand, as before.  The mic is always the
unit's: the file still reads it as 0.  The 0C peaks remain the download check.

Store consequence: new live downloads only; no backfill, no migration.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
This commit is contained in:
serversdownandClaude Opus 5.5 committed 2026-10-31 00:17:57 -04:00
1 parent 69450093f6
commit 0a87d85202
4 files changed
+68 -21

No files matched your search

+26 -12
View File
@@ -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")