feat(scripts): backfill event ZC freq columns from sidecars
This commit is contained in:
@@ -122,3 +122,53 @@ def test_upsert_updates_zc_freq(tmp_path: Path):
|
||||
db.insert_events([ev2], serial="BE11529")
|
||||
row = db.query_events(serial="BE11529")[0]
|
||||
assert row["vert_zc_freq"] == 91.0
|
||||
|
||||
|
||||
def test_backfill_zc_freq_from_sidecar(tmp_path: Path):
|
||||
import importlib
|
||||
mod = importlib.import_module("scripts.backfill_event_zc_freq")
|
||||
|
||||
db = SeismoDb(tmp_path / "seismo_relay.db")
|
||||
# Insert an event WITHOUT freq (simulates a pre-feature row), with a filename.
|
||||
from minimateplus.models import Event, Timestamp
|
||||
ev = Event(index=0)
|
||||
ev._waveform_key = bytes.fromhex("01110000")
|
||||
ev.timestamp = Timestamp(raw=b"", flag=0x10, year=2026, unknown_byte=0,
|
||||
month=6, day=25, hour=8, minute=50, second=0)
|
||||
ev.record_type = "Waveform"
|
||||
db.insert_events([ev], serial="BE11529",
|
||||
waveform_records={"01110000": {"filename": "M529AAAA.AB0T"}})
|
||||
|
||||
class FakeStore:
|
||||
def load_sidecar(self, serial, filename):
|
||||
return {"bw_report": {
|
||||
"peaks": {"vert": {"zc_freq_hz": 85.0},
|
||||
"tran": {"zc_freq_hz": 100.0, "zc_freq_above_range": True}},
|
||||
"mic": {"zc_freq_hz": 51.0}}}
|
||||
|
||||
counts = mod.backfill_zc_freq(db, FakeStore())
|
||||
assert counts["updated"] == 1
|
||||
row = db.query_events(serial="BE11529")[0]
|
||||
assert row["vert_zc_freq"] == 85.0
|
||||
assert row["tran_zc_above_range"] == 1
|
||||
assert row["mic_zc_freq"] == 51.0
|
||||
|
||||
|
||||
def test_backfill_skips_event_without_sidecar(tmp_path: Path):
|
||||
import importlib
|
||||
mod = importlib.import_module("scripts.backfill_event_zc_freq")
|
||||
db = SeismoDb(tmp_path / "seismo_relay.db")
|
||||
from minimateplus.models import Event, Timestamp
|
||||
ev = Event(index=0)
|
||||
ev._waveform_key = bytes.fromhex("01110000")
|
||||
ev.timestamp = Timestamp(raw=b"", flag=0x10, year=2026, unknown_byte=0,
|
||||
month=6, day=25, hour=8, minute=50, second=0)
|
||||
db.insert_events([ev], serial="BE11529",
|
||||
waveform_records={"01110000": {"filename": "M529AAAA.AB0T"}})
|
||||
|
||||
class NoneStore:
|
||||
def load_sidecar(self, serial, filename): return None
|
||||
|
||||
counts = mod.backfill_zc_freq(db, NoneStore())
|
||||
assert counts["updated"] == 0
|
||||
assert counts["skipped_no_sidecar"] == 1
|
||||
|
||||
Reference in New Issue
Block a user