fix(mlg): final-review fixes
A fresh whole-branch review found four Important issues; three of its Minors and one item it set aside were re-graded up. Each has a test that failed first. - A windowed timeline 500'd when a file came without its modified time (Python 3.10 rejects the 'Z' of received_at). received_at is now +00:00 and timeline times parse 'Z' too. - On the clock-step day an event-triggered call-in moved the event into the next session and lost the step. An event now joins the 'monitoring started' record of its own file. - A call-in whose records came first in another file (a cable download) read 'nothing_new'. Each file now keeps its own call summary (last_stop, no_file_stops) from when it arrived. - Sessions and call-ins now carry record_ids / file_ids / file_id, the shot report's proof (spec 5). - A non-'started' record with no stop made the unit's timeline 500 for good; it now opens a session whose end is unknown. - A serial from a file's bytes (or a hint) could write outside the store; only plain serials are used, and records with no serial are refused, not dropped. - Times with a UTC offset, an empty 'at', or a bad mtimes value gave 500s (or stored half a request); they are now 400s, checked first. - A missing call-in file made the gap after its Modem Exit read 'not monitoring' for days. Files are numbered <serial><counter>; a gap across a missing number is now 'records missing' (unknown). A long gap after a call-in with no number missing is 'no restart after a call-in': real outages on the DL2 data (BE6907 14 days from 2026-10-07; BE8081 over Labor Day 2019). Real fixtures BE6907 #899-#902 added. - Docs: BE8081 did write one empty file (BE80811.MLG). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ALX2R9LdWawLzUxwewZGA1
This commit is contained in:
1 parent
35bac40dd5
commit
ba826dfac6
16 files changed
+359
-77
No files matched your search
+16
-11
@@ -3075,13 +3075,19 @@ async def db_import_idf_file(
|
||||
# Record and timeline times are the unit's own local clock; file times are UTC.
|
||||
|
||||
|
||||
def _parse_unit_time(value: Optional[str], name: str) -> Optional[datetime.datetime]:
|
||||
def _parse_unit_time(value: Optional[str], name: str, *, required: bool = False) -> Optional[datetime.datetime]:
|
||||
"""A time on the unit's own clock: ISO-8601 with no UTC offset. 400 otherwise."""
|
||||
if not value:
|
||||
if required:
|
||||
raise HTTPException(400, f"{name} is required (ISO-8601, the unit's clock)")
|
||||
return None
|
||||
try:
|
||||
return datetime.datetime.fromisoformat(value)
|
||||
parsed = datetime.datetime.fromisoformat(value)
|
||||
except ValueError:
|
||||
raise HTTPException(400, f"{name} is not an ISO-8601 time: {value!r}")
|
||||
if parsed.tzinfo is not None:
|
||||
raise HTTPException(400, f"{name} is on the unit's own clock and carries no UTC offset: {value!r}")
|
||||
return parsed
|
||||
|
||||
|
||||
def _mlg_timeline(serial: str) -> dict:
|
||||
@@ -3104,11 +3110,13 @@ async def db_import_mlg_file(
|
||||
not whole, or any of whose records fails its checksum, stores nothing.
|
||||
The original is kept byte for byte in the waveform store.
|
||||
"""
|
||||
try:
|
||||
file_times = json.loads(mtimes) if mtimes else {}
|
||||
if not isinstance(file_times, dict):
|
||||
try: # all of it checked before any file is stored
|
||||
raw_times = json.loads(mtimes) if mtimes else {}
|
||||
if not isinstance(raw_times, dict):
|
||||
raise ValueError("not an object")
|
||||
except ValueError as exc:
|
||||
file_times = {name: datetime.datetime.fromtimestamp(float(stamp), datetime.timezone.utc)
|
||||
for name, stamp in raw_times.items()}
|
||||
except (ValueError, TypeError, OverflowError, OSError) as exc:
|
||||
raise HTTPException(400, f"mtimes must be a JSON object of file name -> unix seconds: {exc}")
|
||||
db, store = _get_db(), _get_store()
|
||||
results: list[dict] = []
|
||||
@@ -3119,11 +3127,8 @@ async def db_import_mlg_file(
|
||||
except Exception as exc:
|
||||
results.append({"filename": name, "status": "error", "detail": f"read failed: {exc}"})
|
||||
continue
|
||||
stamp = file_times.get(name)
|
||||
file_mtime = (datetime.datetime.fromtimestamp(float(stamp), datetime.timezone.utc)
|
||||
if stamp is not None else None)
|
||||
results.append(ingest_mlg(db, store, name, data, serial_hint=serial,
|
||||
file_mtime=file_mtime, call_in=call_in))
|
||||
file_mtime=file_times.get(name), call_in=call_in))
|
||||
return {"count": len(results), "results": results}
|
||||
|
||||
|
||||
@@ -3150,7 +3155,7 @@ def db_unit_monitoring_at(
|
||||
) -> dict:
|
||||
"""Was the unit monitoring at `at`? monitoring / not_monitoring / unknown,
|
||||
with the session or gap that says so and the trigger level as logged."""
|
||||
when = _parse_unit_time(at, "at")
|
||||
when = _parse_unit_time(at, "at", required=True)
|
||||
return {"serial": serial, "at": at, **mlg_monitoring_at(_mlg_timeline(serial), when)}
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user