fix(decode): a Series-3 waveform's time comes from its Blastware filename

The review of this branch measured (and I re-measured) that the binary's
trigger -- ts2 minus the record time, from 1e76d08 -- is a second off on 260 of
prod's 1,394 waveforms (2026-09-30 snapshot): 199 late, 61 early.  A Blastware
filename encodes Blastware's own time to the second: it equals the report's
Event Time on 81/81 prod and 1,249/1,249 DL2 report-paired waveforms.

The cost of the second was real, not cosmetic:
- events is unique on (serial, timestamp), and on BE9558 the 61 early
  waveforms land on their histogram twin's second -- a fresh import wrote each
  waveform over its histogram's row (888 files -> 827 rows on dev);
- the release backfill would have moved 161 prod rows that v0.31.0 already had
  exactly right a second off.

Same-second collisions across all 11,827 prod-snapshot files: 61 with the
binary's times, 0 with waveform names.  Histograms keep the binary's ts1: their
name is Blastware's start time too (13,089/13,089) and ts1 runs a second early
on 97% of them, but with both on Blastware's times a waveform and its
histogram share a second 209 times -- the key cannot hold that.  Correcting
histogram times needs the key changed; not here.

- blastware_file.blastware_filename_time(): the inverse of
  blastware_filename(), V10.72 'AB0' names only, None for anything else.
- read_blastware_file(path, *, name=None): a waveform takes the name's time;
  save_imported_bw passes the upload's real name (it reads a temp file).
- insert_events' restamp matches only Blastware names (every unnamed upload is
  'imported.bw', so two events could share it) and, of several copies, moves a
  reviewed one with a time first (review items M1, M2).

Tests: the decoder (documented names, encoder round trip, other names), a
waveform's name time, a temp-named read, histograms unchanged, the twin
collision on BE9441's own ZI0 (binary 14:23:43, Blastware 14:23:42), and both
review items.  5 mutants, each caught.  Suite: only the 16 known failures.

Codec-library change: TOOL_VERSION to be bumped at release.  No schema change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MUHR251NLznsFvPSrfegqL
This commit is contained in:
serversdownandClaude Opus 5.5 committed 2026-10-26 19:15:59 -04:00
1 parent abb671a440
commit 3948dc1a3c
7 files changed
+184 -6

No files matched your search

+26
View File
@@ -130,3 +130,29 @@ def test_the_release_backfill_corrects_a_v031_row_in_place(tmp_path):
(row,) = _rows(db)
assert (row["id"], row["timestamp"], row["false_trigger"]) == (old["id"], NEW_TIME, 1)
def test_a_generic_upload_name_is_not_one_event(tmp_path):
# Unnamed uploads are all stored as "imported.bw": two different events can
# share it. Only a Blastware name says which event a row is.
db = SeismoDb(tmp_path / "seismo_relay.db")
_store(db, _event(OLD_TIME), filename="imported.bw")
_store(db, _event(NEW_TIME, key="01118a2c"), filename="imported.bw")
assert [r["timestamp"] for r in _rows(db)] == [OLD_TIME, NEW_TIME]
def test_of_two_copies_the_reviewed_one_with_a_time_is_the_one_moved(tmp_path):
db = SeismoDb(tmp_path / "seismo_relay.db")
db.insert_events([_event(OLD_TIME)], serial="BE12844", device_family="series3",
waveform_records={"0111646a": {"filename": "N844LQHB.ZT0W"}})
with sqlite3.connect(str(db.db_path)) as c: # an older copy with no time
c.execute("INSERT INTO events (id, serial, waveform_key, timestamp, blastware_filename) "
"VALUES ('untimed', 'BE12844', '0111646a', NULL, 'N844LQHB.ZT0W')")
c.execute("UPDATE events SET rowid = 0 WHERE id = 'untimed'")
reviewed = next(r["id"] for r in _rows(db) if r["timestamp"] == OLD_TIME)
db.set_false_trigger(reviewed, True)
_store(db, _event(NEW_TIME))
moved = {r["id"]: r["timestamp"] for r in _rows(db)}
assert moved[reviewed] == NEW_TIME and moved["untimed"] is None