feat: preserve and encode raw 0C record in sidecar extensions for offline analysis
This commit is contained in:
@@ -1362,6 +1362,20 @@ def _decode_waveform_record_into(data: bytes, event: Event) -> None:
|
||||
|
||||
Modifies event in-place.
|
||||
"""
|
||||
# ── Always preserve the raw 210 bytes ─────────────────────────────────────
|
||||
# The 0C record carries far more than just peaks + project strings:
|
||||
# ZC Freq, Time of Peak, Peak Acceleration, Peak Displacement, Vector
|
||||
# Sum Time, MicL Time of Peak, and the per-channel sensor self-check
|
||||
# results (Test Freq / Ratio / Pass-Fail) all live somewhere in this
|
||||
# 210-byte block. Their byte offsets are not yet mapped — keeping the
|
||||
# raw bytes lets us decode those fields offline once we have a paired
|
||||
# (raw 0C, BW-report) sample to fit against. Cheap to keep around
|
||||
# (210 bytes per event).
|
||||
try:
|
||||
event._raw_record = bytes(data[:210])
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# ── Record type + format detection ────────────────────────────────────────
|
||||
# `record_type` is the user-facing label ("Waveform" for any triggered
|
||||
# event regardless of timestamp-header layout). `fmt` is the internal
|
||||
|
||||
@@ -15,6 +15,7 @@ declared in `event_to_sidecar_dict()`.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import base64
|
||||
import datetime
|
||||
import hashlib
|
||||
import json
|
||||
@@ -135,6 +136,20 @@ def event_to_sidecar_dict(
|
||||
|
||||
captured_at = captured_at or datetime.datetime.utcnow()
|
||||
|
||||
# Stash raw 0C record bytes in `extensions.raw_records` so future
|
||||
# field-decoding work (Peak Acceleration, ZC Freq, Time of Peak,
|
||||
# sensor self-check results, etc.) can run offline against committed
|
||||
# sidecars without a live device. Cheap (~280 bytes base64) and
|
||||
# forward-compatible (older readers ignore unknown extensions keys).
|
||||
ext_dict: dict = dict(extensions) if extensions else {}
|
||||
raw_0c = getattr(event, "_raw_record", None)
|
||||
if raw_0c:
|
||||
rr = ext_dict.setdefault("raw_records", {})
|
||||
# Don't clobber a raw_0c that callers explicitly passed in via
|
||||
# `extensions=...` (e.g. round-trip preservation in patch_sidecar).
|
||||
rr.setdefault("waveform_record_b64", base64.b64encode(raw_0c).decode("ascii"))
|
||||
rr.setdefault("waveform_record_len", len(raw_0c))
|
||||
|
||||
return {
|
||||
"schema_version": SCHEMA_VERSION,
|
||||
"kind": SIDECAR_KIND,
|
||||
@@ -174,7 +189,7 @@ def event_to_sidecar_dict(
|
||||
"notes": "",
|
||||
},
|
||||
|
||||
"extensions": extensions or {},
|
||||
"extensions": ext_dict,
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user