fix(decode): a histogram's start and stop come from its own event record (#51)

The footer's start runs a second early on 97% of histograms.  Each
histogram carries an event record like a waveform's -- lead 00 28 05 00,
source 04 00, marker fe f5, then start and stop -- and it holds
Blastware's Histogram Start and Stop on 63,490 / 63,490 DL2 histograms.
On all 63,500 there is exactly one, its start 0 or 1 s after the
footer's and its stop 0 or 1 s before; that is the validation rule.
Without a validated record the footer's start stands, as a decode
problem.

Ships with the unit + time + type key (ea2dfc2), without which a
waveform and its histogram at the same second would collide.  Three
tests that pinned the old footer start (one said 'for now', pointing at
#51) now pin the record's, which equals the file's Blastware name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ALX2R8pghDaZuti9U7mEE9
This commit is contained in:
serversdownandClaude Opus 5.5 committed 2026-11-03 21:33:32 -05:00
1 parent e24e77bfd0
commit a9bb9f08c0
5 files changed
+98 -18

No files matched your search

+5 -3
View File
@@ -141,10 +141,12 @@ def test_a_report_fills_in_when_the_record_is_missing():
assert (_dt(ev.timestamp), ev.timestamp_source) == (TRIGGER, "report")
def test_a_histogram_keeps_its_footer_start_for_now():
# Its record (marker fe f5) also holds Blastware's start -- that change is #51.
def test_a_histogram_takes_its_event_records_start():
# #51: its record (marker fe f5) holds Blastware's start; the footer's
# 19:04:50 is a second early.
ev = read_blastware_file(HISTOGRAM)
assert (_dt(ev.timestamp), ev.timestamp_source) == (datetime.datetime(2026, 5, 10, 19, 4, 50), "footer")
assert (_dt(ev.timestamp), ev.timestamp_source) == (datetime.datetime(2026, 5, 10, 19, 4, 51),
"event_record")
def test_the_sidecar_keeps_the_instruments_time_and_says_where_it_came_from():
+24
View File
@@ -471,3 +471,27 @@ def test_the_h5_carries_the_interval_detail(tmp_path):
assert int(f.attrs["histogram_interval_sec"]) == 60
assert list(f["intervals/half_period/Vert"][:]) == ev.interval_half_periods["Vert"]
assert abs(float(f["intervals/pvs_ips"][0]) - 2.644) <= 0.0005 + 1e-9
# ── #51: a histogram's start and stop from its own event record ─────────────
# The footer's start runs a second early on 97%. The histogram's event record
# (lead 00 28 05 00, source 04 00, marker fe f5) holds Blastware's start and
# stop: 63,490 / 63,490 DL2 histograms each (2026-11-03).
def test_a_histogram_starts_at_its_event_records_start():
ev = read_blastware_file(_FIX / "decode-checker-10-29-26/T004JTRF.ME0H")
t, s = ev.timestamp, ev.stop_time
# Blastware: start 2022-12-28 12:49:26, stop 12:49:33
assert (t.year, t.month, t.day, t.hour, t.minute, t.second) == (2022, 12, 28, 12, 49, 26)
assert (s.hour, s.minute, s.second) == (12, 49, 33)
assert ev.timestamp_source == "event_record"
def test_a_histogram_without_its_record_falls_back_to_the_footer_and_says_so():
raw = bytearray((_FIX / "decode-checker-10-29-26/T004JTRF.ME0H").read_bytes())
i = raw.find(b"\xfe\xf5")
raw[i] = 0x00 # break the record's marker
ev = decode_blastware_bytes(bytes(raw), name=None)
assert ev.timestamp_source == "footer"
assert ev.timestamp.second == 25 # the footer's start, a second early
assert any("histogram event record" in p for p in ev.decode_problems)
+6 -3
View File
@@ -83,9 +83,12 @@ def test_a_waveform_read_under_another_name_keeps_its_time(tmp_path):
datetime.datetime(2026, 10, 26, 14, 23, 42)
def test_a_histogram_keeps_the_binarys_window_start():
assert blastware_filename_time(HISTOGRAM.name) != datetime.datetime(2026, 5, 10, 19, 4, 50)
assert _dt(read_blastware_file(HISTOGRAM).timestamp) == datetime.datetime(2026, 5, 10, 19, 4, 50)
def test_a_histogram_now_agrees_with_its_filename():
# #51: the start comes from the histogram's own event record, which is
# Blastware's -- and so the filename's. The footer's window start (19:04:50)
# was a second early.
assert blastware_filename_time(HISTOGRAM.name) == datetime.datetime(2026, 5, 10, 19, 4, 51)
assert _dt(read_blastware_file(HISTOGRAM).timestamp) == datetime.datetime(2026, 5, 10, 19, 4, 51)
def test_an_import_no_longer_lands_a_waveform_on_its_histogram_twins_row(tmp_path):
+5 -4
View File
@@ -22,7 +22,7 @@ from minimateplus.models import Event
FIX = Path(__file__).parent / "fixtures"
WAVEFORM = FIX / "fft-oracle-2026-09-14" / "N844LQHB.ZT0W" # footer ts2 = 2026-08-25 10:33:32
HISTOGRAM = FIX / "ts-fix" / "K441LKZU.C30H" # window start 2026-05-10 19:04:50
HISTOGRAM = FIX / "ts-fix" / "K441LKZU.C30H" # start 2026-05-10 19:04:51 (#51)
def _tuple(ts):
@@ -39,9 +39,10 @@ def test_waveform_timestamp_is_exact_trigger_from_binary():
def test_histogram_timestamp_is_window_start_unchanged():
ev = read_blastware_file(HISTOGRAM)
# Histogram event time = the window start (ts1); must NOT get the waveform
# ts2 treatment (that would land ~24 h off).
assert _tuple(ev.timestamp) == (2026, 5, 10, 19, 4, 50), _tuple(ev.timestamp)
# Histogram event time = the window start, from its own event record (#51;
# the footer's ts1 is a second earlier); must NOT get the waveform ts2
# treatment (that would land ~24 h off).
assert _tuple(ev.timestamp) == (2026, 5, 10, 19, 4, 51), _tuple(ev.timestamp)
def test_a_report_does_not_override_the_instruments_event_record():