merge: dev into feat/series4-sfm-parity -- v0.32.0, #42, #47/#49, #44/#45, the S3 decode checker
Brings the branch up to dev (41 commits) before the 1c bench fixes, which touch code dev changed: the histogram reader (#47/#49, bench finding #2), the v0.32.0 event-time rules, the Blastware file's setup-block fields (#44/#45), and the decode checker for verifying stored S3 downloads. One conflict: the top of the Series-III reference's change table -- both sides added rows; kept all, in date order, CRLF preserved. CLAUDE.md, README, blastware_file.py, models.py and database.py merged cleanly. Suite: the known 16 failures only (15 test_bw_ascii_report, test_save_imported_bw_without_report_ works_unchanged, which also fails on dev); 1237 passed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
This commit is contained in:
commit
342c69602d
54 files changed
+22279
-264
No files matched your search
@@ -41,6 +41,7 @@ import uuid
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
from minimateplus.blastware_file import blastware_filename_time
|
||||
from minimateplus.models import Event, MonitorLogEntry
|
||||
|
||||
log = logging.getLogger("sfm.database")
|
||||
@@ -519,6 +520,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
|
||||
@@ -547,6 +554,21 @@ class SeismoDb:
|
||||
pi = ev.project_info
|
||||
rec = wave_recs.get(key) or {}
|
||||
|
||||
if getattr(ev, "timestamp_source", None) == "estimate":
|
||||
# No validated event record: the time may be a second off,
|
||||
# so it is never allowed to move, merge into or duplicate
|
||||
# a row (_estimate_guard). The file is already stored.
|
||||
why = self._estimate_guard(conn, serial, rec.get("filename"), ts)
|
||||
if why:
|
||||
log.warning("insert_events: %s %s: %s", serial,
|
||||
rec.get("filename") or key, why)
|
||||
skipped += 1
|
||||
continue
|
||||
elif rec.get("filename") and ts and \
|
||||
self._restamp_by_file(conn, serial, rec["filename"], ts) is False:
|
||||
skipped += 1
|
||||
continue
|
||||
|
||||
try:
|
||||
conn.execute(
|
||||
"""
|
||||
@@ -704,6 +726,80 @@ class SeismoDb:
|
||||
serial, inserted, skipped)
|
||||
return inserted, skipped
|
||||
|
||||
@staticmethod
|
||||
def _estimate_guard(conn: sqlite3.Connection, serial: str, filename: Optional[str],
|
||||
ts: Optional[str]) -> Optional[str]:
|
||||
"""Why an event whose time is only an estimate must not be written, or None.
|
||||
|
||||
An estimate (the decoder found no validated event record) may be a
|
||||
second off, and (serial, timestamp) is the table's key. So it never
|
||||
moves a row, never lands on another event's row, and never adds a second
|
||||
row for an event already stored -- each refusal is logged by the caller,
|
||||
and the event's file and sidecar are already in the store. Its own
|
||||
row at the same second is refreshed as before; a free second is stored.
|
||||
"""
|
||||
named = filename if filename and blastware_filename_time(filename) is not None else None
|
||||
if named:
|
||||
own = [r[0] for r in conn.execute(
|
||||
"SELECT timestamp FROM events WHERE serial = ? AND blastware_filename = ?",
|
||||
(serial, named))]
|
||||
if own and ts not in own:
|
||||
return (f"already stored under {', '.join(str(t) for t in own)}; its estimated "
|
||||
f"time {ts} does not move or duplicate it")
|
||||
holder = conn.execute(
|
||||
"SELECT blastware_filename FROM events WHERE serial = ? AND timestamp = ?",
|
||||
(serial, ts)).fetchone()
|
||||
if holder is not None and (named is None or holder[0] != named):
|
||||
return (f"its estimated time {ts} is held by {holder[0] or 'another event'}; "
|
||||
"not merged into it")
|
||||
return None
|
||||
|
||||
@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. Any other name says nothing -- every unnamed upload is
|
||||
stored as "imported.bw" -- so only a Blastware name is matched. Of
|
||||
several rows for one file, a reviewed one with a time moves first.
|
||||
|
||||
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.
|
||||
"""
|
||||
if blastware_filename_time(filename) is None:
|
||||
return None
|
||||
mine = conn.execute(
|
||||
"SELECT id, timestamp FROM events WHERE serial = ? AND blastware_filename = ? "
|
||||
"AND (timestamp IS NULL OR timestamp != ?) "
|
||||
"ORDER BY COALESCE(false_trigger, 0) DESC, timestamp IS NULL, 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