feat(sfm): SFM's MiniMate files carry the W/H type letter Blastware's direct downloads leave off
Blastware names a direct download K441LTON.900 and only its call-in copy K441LTON.900H, so a folder of directly downloaded events cannot be sorted by kind. SFM's own files now always carry the letter. It is read from the file's own record-type byte (STRT[18], #41) by the new with_type_letter() -- not from the recording mode: BE9441's K441LTOK.R10 is a waveform that triggered 2 s into histogram K441LTOK.QZ0 (Histogram+Continuous). A file whose type does not read keeps the plain name; a name never fails a download. All three paths that name a MiniMate file SFM builds: the device-access download (the page's event list), WaveformStore.save (the legacy route's store copy, the bench call-in server), and the legacy /device/event/{i}/blastware_file download. Verified on BE9441's recorded 5A walk: 0111f210 -> K441LTON.900H, 011106a0 -> K441LTOK.R10W, byte-identical to Blastware's files. find_event_by_blastware_name tightens with it: a lettered name matches itself and the letterless form, not the other letter (a waveform and a histogram in the same second are different events); a letterless name still matches all three. Store consequence: new downloads only; rows and files stored before keep their names, and 'already stored' still finds them. No schema change, no migration. The event list shows the plain name until the event is downloaded (the type is not known before the 5A). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
This commit is contained in:
1 parent
50a0501147
commit
b6ed5f5bd5
10 files changed
+200
-21
No files matched your search
+14
-9
@@ -813,20 +813,25 @@ class SeismoDb:
|
||||
|
||||
A Blastware name encodes the serial and the event's second
|
||||
(`blastware_filename_time`), so the same name is the same event -- the
|
||||
rule `_restamp_by_file` uses. A direct download is `<stem>.<AB>0` and
|
||||
Blastware's call-in copy of the same event `<stem>.<AB>0W` / `H`; all
|
||||
three forms match. Any other name ("imported.bw") matches nothing.
|
||||
rule `_restamp_by_file` uses. Blastware's direct download is
|
||||
`<stem>.<AB>0`, its call-in copy and SFM's own files `<stem>.<AB>0W` / `H`.
|
||||
A name without the letter matches all three forms; one with it matches
|
||||
itself and the letterless form -- not the other letter, since in
|
||||
Histogram+Continuous a waveform can trigger in the second a histogram
|
||||
starts. Any other name ("imported.bw") matches nothing.
|
||||
"""
|
||||
if blastware_filename_time(filename) is None:
|
||||
return None
|
||||
base = filename.upper()
|
||||
if len(base.rsplit(".", 1)[-1]) == 4:
|
||||
base = base[:-1]
|
||||
name = filename.upper()
|
||||
if len(name.rsplit(".", 1)[-1]) == 4:
|
||||
forms = (name[:-1], name)
|
||||
else:
|
||||
forms = (name, name + "W", name + "H")
|
||||
with self._connect() as conn:
|
||||
row = conn.execute(
|
||||
"SELECT * FROM events WHERE serial = ? AND UPPER(blastware_filename) IN (?, ?, ?) "
|
||||
"ORDER BY rowid LIMIT 1",
|
||||
(serial, base, base + "W", base + "H"),
|
||||
f"SELECT * FROM events WHERE serial = ? AND UPPER(blastware_filename) IN "
|
||||
f"({', '.join('?' * len(forms))}) ORDER BY rowid LIMIT 1",
|
||||
(serial, *forms),
|
||||
).fetchone()
|
||||
return dict(row) if row else None
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import struct
|
||||
from typing import Any, Callable, Optional
|
||||
|
||||
from minimateplus import MiniMateClient
|
||||
from minimateplus.blastware_file import blastware_file_bytes, blastware_filename
|
||||
from minimateplus.blastware_file import blastware_file_bytes, blastware_filename, with_type_letter
|
||||
from minimateplus.event_file_io import _GEO_INT16_FS
|
||||
from minimateplus.framing import build_bw_write_frame
|
||||
from minimateplus.protocol import SUB_START_MONITORING, SUB_STOP_MONITORING
|
||||
@@ -408,6 +408,7 @@ class Series3Adapter:
|
||||
raise MalformedReply(
|
||||
f"event {key.hex()}: its Blastware file could not be assembled ({exc}); not saved"
|
||||
) from exc
|
||||
filename = with_type_letter(filename, bw_bytes) # ...900 -> ...900H, from the file's own bytes
|
||||
return DownloadedEvent(
|
||||
event_id=make_event_id(serial, key, found), serial=serial, series=3,
|
||||
filename=filename, verified=verified, event=ev, a5_frames=ev._a5_frames,
|
||||
|
||||
+6
-4
@@ -71,7 +71,7 @@ from minimateplus import MiniMateClient
|
||||
from minimateplus.protocol import ProtocolError
|
||||
from minimateplus.models import CallHomeConfig, ComplianceConfig, DeviceInfo, Event, PeakValues, ProjectInfo, Timestamp
|
||||
from minimateplus.transport import TcpTransport, DEFAULT_TCP_PORT
|
||||
from minimateplus.blastware_file import write_blastware_file, blastware_filename
|
||||
from minimateplus.blastware_file import blastware_file_bytes, blastware_filename, with_type_letter
|
||||
from minimateplus.client import _decode_a5_metadata_into, _decode_a5_waveform, _decode_event_count
|
||||
from minimateplus.framing import build_bw_write_frame, SESSION_RESET, POLL_PROBE, POLL_DATA
|
||||
from minimateplus.protocol import SUB_STOP_MONITORING
|
||||
@@ -1025,8 +1025,10 @@ def device_event_blastware_file(
|
||||
# Determine serial number from device info
|
||||
serial = getattr(info, "serial", None) or "UNKNOWN"
|
||||
|
||||
# Build filename using the same algorithm Blastware uses
|
||||
filename = blastware_filename(ev, serial)
|
||||
# Build filename using the same algorithm Blastware uses, plus the W/H type
|
||||
# letter its direct downloads leave off (read from the file's own bytes).
|
||||
bw_bytes = blastware_file_bytes(ev, a5_frames)
|
||||
filename = with_type_letter(blastware_filename(ev, serial), bw_bytes)
|
||||
|
||||
# Write to OS temp dir (cross-platform: /tmp on Linux/macOS,
|
||||
# %TEMP% on Windows) so FastAPI can stream it back via FileResponse.
|
||||
@@ -1040,7 +1042,7 @@ def device_event_blastware_file(
|
||||
out_path.unlink()
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
write_blastware_file(ev, a5_frames, out_path)
|
||||
out_path.write_bytes(bw_bytes)
|
||||
log.info(
|
||||
"blastware_file: wrote %s (%d A5 frames, serial=%s)",
|
||||
out_path, len(a5_frames), serial,
|
||||
|
||||
@@ -38,7 +38,7 @@ from pathlib import Path
|
||||
from typing import Optional, Union
|
||||
|
||||
from minimateplus import event_file_io
|
||||
from minimateplus.blastware_file import blastware_filename, write_blastware_file
|
||||
from minimateplus.blastware_file import blastware_file_bytes, blastware_filename, with_type_letter
|
||||
from minimateplus.framing import S3Frame
|
||||
from minimateplus.models import Event
|
||||
from sfm import event_hdf5
|
||||
@@ -75,7 +75,7 @@ class WaveformStore:
|
||||
"""
|
||||
Persistent store for Blastware-format waveform files + their A5 source frames.
|
||||
|
||||
Thread safety: write_blastware_file is single-shot; concurrent saves of the
|
||||
Thread safety: the event file is written single-shot; concurrent saves of the
|
||||
*same* filename would race, but the filename encodes second-resolution
|
||||
timestamps + serial, so collisions across threads/processes are vanishingly
|
||||
unlikely in practice.
|
||||
@@ -184,7 +184,8 @@ class WaveformStore:
|
||||
if not serial:
|
||||
raise ValueError("WaveformStore.save: serial is required")
|
||||
|
||||
filename = blastware_filename(ev, serial)
|
||||
bw_bytes = blastware_file_bytes(ev, a5_frames)
|
||||
filename = with_type_letter(blastware_filename(ev, serial), bw_bytes) # ...900 -> ...900H
|
||||
bw_path, a5_path = self.paths_for(serial, filename)
|
||||
sidecar_path = self.sidecar_path_for(serial, filename)
|
||||
hdf5_path = self.hdf5_path_for(serial, filename)
|
||||
@@ -195,7 +196,7 @@ class WaveformStore:
|
||||
bw_path.unlink()
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
write_blastware_file(ev, a5_frames, bw_path)
|
||||
bw_path.write_bytes(bw_bytes)
|
||||
filesize = bw_path.stat().st_size
|
||||
sha256 = event_file_io.file_sha256(bw_path)
|
||||
|
||||
|
||||
Reference in new issue
Block a user