diff --git a/app/workers/contract_check.py b/app/workers/contract_check.py index dc733b1..7526cbe 100644 --- a/app/workers/contract_check.py +++ b/app/workers/contract_check.py @@ -82,7 +82,7 @@ def _truncate_sample(payload: Any) -> dict[str, Any] | None: async def _check_token(client: TracksolidClient, *, parser_version: str) -> None: try: - await client._ensure_token() # noqa: SLF001 — intentional probe + await client._ensure_token() # intentional probe of the token endpoint except (TracksolidError, httpx.HTTPError) as exc: await _record( endpoint=TOKEN_METHOD, diff --git a/pyproject.toml b/pyproject.toml index 55a9334..29ea1fe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -47,6 +47,9 @@ ignore = ["PLR0913", "PLR2004"] [tool.ruff.lint.per-file-ignores] "tests/*" = ["PLR0913", "PLR2004"] +# One-off operational/analysis scripts: allow the long, branchy simulation +# routines that mirror the SQL trip state machine. +"scripts/*" = ["PLR0912", "PLR0915"] [tool.mypy] python_version = "3.12" diff --git a/scripts/simulate_trips_from_legacy.py b/scripts/simulate_trips_from_legacy.py index 3e774b5..adcaddc 100644 --- a/scripts/simulate_trips_from_legacy.py +++ b/scripts/simulate_trips_from_legacy.py @@ -19,8 +19,8 @@ from __future__ import annotations import json import math import sys -from collections import Counter, defaultdict -from dataclasses import dataclass, field +from collections import defaultdict +from dataclasses import dataclass from datetime import datetime, timedelta from typing import Any @@ -205,19 +205,20 @@ def legacy_summary(rows: list[dict[str, Any]]) -> dict[str, Any]: def main(path: str) -> None: - rows = json.load(open(path)) + with open(path) as f: + rows = json.load(f) print(f"\n=== {path} ===") print(f"raw rows: {len(rows)}") leg = legacy_summary(rows) - print(f"\n-- LEGACY --") + print("\n-- LEGACY --") print(f"trips: {len(leg['trips'])} (plus {leg['n_stationary_rows']} stationary-bucket rows)") for tid, t0, t1, n in leg["trips"]: dur = (t1 - t0).total_seconds() / 60 print(f" trip {tid}: {t0:%H:%M:%S} → {t1:%H:%M:%S} ({dur:.0f} min, {n} fixes)") sim = simulate(rows) - print(f"\n-- NEW ALGO (5min stop, 30min gap, 5 km/h stationary) --") + print("\n-- NEW ALGO (5min stop, 30min gap, 5 km/h stationary) --") rep = sim["reporting_time"] print(f"reporting_time: {rep.isoformat() if rep else 'none'}") print(f"day totals: distance={sim['total_distance_km']} km, "