fix(sfm): a fresh Series-4 download keeps the unit's own PVS and sensor location

Without Thor's TXT report, save_imported_idf fills only the three PPVs.
The unit's 0x0C record -- already read for the list and the stale check --
also gives the peak vector sum and the sensor location, and they were
dropped: Terra-View showed a blank PVS, and find_twins (which matches on
PVS) could not link the event to its histogram twin.

persist_download now overlays DownloadedEvent.record onto the bridged
event before insert_events, filling only fields the file left empty
(creating PeakValues / ProjectInfo when absent).  Not the mic: its 0x0C
decode reads a denormal, parked.

The sidecar is written by save_imported_idf before the overlay, so it
still has no vector sum; the DB row does.  No schema change, 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-21 17:36:15 -04:00
1 parent ef096e3082
commit 157fcc51a7
2 files changed
+71

No files matched your search

+46
View File
@@ -55,6 +55,52 @@ def test_a_series4_waveform_is_stored_and_findable(sdm):
assert out.verified is True and out.sha256
def test_a_fresh_series4_download_keeps_the_units_pvs_and_sensor_location(sdm):
# Without Thor's TXT the file alone gives only the three PPVs; the unit's
# 0x0C record carries the vector sum (find_twins matches on it) and the location.
store, db = sdm
out = persist_download(s4_download("UM20147_20250531135901.IDFW",
record={"peak_vector_sum_ips": 0.391, "sensor_location": "Loc A"}),
store=store, db=db)
row = db.get_event(out.db_event_id)
assert out.inserted
assert (row["peak_vector_sum"], row["sensor_location"]) == (0.391, "Loc A")
assert row["tran_ppv"] is not None # the file's own peaks still stored
def test_the_record_fills_only_what_the_file_left_empty(sdm, monkeypatch):
store, db = sdm
real = store.save_imported_idf
def with_values(*a, **kw):
ev, rec = real(*a, **kw)
ev.peak_values.peak_vector_sum = 1.5
ev.project_info.sensor_location = "From the file"
return ev, rec
monkeypatch.setattr(store, "save_imported_idf", with_values)
out = persist_download(s4_download("UM20147_20250531135901.IDFW",
record={"peak_vector_sum_ips": 0.391, "sensor_location": "Loc A"}),
store=store, db=db)
row = db.get_event(out.db_event_id)
assert (row["peak_vector_sum"], row["sensor_location"]) == (1.5, "From the file")
def test_the_record_is_kept_even_when_the_file_gave_no_peaks_or_project(sdm, monkeypatch):
store, db = sdm
real = store.save_imported_idf
def bare(*a, **kw):
ev, rec = real(*a, **kw)
ev.peak_values = ev.project_info = None
return ev, rec
monkeypatch.setattr(store, "save_imported_idf", bare)
out = persist_download(s4_download("UM20147_20250531135901.IDFW",
record={"peak_vector_sum_ips": 0.391, "sensor_location": "Loc A"}),
store=store, db=db)
row = db.get_event(out.db_event_id)
assert (row["peak_vector_sum"], row["sensor_location"]) == (0.391, "Loc A")
def test_a_series4_histogram_is_stored(sdm):
store, db = sdm
out = persist_download(s4_download("UM20147_20250330070110.IDFH", verified=None), store=store, db=db)