test: the estimate guard's neighbour is an event of the same type (#51)
Under the unit + time + type key, the test's untyped neighbour no longer shared the imported waveform's key, so the waveform was stored as its own row -- the neighbour untouched, which is what the test's name asks. The guard's job is an estimate landing on another waveform's second, so the neighbour is now a waveform. A companion test pins the case the new key allows: an estimate beside a histogram at its second is stored alongside it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ALX2R8pghDaZuti9U7mEE9
This commit is contained in:
1 parent
ea2dfc21b7
commit
e24e77bfd0
1 file changed
+31
-3
@@ -173,13 +173,16 @@ def test_an_imported_event_with_only_an_estimate_does_not_overwrite_its_neighbou
|
||||
from sfm.database import SeismoDb
|
||||
from sfm.waveform_store import WaveformStore
|
||||
store, db = WaveformStore(tmp_path / "waveforms"), SeismoDb(tmp_path / "seismo_relay.db")
|
||||
other = Event(index=0) # a different event at 14:23:43
|
||||
# A different waveform at 14:23:43. The key is unit + time + type (#51), so
|
||||
# "its neighbour" is an event of the same type at the same second.
|
||||
other = Event(index=0)
|
||||
other.timestamp = Timestamp(raw=b"", flag=0x10, year=2026, unknown_byte=0, month=10, day=26,
|
||||
hour=14, minute=23, second=43)
|
||||
other._waveform_key = bytes.fromhex("01110000")
|
||||
other.record_type = "Waveform"
|
||||
other.peak_values = PeakValues(tran=0.01, vert=0.02, long=0.03, peak_vector_sum=0.04, micl=None)
|
||||
db.insert_events([other], serial="BE9441", device_family="series3",
|
||||
waveform_records={"01110000": {"filename": "K441LTOF.ZJ0H"}})
|
||||
waveform_records={"01110000": {"filename": "K441LTOF.ZJ0W"}})
|
||||
|
||||
broken = bytes(_broken(lambda r, i: r.__setitem__(i + 1, 0x81))) # no validated record
|
||||
ev, rec = store.save_imported_bw(broken, source_path=Path(ZI0.name))
|
||||
@@ -189,6 +192,31 @@ def test_an_imported_event_with_only_an_estimate_does_not_overwrite_its_neighbou
|
||||
waveform_records={ev._waveform_key.hex(): rec}) == (0, 1)
|
||||
with sqlite3.connect(str(db.db_path)) as c:
|
||||
assert c.execute("SELECT blastware_filename, peak_vector_sum FROM events").fetchall() == \
|
||||
[("K441LTOF.ZJ0H", 0.04)]
|
||||
[("K441LTOF.ZJ0W", 0.04)]
|
||||
assert (tmp_path / "waveforms" / "BE9441" / "K441LTOF.ZI0").exists() # the data is kept
|
||||
assert any("not merged" in r.message for r in caplog.records)
|
||||
|
||||
|
||||
def test_an_estimate_beside_a_histogram_at_its_second_is_stored_alongside(tmp_path):
|
||||
# A waveform and a histogram may share a second (#51): the estimate is its
|
||||
# own row, and the histogram is untouched.
|
||||
import sqlite3
|
||||
from minimateplus.models import Event, PeakValues, Timestamp
|
||||
from sfm.database import SeismoDb
|
||||
from sfm.waveform_store import WaveformStore
|
||||
store, db = WaveformStore(tmp_path / "waveforms"), SeismoDb(tmp_path / "seismo_relay.db")
|
||||
hist = Event(index=0)
|
||||
hist.timestamp = Timestamp(raw=b"", flag=0x10, year=2026, unknown_byte=0, month=10, day=26,
|
||||
hour=14, minute=23, second=43)
|
||||
hist._waveform_key = bytes.fromhex("01110000")
|
||||
hist.record_type = "Histogram"
|
||||
hist.peak_values = PeakValues(tran=0.01, vert=0.02, long=0.03, peak_vector_sum=0.04, micl=None)
|
||||
db.insert_events([hist], serial="BE9441", device_family="series3",
|
||||
waveform_records={"01110000": {"filename": "K441LTOF.ZJ0H"}})
|
||||
broken = bytes(_broken(lambda r, i: r.__setitem__(i + 1, 0x81))) # no validated record
|
||||
ev, rec = store.save_imported_bw(broken, source_path=Path(ZI0.name))
|
||||
assert db.insert_events([ev], serial="BE9441", device_family="series3",
|
||||
waveform_records={ev._waveform_key.hex(): rec}) == (1, 0)
|
||||
with sqlite3.connect(str(db.db_path)) as c:
|
||||
rows = c.execute("SELECT record_type, peak_vector_sum FROM events ORDER BY record_type").fetchall()
|
||||
assert rows[0] == ("Histogram", 0.04) and rows[1][0] == "Waveform"
|
||||
Reference in new issue
Block a user