fix(sfm): a re-stored event at a corrected time moves its row instead of duplicating it
The waveform event-time fix (a84a46e/1e76d08, on dev since 2026-09-20) changed what time a Series-3 waveform decodes to: the trigger, where v0.31.0 stamped the monitoring-session start -- hours off. events is unique on (serial, timestamp), so re-storing an old event at its corrected time matched nothing and inserted it a second time. Measured 2026-10-26: files stored with v0.31.0 (prod's code), then dev's backfill_sidecars --force -- the release's own deploy step -- gave every waveform two rows, one at each time. N844LQHB.ZT0W (BE12844): 06:00:13 and 10:33:29, its false-trigger mark only on the wrong-time copy. A Blastware re-forward of an old event would do the same with no backfill at all. Prod has not run the new decoder, so it holds no duplicates yet. insert_events now matches a row by its stored file first (serial + blastware_filename; a Blastware name encodes the serial and the second): one under another time is moved to the new time in place -- same id, review kept -- and the usual refresh follows. When a different stored file already holds the corrected second, nothing moves and nothing is written; the old upsert wrote this event's file and peaks over that other event's row. Rows with no stored file are matched on time alone, as before. Tests: the move (id, review, refresh), a different file, no file, the collision, a duplicate already at the new time, and the release backfill end to end on a v0.31.0-shaped row. Re-checked across versions: v0.31.0 import, then this branch's backfill -- 5 real files, every row corrected in place, no duplicates. Suite: only the 16 known fixture failures. No schema change, no migration, no codec change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MUHR251NLznsFvPSrfegqL
This commit is contained in:
1 parent
6690434ecf
commit
847900baeb
2 files changed
+184
No files matched your search
@@ -397,6 +397,12 @@ class SeismoDb:
|
||||
existing row so a re-download via the live endpoint refreshes the
|
||||
file metadata.
|
||||
|
||||
An event whose stored file already has a row under a different time is
|
||||
the same event re-stored with a corrected time (the waveform event-time
|
||||
fix moved Series-3 waveforms from the session start to the trigger):
|
||||
that row is moved to the new time in place, keeping its id and review,
|
||||
rather than duplicated. See ``_restamp_by_file``.
|
||||
|
||||
``device_family`` (optional): "series3" (MiniMate Plus / Blastware) or
|
||||
"series4" (Micromate / Thor). Drives per-family UI rendering — most
|
||||
importantly the mic-unit convention (psi vs dB(L)). Set on every
|
||||
@@ -425,6 +431,11 @@ class SeismoDb:
|
||||
pi = ev.project_info
|
||||
rec = wave_recs.get(key) or {}
|
||||
|
||||
if rec.get("filename") and ts and \
|
||||
self._restamp_by_file(conn, serial, rec["filename"], ts) is False:
|
||||
skipped += 1
|
||||
continue
|
||||
|
||||
try:
|
||||
conn.execute(
|
||||
"""
|
||||
@@ -582,6 +593,47 @@ class SeismoDb:
|
||||
serial, inserted, skipped)
|
||||
return inserted, skipped
|
||||
|
||||
@staticmethod
|
||||
def _restamp_by_file(conn: sqlite3.Connection, serial: str, filename: str,
|
||||
ts: str) -> Optional[bool]:
|
||||
"""Move this file's row to `ts` when it sits under another time.
|
||||
|
||||
The events table is unique on (serial, timestamp), so an event re-stored
|
||||
with a corrected time -- every Series-3 waveform after the event-time fix,
|
||||
through the release backfill or a watcher re-forward -- matched nothing
|
||||
and was inserted a second time (measured 2026-10-26). The same stored
|
||||
file is the same event: a Blastware name encodes the serial and the time
|
||||
to the second.
|
||||
|
||||
Returns True when the row was moved; None when there was nothing to move
|
||||
(no row for this file elsewhere, or this file's own row already holds
|
||||
`ts`), so the caller goes on as before; False when a different stored
|
||||
file holds `ts` -- moving would collide, and the old upsert would write
|
||||
this event over that one -- so the caller must store nothing.
|
||||
"""
|
||||
mine = conn.execute(
|
||||
"SELECT id, timestamp FROM events WHERE serial = ? AND blastware_filename = ? "
|
||||
"AND (timestamp IS NULL OR timestamp != ?) ORDER BY rowid LIMIT 1",
|
||||
(serial, filename, ts),
|
||||
).fetchone()
|
||||
if mine is None:
|
||||
return None
|
||||
holder = conn.execute(
|
||||
"SELECT id, blastware_filename FROM events WHERE serial = ? AND timestamp = ?",
|
||||
(serial, ts),
|
||||
).fetchone()
|
||||
if holder is None:
|
||||
conn.execute("UPDATE events SET timestamp = ? WHERE id = ?", (ts, mine[0]))
|
||||
log.info("insert_events: %s %s moved from %s to %s (corrected event time)",
|
||||
serial, filename, mine[1], ts)
|
||||
return True
|
||||
if holder[1] in (None, filename):
|
||||
return None
|
||||
log.warning("insert_events: %s %s decodes to %s, which %s already holds -- "
|
||||
"row %s left at %s, nothing stored", serial, filename, ts, holder[1],
|
||||
mine[0], mine[1])
|
||||
return False
|
||||
|
||||
def get_event(self, event_id: str) -> Optional[dict]:
|
||||
"""Return one event row by id, or None."""
|
||||
with self._connect() as conn:
|
||||
|
||||
Reference in new issue
Block a user