feat: preserve and encode raw 0C record in sidecar extensions for offline analysis
This commit is contained in:
@@ -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