fix(ingest): a live download is held to its record type (#51)

Since #51 a waveform and a histogram recorded in the same second are two
events (UNIQUE(serial, timestamp, record_type)).  persist_download's
'already stored?' checks matched any row at the second and any row under
the letterless Blastware name both twins share, so a live download of
one twin was skipped as stored.  Both checks now hold to the download's
own type, read from its file (STRT[18]; IDFW / IDFH); an untyped row at
that second, or a download whose type does not read, still counts as
stored.  find_event_by_blastware_name takes an optional record_type.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
This commit is contained in:
serversdownandClaude Opus 5.5 committed 2026-11-04 12:34:46 -05:00
1 parent f24913189b
commit 2d237be5ef
3 files changed
+87 -9

No files matched your search

+42
View File
@@ -499,3 +499,45 @@ def test_a_letterless_stored_name_still_matches_a_lettered_download(sdm):
store, db = sdm
_stored_as(store, db, "K441LTOK.QZ0")
assert db.find_event_by_blastware_name("BE9441", "K441LTOK.QZ0H")["blastware_filename"] == "K441LTOK.QZ0"
# #51 (dev, 2026-11-03): a waveform and a histogram recorded in the same second
# are two events (UNIQUE(serial, timestamp, record_type)). A live download of one
# must not be skipped because its twin is stored -- not by the time, and not by a
# letterless Blastware name both twins share. An untyped row at that second still
# counts as stored (conservatively: it may be this event).
def _stored_twin(store, db, name, record_type):
ev, rec = store.save_imported_bw((HIST_FIX / "K441LTOK.QZ0").read_bytes(),
source_path=Path(name), serial_hint=None,
bw_report_text=(HIST_FIX / "K441LTOK_QZ0_ASCII.TXT").read_bytes())
ev.record_type = record_type
db.insert_events([ev], serial="BE9441", waveform_records={ev._waveform_key.hex(): rec},
device_family="series3")
@pytest.mark.parametrize("twin_name", ["K441LTOK.QZ0W", "K441LTOK.QZ0"]) # call-in / direct name
def test_a_live_histogram_is_stored_beside_its_same_second_waveform_twin(sdm, twin_name):
store, db = sdm
_stored_twin(store, db, twin_name, "Waveform")
dl = _hist_download("K441LTOK.QZ0", "01110000", datetime.datetime(2026, 10, 26, 16, 6, 35))
dl.filename = "K441LTOK.QZ0H" # a live download carries the letter (s3.py: with_type_letter)
out = persist_download(dl, store=store, db=db)
assert out.inserted is True
assert sorted(r["record_type"] for r in db.query_events(serial="BE9441")) == ["Histogram", "Waveform"]
def test_an_untyped_row_at_that_second_still_counts_as_stored(sdm):
store, db = sdm
_stored_twin(store, db, "K441LTOK.QZ0", None)
out = persist_download(_hist_download("K441LTOK.QZ0", "01110000",
datetime.datetime(2026, 10, 26, 16, 6, 35)), store=store, db=db)
assert out.inserted is False and out.detail["already_stored"] is True
def test_the_name_lookup_can_be_held_to_a_record_type(sdm):
store, db = sdm
_stored_twin(store, db, "K441LTOK.QZ0", "Waveform")
assert db.find_event_by_blastware_name("BE9441", "K441LTOK.QZ0H", record_type="Histogram") is None
assert db.find_event_by_blastware_name("BE9441", "K441LTOK.QZ0", record_type="waveform") is not None
assert db.find_event_by_blastware_name("BE9441", "K441LTOK.QZ0") is not None