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:
1 parent
ef096e3082
commit
157fcc51a7
2 files changed
+71
No files matched your search
@@ -66,6 +66,29 @@ def _already_stored(dl: DownloadedEvent, row: dict) -> EventDownload:
|
||||
)
|
||||
|
||||
|
||||
def _overlay_s4_record(ev: Any, record: dict) -> None:
|
||||
"""Fill, where the file left them empty, what the unit's 0x0C said.
|
||||
|
||||
Without Thor's TXT report the IDF file gives only the three PPVs. The
|
||||
vector sum matters beyond display: find_twins matches on it. Not the mic:
|
||||
its 0x0C decode reads a denormal (parked).
|
||||
"""
|
||||
from minimateplus.models import PeakValues, ProjectInfo
|
||||
|
||||
pvs = record.get("peak_vector_sum_ips")
|
||||
if pvs is not None:
|
||||
if ev.peak_values is None:
|
||||
ev.peak_values = PeakValues()
|
||||
if ev.peak_values.peak_vector_sum is None:
|
||||
ev.peak_values.peak_vector_sum = pvs
|
||||
location = record.get("sensor_location")
|
||||
if location is not None:
|
||||
if ev.project_info is None:
|
||||
ev.project_info = ProjectInfo()
|
||||
if ev.project_info.sensor_location is None:
|
||||
ev.project_info.sensor_location = location
|
||||
|
||||
|
||||
def persist_download(dl: DownloadedEvent, *, store: Any, db: Any) -> EventDownload:
|
||||
# Never merge: a row for (serial, timestamp) means the event is stored, and
|
||||
# whoever stored it first keeps it. No store call, no insert, no sidecar.
|
||||
@@ -76,6 +99,8 @@ def persist_download(dl: DownloadedEvent, *, store: Any, db: Any) -> EventDownlo
|
||||
if dl.series == 4:
|
||||
ev, rec = store.save_imported_idf(dl.idf_bytes, source_path=Path(dl.filename),
|
||||
serial_hint=dl.serial)
|
||||
if ev is not None:
|
||||
_overlay_s4_record(ev, dl.record)
|
||||
family = "series4"
|
||||
else:
|
||||
ev = dl.event
|
||||
|
||||
Reference in new issue
Block a user