fix: correct Event and PeakValues field names in ach_server serialization
Event model uses peak_values (not peaks) and project_info (not direct fields). PeakValues fields are tran/vert/long/micl/peak_vector_sum (not transverse etc). ProjectInfo fields accessed via ev.project_info.project etc. Also fix ev.timestamp serialization: use str() instead of .isoformat() since Timestamp is a custom dataclass, not datetime. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+22
-17
@@ -279,14 +279,17 @@ class AchSession:
|
|||||||
log.info(" (skipped %d already-seen event(s))", last_count)
|
log.info(" (skipped %d already-seen event(s))", last_count)
|
||||||
|
|
||||||
for i, ev in enumerate(new_events):
|
for i, ev in enumerate(new_events):
|
||||||
|
pv = ev.peak_values
|
||||||
|
pi = ev.project_info
|
||||||
log.info(
|
log.info(
|
||||||
" NEW Event %d: %s Tran=%.4f Vert=%.4f Long=%.4f VS=%.4f",
|
" NEW Event %d: %s Tran=%.4f Vert=%.4f Long=%.4f VS=%.4f project=%r",
|
||||||
last_count + i,
|
last_count + i,
|
||||||
ev.timestamp.isoformat() if ev.timestamp else "?",
|
str(ev.timestamp) if ev.timestamp else "?",
|
||||||
ev.peaks.transverse if ev.peaks else 0,
|
pv.tran if pv else 0,
|
||||||
ev.peaks.vertical if ev.peaks else 0,
|
pv.vert if pv else 0,
|
||||||
ev.peaks.longitudinal if ev.peaks else 0,
|
pv.long if pv else 0,
|
||||||
ev.peaks.vector_sum if ev.peaks else 0,
|
pv.peak_vector_sum if pv else 0,
|
||||||
|
pi.project if pi else "",
|
||||||
)
|
)
|
||||||
|
|
||||||
# Update high-water mark
|
# Update high-water mark
|
||||||
@@ -342,14 +345,16 @@ def _device_info_to_dict(d: DeviceInfo) -> dict:
|
|||||||
|
|
||||||
|
|
||||||
def _event_to_dict(e: Event) -> dict:
|
def _event_to_dict(e: Event) -> dict:
|
||||||
|
pv = e.peak_values
|
||||||
|
pi = e.project_info
|
||||||
peaks = {}
|
peaks = {}
|
||||||
if e.peaks:
|
if pv:
|
||||||
peaks = {
|
peaks = {
|
||||||
"transverse": e.peaks.transverse,
|
"transverse": pv.tran,
|
||||||
"vertical": e.peaks.vertical,
|
"vertical": pv.vert,
|
||||||
"longitudinal": e.peaks.longitudinal,
|
"longitudinal": pv.long,
|
||||||
"vector_sum": e.peaks.vector_sum,
|
"vector_sum": pv.peak_vector_sum,
|
||||||
"mic": e.peaks.mic,
|
"mic": pv.micl,
|
||||||
}
|
}
|
||||||
samples = {}
|
samples = {}
|
||||||
if e.raw_samples:
|
if e.raw_samples:
|
||||||
@@ -359,11 +364,11 @@ def _event_to_dict(e: Event) -> dict:
|
|||||||
}
|
}
|
||||||
samples["__note__"] = "first 20 sample-sets only; see raw_rx.bin for full waveform"
|
samples["__note__"] = "first 20 sample-sets only; see raw_rx.bin for full waveform"
|
||||||
return {
|
return {
|
||||||
"timestamp": e.timestamp.isoformat() if e.timestamp else None,
|
"timestamp": str(e.timestamp) if e.timestamp else None,
|
||||||
"project": e.project,
|
"project": pi.project if pi else None,
|
||||||
"client": e.client,
|
"client": pi.client if pi else None,
|
||||||
"operator": e.operator,
|
"operator": pi.operator if pi else None,
|
||||||
"sensor_location": e.sensor_location,
|
"sensor_location": pi.sensor_location if pi else None,
|
||||||
"peaks": peaks,
|
"peaks": peaks,
|
||||||
"raw_samples_preview": samples,
|
"raw_samples_preview": samples,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user