feat: add waveform download and storage.
This commit is contained in:
@@ -1006,6 +1006,41 @@ def db_set_false_trigger(
|
||||
return {"status": "ok", "event_id": event_id, "false_trigger": value}
|
||||
|
||||
|
||||
@app.get("/db/events/{event_id}/waveform")
|
||||
def db_event_waveform(event_id: str) -> dict:
|
||||
"""
|
||||
Return the stored waveform blob for a DB event.
|
||||
|
||||
The response shape is identical to GET /device/event/{index}/waveform so the
|
||||
waveform viewer can consume either source without modification:
|
||||
- total_samples, pretrig_samples, rectime_seconds, samples_decoded
|
||||
- sample_rate
|
||||
- peak_values (tran, vert, long, micl_psi, peak_vector_sum)
|
||||
- channels ({"Tran": [...], "Vert": [...], "Long": [...], "Mic": [...]})
|
||||
|
||||
Returns 404 if the event doesn't exist, 422 if the event exists but has no
|
||||
stored waveform (downloaded before waveform storage was implemented).
|
||||
"""
|
||||
import json as _json
|
||||
db = _get_db()
|
||||
found, blob_str = db.get_event_waveform(event_id)
|
||||
if not found:
|
||||
raise HTTPException(status_code=404, detail=f"Event {event_id} not found")
|
||||
if blob_str is None:
|
||||
raise HTTPException(
|
||||
status_code=422,
|
||||
detail=(
|
||||
f"Event {event_id} has no stored waveform. "
|
||||
"Waveform storage requires ACH server v0.11+. "
|
||||
"Re-download the event from the device to backfill."
|
||||
),
|
||||
)
|
||||
try:
|
||||
return _json.loads(blob_str)
|
||||
except Exception as exc:
|
||||
raise HTTPException(status_code=500, detail=f"Waveform blob corrupt: {exc}") from exc
|
||||
|
||||
|
||||
@app.get("/db/monitor_log")
|
||||
def db_monitor_log(
|
||||
serial: Optional[str] = Query(None, description="Filter by unit serial"),
|
||||
|
||||
Reference in New Issue
Block a user