feat: lean-Pi WS fan-out, geofences, DVR playback, fire/aircraft correlation

Phase 1: in-memory ConnectionManager viewport fan-out, 500ms map debounce,
cachetools TTLCache, background masscan/ffmpeg, compose memory caps.

Phase 2: PostGIS geofences + ST_Intersects alerts, Timescale 1-min CAGGs
and timestamp playback, FIRMS/WFIGS x firefighting ADS-B within 20 miles.

No Redis/Kafka/Celery.
This commit is contained in:
Sirius DevOps 2026-08-28 09:33:19 -04:00
commit 5ea9a4e879
28 changed files with 2318 additions and 50 deletions

View file

@ -69,6 +69,9 @@ vessel_lock = asyncio.Lock()
# Viewport-following accumulates vessels across every region visited in a
# session — keep the in-memory store bounded (oldest entries evicted).
_MAX_VESSELS = 6000
# Last ADS-B snapshot + WFIGS points for fire↔tanker correlation.
aircraft_last_known: dict[str, dict] = {}
fire_last_known: list[dict] = []
def overlay_catalog() -> dict:
@ -576,6 +579,25 @@ async def fetch_aircraft(bbox: str, limit: int = DEFAULT_LIMIT) -> list[dict]:
return transform_adsb_lol(await _get_json(url))
rows = await _ttl_get(cache_key, 8.0, _load)
from ws_manager import manager
from tracks import record_position
from geofence import record_and_notify
aircraft_last_known.clear()
for m in rows:
aircraft_last_known[str(m.get("id"))] = m
mlat, mlon = m.get("lat"), m.get("lon")
if mlat is None or mlon is None:
continue
await record_position("aircraft", m)
if manager.has_clients():
await manager.publish_point("adsb", m, lat=mlat, lon=mlon)
await record_and_notify(
source_kind="adsb", entity_id=str(m.get("id")),
lat=mlat, lon=mlon, payload=m,
)
if fire_last_known:
from fire_aircraft import correlate_and_notify
await correlate_and_notify(fire_last_known, rows)
return filter_points_bbox(rows, minlon, minlat, maxlon, maxlat, limit)
@ -613,7 +635,7 @@ async def upsert_vessel(marker: dict) -> None:
label = marker.get("label")
if not label or label == vid:
label = prev.get("label") or vid
vessel_last_known[vid] = {
stored = {
**to_marker(
vid, lat, lon,
heading=marker.get("heading") if marker.get("heading") is not None else prev.get("heading"),
@ -623,6 +645,7 @@ async def upsert_vessel(marker: dict) -> None:
),
"seen_at": datetime.now(timezone.utc).isoformat(),
}
vessel_last_known[vid] = stored
if len(vessel_last_known) > _MAX_VESSELS:
excess = len(vessel_last_known) - int(_MAX_VESSELS * 0.9)
oldest = sorted(
@ -631,6 +654,15 @@ async def upsert_vessel(marker: dict) -> None:
)[:excess]
for k in oldest:
vessel_last_known.pop(k, None)
if lat is not None and lon is not None:
from ws_manager import manager
from tracks import record_position
from geofence import record_and_notify
await manager.publish_point("ais", stored, lat=lat, lon=lon)
await record_position("vessel", stored)
await record_and_notify(
source_kind="ais", entity_id=vid, lat=lat, lon=lon, payload=stored,
)
def _wfigs_params(bbox: str | None, *, offset_m: float = 250.0) -> dict:
@ -662,6 +694,10 @@ async def fetch_fire_incidents(bbox: str | None, limit: int = DEFAULT_LIMIT) ->
return transform_wfigs_incidents(await _get_json(WFIGS_INCIDENTS, params))
rows = await _ttl_get(f"wfigs:inc:{bbox_cell_key(bbox)}", 600.0, _load)
fire_last_known[:] = list(rows)
if rows and aircraft_last_known:
from fire_aircraft import correlate_and_notify
await correlate_and_notify(rows, list(aircraft_last_known.values()))
return rows[:limit]