Merge pull request 'feat(gpsjam): GPS interference hex overlay API (GPSJAM/ADS-B Exchange)' (#29) from feat/gpsjam-interference-overlay into master
Some checks failed
build-and-deploy / build-push-deploy (push) Failing after 1h14m25s

Reviewed-on: #29
This commit is contained in:
sirius 2026-08-29 17:54:01 -04:00
commit 0406eb6b7b
4 changed files with 280 additions and 3 deletions

View file

@ -14,6 +14,7 @@ from __future__ import annotations
import asyncio
import json
import logging
import re
from contextlib import asynccontextmanager
from datetime import datetime, timedelta, timezone
from decimal import Decimal
@ -21,6 +22,7 @@ from pathlib import Path
from typing import NoReturn
from uuid import UUID
import httpx
import structlog
from fastapi import BackgroundTasks, FastAPI, HTTPException, Query, WebSocket, WebSocketDisconnect
from fastapi.middleware.gzip import GZipMiddleware
@ -53,9 +55,9 @@ from keystore import KeyFormatError, delete_key, list_keys, set_key
from settings_store import SettingsError, get_app_settings, list_models, set_summary_model
from live_layers import (
fetch_aircraft, fetch_fire_incidents, fetch_fire_perimeters,
fetch_planespotters_photo, fetch_radar_meta, fetch_sentinel1, fetch_storms,
fetch_trains, fetch_vessels, fetch_weather_alerts, overlay_catalog,
parse_bbox, UpstreamRateLimited,
fetch_gpsjam, fetch_planespotters_photo, fetch_radar_meta, fetch_sentinel1,
fetch_storms, fetch_trains, fetch_vessels, fetch_weather_alerts,
overlay_catalog, parse_bbox, UpstreamRateLimited,
)
logging.basicConfig(level=logging.INFO)
@ -1698,6 +1700,41 @@ async def list_storms():
_upstream_or_502(exc, "storms")
_GPSJAM_DATE = re.compile(r"^\d{4}-\d{2}-\d{2}$")
@app.get("/api/map/gpsjam")
async def map_gpsjam(
date: str | None = Query(None, description="YYYY-MM-DD (default: yesterday UTC)"),
):
"""GPSJAM daily GPS-interference hex layer (whole world, GeoJSON).
Red/yellow hexes correlate with suspected jamming but are NOT proof of it.
Fetched once per day from gpsjam.org (ADS-B Exchange data) and cached 1h.
"""
target = date
if target is None:
target = (datetime.now(timezone.utc) - timedelta(days=1)).strftime("%Y-%m-%d")
if not _GPSJAM_DATE.match(target):
raise HTTPException(422, "date must be YYYY-MM-DD")
try:
fc = await fetch_gpsjam(target)
except httpx.HTTPStatusError as exc:
if exc.response.status_code == 404:
return JSONResponse(
{"error": "unavailable", "href": "https://gpsjam.org/",
"date": target},
)
_upstream_or_502(exc, "gpsjam")
except Exception as exc:
_upstream_or_502(exc, "gpsjam")
if not fc.get("features"):
return JSONResponse(
{"error": "unavailable", "href": "https://gpsjam.org/", "date": target},
)
return overlay_json(fc, 3600)
@app.get("/api/map/times")
async def map_layer_times(
layer: str = Query(..., description="GIBS layer identifier, e.g. VIIRS_SNPP_CorrectedReflectance_TrueColor"),