feat(gpsjam): GPS interference hex overlay API (GPSJAM/ADS-B Exchange)
GET /api/map/gpsjam?date=YYYY-MM-DD (default yesterday UTC) fetches the daily gpsjam.org H3 resolution-4 CSV, converts hexes to GeoJSON polygons, and tags each with level low|medium|high (0-2% / 2-10% / >10%) via GPSJAM's denoise formula. Whole world once, 1h TTL, graceful unavailable fallback. - overlay_catalog: add kind=geojson gpsjam stub - tests: mocked-HTTP unit + API contract (9 new)
This commit is contained in:
parent
8498945549
commit
42ca6295f0
4 changed files with 280 additions and 3 deletions
43
app/main.py
43
app/main.py
|
|
@ -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)
|
||||
|
|
@ -1682,6 +1684,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"),
|
||||
|
|
|
|||
Loading…
Reference in a new issue