feat(db): persist per-channel ZC freq on insert/upsert
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YDXjZCr4RqT2U3QvMDhgzf
This commit is contained in:
@@ -85,3 +85,40 @@ def test_apply_bw_report_dict_copies_zc_freq():
|
||||
assert pv.vert_zc_freq == 85.0
|
||||
assert pv.tran_zc_above_range is True
|
||||
assert pv.mic_zc_freq == 51.0
|
||||
|
||||
|
||||
def _event_with_zc(waveform_key="01110000"):
|
||||
from minimateplus.models import Event, Timestamp
|
||||
ev = Event(index=0)
|
||||
ev._waveform_key = bytes.fromhex(waveform_key)
|
||||
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"
|
||||
ev.peak_values = PeakValues(
|
||||
tran=0.075, vert=0.220, long=0.045, peak_vector_sum=0.231, micl=0.01,
|
||||
tran_zc_freq=100.0, vert_zc_freq=85.0, long_zc_freq=73.0, mic_zc_freq=51.0,
|
||||
tran_zc_above_range=True,
|
||||
)
|
||||
return ev
|
||||
|
||||
|
||||
def test_insert_events_persists_zc_freq(tmp_path: Path):
|
||||
db = SeismoDb(tmp_path / "seismo_relay.db")
|
||||
ins, _ = db.insert_events([_event_with_zc()], serial="BE11529")
|
||||
assert ins == 1
|
||||
row = db.query_events(serial="BE11529")[0]
|
||||
assert row["vert_zc_freq"] == 85.0
|
||||
assert row["tran_zc_freq"] == 100.0
|
||||
assert row["tran_zc_above_range"] == 1
|
||||
assert row["vert_zc_above_range"] == 0
|
||||
assert row["mic_zc_freq"] == 51.0
|
||||
|
||||
|
||||
def test_upsert_updates_zc_freq(tmp_path: Path):
|
||||
db = SeismoDb(tmp_path / "seismo_relay.db")
|
||||
db.insert_events([_event_with_zc()], serial="BE11529")
|
||||
ev2 = _event_with_zc()
|
||||
ev2.peak_values.vert_zc_freq = 91.0 # same (serial, timestamp) → UPSERT
|
||||
db.insert_events([ev2], serial="BE11529")
|
||||
row = db.query_events(serial="BE11529")[0]
|
||||
assert row["vert_zc_freq"] == 91.0
|
||||
|
||||
Reference in New Issue
Block a user