Merge origin/master into Overpass nuclear infrastructure

Keep both overlay_catalog entries: infra_nuclear (this PR) and
conflicts (already on master). Disjoint layers.
This commit is contained in:
Sirius DevOps 2026-08-31 22:11:29 -04:00
commit 6c41019d6c
No known key found for this signature in database
10 changed files with 671 additions and 21 deletions

View file

@ -38,6 +38,7 @@ from models import (
)
from schemas import (
AlertCreate, AlertOut, AlertSeverity, AlertType, AlertUpdate,
ConflictZoneOut, ConflictsOut,
DashboardSummary, EntityCreate, EntityKind, EntityOut,
EventCreate, EventOut, FireOut, NewsArticleOut, NewsMapItemOut,
NewsSummaryOut, NewsTickerItemOut,
@ -1432,6 +1433,58 @@ async def map_chokepoints():
return {"chokepoints": chokepoints()}
async def _fetch_geocoded_points() -> list[tuple[float, float, datetime | None]]:
"""Collect geocoded ``(lat, lon, ts)`` rows from the local DB.
Sources are the flagged map pins (``news_items`` kind=map) and geocoded
news/GDELT events (``events`` with ``location_lat/lon``). This is the
pre-existing geocoded corpus the conflict-zone counters roll up — no
upstream scraping and no generated/jittered coordinates.
"""
async with async_session() as session:
map_rows = (
await session.execute(
select(news_items.c.lat, news_items.c.lon, news_items.c.created_at)
.where(
news_items.c.kind == "map",
news_items.c.lat.isnot(None),
news_items.c.lon.isnot(None),
)
)
).all()
event_rows = (
await session.execute(
select(events.c.location_lat, events.c.location_lon, events.c.source_timestamp)
.where(
events.c.source_type.in_(["rss", "gdel-t2"]),
events.c.location_lat.isnot(None),
events.c.location_lon.isnot(None),
)
)
).all()
return [tuple(r) for r in map_rows] + [tuple(r) for r in event_rows]
@app.get("/api/conflicts", response_model=ConflictsOut)
async def list_conflicts():
"""Curated conflict-zone catalog with per-zone event counts.
Static catalogue (severity + short factual description) merged with a live
``eventCount`` roll-up of pre-existing geocoded news/GDELT//api/news/map
rows inside each zone bbox. Empty DB → ``eventCount=0`` (never 502).
"""
from conflicts import conflict_zones, zone_event_stats
points = await _fetch_geocoded_points()
timestamp = datetime.now(timezone.utc)
zones = []
for z in conflict_zones():
bbox = z.pop("bbox")
count, latest = zone_event_stats(points, bbox)
zones.append({**z, "eventCount": count, "lastUpdated": latest})
return {"zones": zones, "timestamp": timestamp}
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