fix(sfm): store a MiniMate download through the Blastware-file import path, as production does (#8)
A live Series-3 download was stored from the live 5A decode (store.save): a histogram got no samples and nothing to plot (bench 2026-10-29). The download now carries the assembled Blastware file (DownloadedEvent.bw_bytes, built by the new blastware_file_bytes -- byte-identical to Blastware's own K441LTON.900 and K441LTOK.R10), and persist_download stores it through save_imported_bw, the path the watcher uses for Blastware's files, the way Series 4 already uses save_imported_idf. The event is decoded from the file: histogram samples, setup-block sample rate and record time (#44/#45). source.kind is 'sfm-live'. The file path does not yet read three things right (measured on BE9441): a histogram's vector sum (0.503 where Blastware and the unit say 0.385 -- the decode checker's open finding), the mic peak (0), and a sensitive range. So the unit's own 0C channel peaks, mic and vector sum are overlaid, as Series 4 does, except an impossible vector sum (below the largest channel; BE9441's 0C read -0.0, bench #4), and the unit's range is passed through for the stored samples. Store consequence: new live MiniMate downloads only; existing rows and files are untouched; no backfill, no migration. The record type still reads 'Waveform' for a live histogram until #41 (record type from STRT[18]) lands from the decode checker's branch. 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
ce441a0911
commit
9492e49400
8 files changed
+180
-32
No files matched your search
@@ -126,6 +126,7 @@ class DownloadedEvent:
|
||||
filename: str
|
||||
verified: Optional[bool]
|
||||
idf_bytes: Optional[bytes] = field(default=None, repr=False)
|
||||
bw_bytes: Optional[bytes] = field(default=None, repr=False) # Series 3: the assembled Blastware file
|
||||
event: Any = field(default=None, repr=False)
|
||||
a5_frames: Optional[list] = field(default=None, repr=False)
|
||||
compliance: Any = field(default=None, repr=False)
|
||||
|
||||
@@ -8,7 +8,7 @@ import struct
|
||||
from typing import Any, Callable, Optional
|
||||
|
||||
from minimateplus import MiniMateClient
|
||||
from minimateplus.blastware_file import blastware_filename
|
||||
from minimateplus.blastware_file import blastware_file_bytes, 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
|
||||
@@ -398,9 +398,16 @@ class Series3Adapter:
|
||||
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)
|
||||
try:
|
||||
bw_bytes = blastware_file_bytes(ev, ev._a5_frames)
|
||||
except ValueError as exc:
|
||||
raise MalformedReply(
|
||||
f"event {key.hex()}: its Blastware file could not be assembled ({exc}); not saved"
|
||||
) from exc
|
||||
return DownloadedEvent(
|
||||
event_id=make_event_id(serial, key, found), serial=serial, series=3,
|
||||
filename=filename, verified=verified, event=ev, a5_frames=ev._a5_frames,
|
||||
bw_bytes=bw_bytes,
|
||||
compliance=info.compliance_config, timestamp=_s3_dt(ev),
|
||||
detail={"a5_frames": len(ev._a5_frames), "check": why},
|
||||
)
|
||||
|
||||
+38
-6
@@ -66,6 +66,33 @@ 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.
|
||||
|
||||
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.
|
||||
"""
|
||||
from minimateplus.models import PeakValues
|
||||
|
||||
if unit_peaks is None:
|
||||
return
|
||||
if ev.peak_values is None:
|
||||
ev.peak_values = PeakValues()
|
||||
pv = ev.peak_values
|
||||
for name in ("tran", "vert", "long", "micl"):
|
||||
value = getattr(unit_peaks, name, None)
|
||||
if value is not None:
|
||||
setattr(pv, name, value)
|
||||
pvs = getattr(unit_peaks, "peak_vector_sum", None)
|
||||
largest = max((getattr(unit_peaks, n, None) or 0.0) for n in ("tran", "vert", "long"))
|
||||
if pvs is not None and pvs > 0 and pvs >= largest - 0.005:
|
||||
pv.peak_vector_sum = pvs
|
||||
|
||||
|
||||
def _overlay_s4_record(ev: Any, record: dict) -> None:
|
||||
"""Fill, where the file left them empty, what the unit's 0x0C said.
|
||||
|
||||
@@ -103,13 +130,18 @@ def persist_download(dl: DownloadedEvent, *, store: Any, db: Any) -> EventDownlo
|
||||
_overlay_s4_record(ev, dl.record)
|
||||
family = "series4"
|
||||
else:
|
||||
ev = dl.event
|
||||
if ev is None:
|
||||
raise IngestError(f"{dl.filename}: the download carried no event; nothing was stored")
|
||||
backfill_series3_event(ev, dl.compliance)
|
||||
# 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 0C peaks
|
||||
# stay what they were -- the download *check* (verify_s3_download).
|
||||
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
|
||||
rec = store.save(ev, serial=dl.serial, a5_frames=dl.a5_frames,
|
||||
geo_range=geo_range if geo_range is not None else "normal")
|
||||
ev, rec = store.save_imported_bw(dl.bw_bytes, source_path=Path(dl.filename),
|
||||
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))
|
||||
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")
|
||||
|
||||
@@ -296,6 +296,8 @@ class WaveformStore:
|
||||
*,
|
||||
serial_hint: Optional[str] = None,
|
||||
bw_report_text: Optional[Union[str, bytes]] = None,
|
||||
source_kind: str = "bw-import",
|
||||
geo_range: Union[str, int] = "normal",
|
||||
) -> tuple[Event, dict]:
|
||||
"""
|
||||
Ingest a Blastware event file produced by an external tool
|
||||
@@ -413,7 +415,9 @@ class WaveformStore:
|
||||
event_hdf5.write_event_hdf5(
|
||||
hdf5_path, ev,
|
||||
serial=serial,
|
||||
geo_range="normal", # BW file doesn't carry the range; assume Normal
|
||||
# The BW file doesn't carry the range (yet); an import assumes Normal,
|
||||
# a live download passes the unit's own (event_ingest).
|
||||
geo_range=geo_range,
|
||||
source_kind="bw-import",
|
||||
)
|
||||
hdf5_filename = hdf5_path.name
|
||||
@@ -438,7 +442,7 @@ class WaveformStore:
|
||||
blastware_filename=filename,
|
||||
blastware_filesize=filesize,
|
||||
blastware_sha256=sha256,
|
||||
source_kind="bw-import",
|
||||
source_kind=source_kind, # "sfm-live" for SFM's own downloads (event_ingest)
|
||||
a5_pickle_filename=None,
|
||||
txt_filename=txt_filename,
|
||||
review=existing_review,
|
||||
|
||||
Reference in new issue
Block a user