feat(map): chokepoint preset catalog + vessels ?src= filter

- GET /api/map/chokepoints: static five-strait fly-to catalog (Hormuz, Bab
  el-Mandeb, Suez, Malacca, Taiwan) with bbox/center/zoom/vesselapi. No
  VesselAPI calls; only Hormuz flags vesselapi=true.
- GET /api/vessels?src=aisstream|vesselapi|all (default all) filters the
  union store by provider so a Hormuz view skips ~5k CONUS AISStream rows.
- Tests: span validation of all five boxes, catalog 200 shape, src filter.
This commit is contained in:
Sirius DevOps 2026-08-29 14:03:15 -04:00
commit ef8b877d21
4 changed files with 208 additions and 2 deletions

View file

@ -1400,6 +1400,17 @@ async def map_layers():
return {"layers": MAP_LAYERS, "overlays": overlay_catalog()}
@app.get("/api/map/chokepoints")
async def map_chokepoints():
"""Static one-tap fly-to presets (Strait of Hormuz, Bab el-Mandeb, …).
Pure catalog — no upstream calls and no VesselAPI quota spend. ``vesselapi``
is True only for Hormuz (the box the VesselAPI poller already covers).
"""
from chokepoints import chokepoints
return {"chokepoints": chokepoints()}
def _upstream_or_502(exc: Exception, name: str) -> NoReturn:
logger.warning("live_layer_upstream_failed", layer=name, error=str(exc))
raise HTTPException(502, f"{name} upstream unavailable: {exc}") from exc
@ -1499,13 +1510,18 @@ async def list_vessels(
bbox: str | None = Query(None, description="minlon,minlat,maxlon,maxlat"),
limit: int = Query(2000, ge=1, le=5000),
timestamp: str | None = Query(None, description="ISO time — DVR 1-min tracks instead of live"),
src: str | None = Query(None, description="aisstream|vesselapi|all (default all)"),
):
"""AIS last-known — union of two independent providers.
AISStream (extra.src="aisstream", live US-coast WebSocket) and VesselAPI
(extra.src="vesselapi", Strait of Hormuz 5×/day poll) both upsert into the
same store. Empty without either key / until the first successful poll.
``src`` filters the union to one provider (default ``all``) so a Hormuz
view can skip the ~5k CONUS AISStream rows.
"""
if src is not None and src not in ("aisstream", "vesselapi", "all"):
raise HTTPException(422, "src must be one of: aisstream, vesselapi, all")
if bbox:
_parse_bbox_query(bbox)
try:
@ -1513,7 +1529,7 @@ async def list_vessels(
ts = parse_timestamp(timestamp)
if ts is not None:
return overlay_json(await fetch_positions_at("vessel", ts, bbox, limit), 5)
return overlay_json(await fetch_vessels(bbox, limit), 5)
return overlay_json(await fetch_vessels(bbox, limit, src=src), 5)
except ValueError as exc:
raise HTTPException(422, str(exc)) from exc