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
+100
-10
@@ -18,6 +18,7 @@ from sfm.waveform_store import WaveformStore # noqa: E4
|
||||
|
||||
THOR_IDF = Path(__file__).parent / "fixtures" / "thor-idf"
|
||||
BW_FIXTURES = Path(__file__).parent / "fixtures" / "5-11-26"
|
||||
HIST_FIX = Path(__file__).parent / "fixtures" / "minimate-bench-10-26-26-histogram" / "blastware"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -182,23 +183,71 @@ class RecordingStore:
|
||||
self.saved.append((ev, serial, a5_frames, geo_range))
|
||||
return {"filename": "T193LQ9K.OE0", "filesize": 8708, "sha256": "ab" * 32}
|
||||
|
||||
def save_imported_bw(self, bw_bytes, source_path, *, serial_hint=None, bw_report_text=None,
|
||||
source_kind="bw-import", geo_range="normal"):
|
||||
self.saved.append(("imported", bw_bytes, source_path, serial_hint, source_kind))
|
||||
self.geo_range = geo_range
|
||||
ev = s3_event(0, "01110000", datetime.datetime(2026, 10, 1, 8, 0, 0))
|
||||
return ev, {"filename": source_path.name, "filesize": len(bw_bytes), "sha256": "ab" * 32}
|
||||
|
||||
def test_a_series3_event_is_backfilled_then_stored_as_series3(tmp_path):
|
||||
|
||||
def test_a_series3_download_is_stored_through_the_file_import_path(tmp_path):
|
||||
# #8: the same path production's watcher uses; data from the binary, no backfill.
|
||||
db = SeismoDb(tmp_path / "seismo.db")
|
||||
store = RecordingStore()
|
||||
fake = FakeMiniMateClient()
|
||||
ev = s3_event(0, "01110000", datetime.datetime(2026, 10, 1, 8, 0, 0))
|
||||
dl = DownloadedEvent(event_id="BE18193:01110000:20261001080000", serial="BE18193", series=3,
|
||||
filename="T193LQ9K.OE0", verified=None, event=ev, a5_frames=["frame"],
|
||||
compliance=fake.compliance, timestamp=datetime.datetime(2026, 10, 1, 8, 0, 0))
|
||||
filename="T193LQ9K.OE0", verified=None, bw_bytes=b"BW-FILE",
|
||||
event=s3_event(0, "01110000", datetime.datetime(2026, 10, 1, 8, 0, 0)),
|
||||
compliance=FakeMiniMateClient().compliance,
|
||||
timestamp=datetime.datetime(2026, 10, 1, 8, 0, 0))
|
||||
out = persist_download(dl, store=store, db=db)
|
||||
saved_ev, serial, frames, geo_range = store.saved[0]
|
||||
assert (serial, frames, geo_range) == ("BE18193", ["frame"], 0)
|
||||
assert saved_ev.sample_rate == 1024 and saved_ev.rectime_seconds == 3.0
|
||||
assert store.saved == [("imported", b"BW-FILE", Path("T193LQ9K.OE0"), "BE18193", "sfm-live")]
|
||||
assert dl.event.sample_rate is None # the live event is not backfilled
|
||||
assert db.get_event(out.db_event_id)["device_family"] == "series3"
|
||||
assert out.stored_filename == "T193LQ9K.OE0"
|
||||
|
||||
|
||||
def _hist_download(name, key, when):
|
||||
return DownloadedEvent(event_id=f"BE9441:{key}:{when:%Y%m%d%H%M%S}", serial="BE9441", series=3,
|
||||
filename=name, verified=None, bw_bytes=(HIST_FIX / name).read_bytes(),
|
||||
timestamp=when)
|
||||
|
||||
|
||||
def test_a_series3_histogram_download_is_stored_from_its_file(sdm):
|
||||
import hashlib, json
|
||||
from sfm import event_hdf5
|
||||
store, db = sdm
|
||||
dl = _hist_download("K441LTON.900", "0111f210", datetime.datetime(2026, 10, 26, 17, 0, 36))
|
||||
out = persist_download(dl, store=store, db=db)
|
||||
assert out.inserted is True
|
||||
assert out.sha256 == hashlib.sha256(dl.bw_bytes).hexdigest() # the file, byte for byte
|
||||
plot = event_hdf5.plot_json_from_hdf5(store.hdf5_path_for("BE9441", "K441LTON.900"))
|
||||
assert plot["channels"]["Tran"]["values"] # the histogram decoded
|
||||
sidecar = json.loads(store.sidecar_path_for("BE9441", "K441LTON.900").read_text())
|
||||
assert sidecar["source"]["kind"] == "sfm-live"
|
||||
assert db.get_event(out.db_event_id)["sample_rate"] == 4096
|
||||
|
||||
|
||||
def test_the_small_mic_off_histogram_is_stored_with_samples(sdm):
|
||||
# Refused on the 2026-10-29 bench; decodes since #47/#49 came in with dev.
|
||||
from sfm import event_hdf5
|
||||
store, db = sdm
|
||||
dl = _hist_download("K441LTOK.QZ0", "01110000", datetime.datetime(2026, 10, 26, 16, 6, 35))
|
||||
out = persist_download(dl, store=store, db=db)
|
||||
assert out.inserted is True
|
||||
plot = event_hdf5.plot_json_from_hdf5(store.hdf5_path_for("BE9441", "K441LTOK.QZ0"))
|
||||
assert plot["channels"]["Vert"]["values"]
|
||||
|
||||
|
||||
def test_a_repeat_series3_download_adds_no_row(sdm):
|
||||
store, db = sdm
|
||||
when = datetime.datetime(2026, 10, 26, 17, 0, 36)
|
||||
first = persist_download(_hist_download("K441LTON.900", "0111f210", when), store=store, db=db)
|
||||
again = persist_download(_hist_download("K441LTON.900", "0111f210", when), store=store, db=db)
|
||||
assert first.inserted is True and again.inserted is False
|
||||
assert len(db.query_events(serial="BE9441")) == 1
|
||||
|
||||
|
||||
def test_downloading_an_event_the_watcher_stored_writes_nothing_series3(tmp_path):
|
||||
db = SeismoDb(tmp_path / "seismo.db")
|
||||
serial, rec = watcher_import_bw(WaveformStore(tmp_path / "waveforms"), db, "M529LL1L.V70")
|
||||
@@ -221,11 +270,11 @@ def test_downloading_an_event_the_watcher_stored_writes_nothing_series3(tmp_path
|
||||
assert ev.sample_rate is None # not even backfilled
|
||||
|
||||
|
||||
def test_a_series3_download_with_no_event_stores_nothing_and_says_so(tmp_path):
|
||||
def test_a_series3_download_with_no_file_stores_nothing_and_says_so(tmp_path):
|
||||
store = RecordingStore()
|
||||
dl = DownloadedEvent(event_id="BE18193:01110000:-", serial="BE18193", series=3,
|
||||
filename="T193LQ9K.OE0", verified=None, event=None, a5_frames=["frame"])
|
||||
with pytest.raises(IngestError, match="nothing was stored"):
|
||||
with pytest.raises(IngestError, match="carried no event file; nothing was stored"):
|
||||
persist_download(dl, store=store, db=SeismoDb(tmp_path / "seismo.db"))
|
||||
assert store.saved == []
|
||||
|
||||
@@ -245,3 +294,44 @@ def test_backfill_without_settings_changes_nothing():
|
||||
ev = s3_event(0, "01110000", datetime.datetime(2026, 10, 1))
|
||||
backfill_series3_event(ev, None)
|
||||
assert ev.sample_rate is None
|
||||
|
||||
|
||||
# The file path does not yet read a histogram's vector sum the way Blastware does
|
||||
# (the checker's open finding), the mic peak, or a sensitive range, so a live
|
||||
# download keeps the unit's own 0C values for those -- the Series-4 pattern.
|
||||
|
||||
def _with_unit_peaks(dl, *, tran, vert, long, micl, pvs):
|
||||
from minimateplus.models import PeakValues
|
||||
dl.event = s3_event(0, dl.event_id.split(":")[1], dl.timestamp)
|
||||
dl.event.peak_values = PeakValues(tran=tran, vert=vert, long=long, micl=micl, peak_vector_sum=pvs)
|
||||
return dl
|
||||
|
||||
|
||||
def test_a_series3_download_keeps_the_units_peaks_mic_and_vector_sum(sdm):
|
||||
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)
|
||||
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["tran_ppv"], row["vert_ppv"], row["long_ppv"]) == pytest.approx((0.2, 0.385, 0.255), abs=1e-4)
|
||||
|
||||
|
||||
def test_an_impossible_unit_vector_sum_is_not_kept(sdm):
|
||||
# Bench finding #4: BE9441's 0C read -0.0 for a vector sum whose channels reach 1.08.
|
||||
store, db = sdm
|
||||
dl = _with_unit_peaks(_hist_download("K441LTOK.R10", "011106a0", datetime.datetime(2026, 10, 26, 16, 6, 37)),
|
||||
tran=0.25, vert=1.08, long=0.195, micl=0.0001, pvs=-0.0)
|
||||
row = db.get_event(persist_download(dl, store=store, db=db).db_event_id)
|
||||
assert row["peak_vector_sum"] == pytest.approx(1.0826, abs=1e-3) # the file's own
|
||||
|
||||
|
||||
def test_the_units_range_reaches_the_store(tmp_path):
|
||||
store = RecordingStore()
|
||||
cc = FakeMiniMateClient().compliance
|
||||
cc.geo_range = 1 # Sensitive, 1.25 in/s
|
||||
dl = DownloadedEvent(event_id="BE18193:01110000:20261001080000", serial="BE18193", series=3,
|
||||
filename="T193LQ9K.OE0", verified=None, bw_bytes=b"BW-FILE", compliance=cc,
|
||||
timestamp=datetime.datetime(2026, 10, 1, 8, 0, 0))
|
||||
persist_download(dl, store=store, db=SeismoDb(tmp_path / "seismo.db"))
|
||||
assert store.geo_range == 1
|
||||
Reference in new issue
Block a user