feat(sfm): a MiniMate download is checked against the unit's own peaks before it is stored
Series 4 downloads were checked (decoded PVS against the unit's); Series 3's were stored unchecked (verified=None), so BE9441's two bad files went in as successes at the bench (2026-10-25). verify_s3_download(): if the waveform decodes, all three geophone channels must be the same length and each peak must be the unit's own 0C peak to one 0.005 in/s step, or the download is refused (MalformedReply, "not saved"). Unverified (stored, as before): no waveform decode -- a histogram; 0 of ~430 fixture histograms decode as one -- or a sensitive-range unit, whose scale is still open. The reason goes in detail["check"]. A test puts the metadata-page bug back and the check refuses the file it produced. Session-replay helpers move to tests/minimate_replay.py. No codec, store or DB change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
This commit is contained in:
1 parent
75d79ece6c
commit
36f4e5d985
4 files changed
+226
-72
No files matched your search
+43
-2
@@ -9,6 +9,7 @@ from typing import Any, Callable, Optional
|
||||
|
||||
from minimateplus import MiniMateClient
|
||||
from minimateplus.blastware_file import blastware_filename
|
||||
from minimateplus.event_file_io import _GEO_INT16_FS
|
||||
from minimateplus.framing import build_bw_write_frame
|
||||
from minimateplus.protocol import SUB_START_MONITORING, SUB_STOP_MONITORING
|
||||
from minimateplus.transport import TcpTransport
|
||||
@@ -97,6 +98,45 @@ def _s3_ref(ev: Any, serial: str) -> EventRef:
|
||||
)
|
||||
|
||||
|
||||
_GEO_FULL_SCALE_IPS = 10.0 # normal range; one decoder step = 0.005 in/s
|
||||
_PEAK_TOLERANCE_IPS = 0.0051 # one 0.005 in/s step, plus the 0C's float32 slop
|
||||
|
||||
|
||||
def verify_s3_download(ev: Any, compliance: Any) -> tuple:
|
||||
"""Check a downloaded waveform against the unit's own 0C peaks: (verified, why).
|
||||
|
||||
True: all three geophone channels decode to the same length and each
|
||||
channel's peak is the unit's own to one 0.005 in/s step. None: nothing to
|
||||
check against -- no waveform decode (a histogram: none of ~430 fixture
|
||||
histograms decodes as a waveform) or a sensitive-range unit, whose scale is
|
||||
still open (the 8x discrepancy). Raises MalformedReply ("not saved")
|
||||
otherwise: a short or misassembled event must not reach the store. BE9441's
|
||||
bench (2026-10-25) stored two such events as successes before this existed.
|
||||
"""
|
||||
samples = getattr(ev, "raw_samples", None) or {}
|
||||
chans = ("Tran", "Vert", "Long")
|
||||
if not all(samples.get(c) for c in chans):
|
||||
return None, "no waveform decode to check (a histogram, or no codec for it)"
|
||||
if getattr(compliance, "geo_range", 0) not in (0, None):
|
||||
return None, "sensitive range: the sample scale is not settled, so not checked"
|
||||
lengths = {c: len(samples[c]) for c in chans}
|
||||
if len(set(lengths.values())) != 1:
|
||||
raise MalformedReply(
|
||||
f"the downloaded waveform's channels have different lengths {lengths} -- the "
|
||||
"download is incomplete or misassembled; not saved")
|
||||
pv = ev.peak_values
|
||||
unit = {"Tran": pv.tran, "Vert": pv.vert, "Long": pv.long} if pv else {}
|
||||
for c in chans:
|
||||
if unit.get(c) is None:
|
||||
return None, f"the unit's record gives no {c} peak to check against"
|
||||
decoded = max(abs(x) for x in samples[c]) * _GEO_FULL_SCALE_IPS / _GEO_INT16_FS
|
||||
if abs(decoded - unit[c]) > _PEAK_TOLERANCE_IPS:
|
||||
raise MalformedReply(
|
||||
f"the downloaded {c} peak is {decoded:.4f} in/s but the unit's own record says "
|
||||
f"{unit[c]:.4f} -- the download is incomplete or misassembled; not saved")
|
||||
return True, f"{lengths['Tran']} samples per channel, peaks match the unit's own"
|
||||
|
||||
|
||||
class Series3Adapter:
|
||||
def __init__(self, client_factory: Callable[..., Any] = default_s3_client_factory) -> None:
|
||||
self._factory = client_factory
|
||||
@@ -272,10 +312,11 @@ class Series3Adapter:
|
||||
filename = _s3_filename(ev, serial)
|
||||
if filename is None:
|
||||
raise MalformedReply(f"event {key.hex()} has no usable timestamp, so it cannot be named or stored")
|
||||
verified, why = verify_s3_download(ev, info.compliance_config)
|
||||
return DownloadedEvent(
|
||||
event_id=make_event_id(serial, key, found), serial=serial, series=3,
|
||||
filename=filename, verified=None, event=ev, a5_frames=ev._a5_frames,
|
||||
filename=filename, verified=verified, event=ev, a5_frames=ev._a5_frames,
|
||||
compliance=info.compliance_config, timestamp=_s3_dt(ev),
|
||||
detail={"a5_frames": len(ev._a5_frames)},
|
||||
detail={"a5_frames": len(ev._a5_frames), "check": why},
|
||||
)
|
||||
return self._run(address, op, timeout=S3_EVENT_TIMEOUT)
|
||||
Reference in new issue
Block a user