news: per-article proximate geolocation + GET /api/news/blips

Every graded article now carries best-effort geo on article_scores:
- parse_map_scores extracts Location/Lat/Lon/Confidence per block
  (clamp_coords-validated; Unknown -> no geo; never invent a place)
- place-name-only blocks resolve via a vendored offline GeoNames
  gazetteer (cities15000 + admin1 + country->capital), confidence approx
- nullable location_name/lat/lon/location_confidence columns (alembic
  014, single head; idempotent ensure_tables mirror) + partial bbox index
- GET /api/news/blips: frozen contract, dedup by article id (latest geo
  wins), finite coords only, created_at DESC, bbox/since/limit, default
  1000 max 5000, public read like /api/news/map
- critical/high map pins, ticker, grading thresholds, dedupe unchanged

Tests: 50 new summarizer geo tests (161 total), 18 new blips API
contract tests; alembic upgrade heads proven on fresh DBs both start
orders; forced batch on test DB yielded 10 non-critical blips with geo.

Card: t_bc15eb53
This commit is contained in:
Sirius DevOps 2026-11-19 22:50:59 -05:00
commit ca1c73e1a6
16 changed files with 39639 additions and 10 deletions

View file

@ -0,0 +1,40 @@
"""article_scores geo: per-article proximate location for /api/news/blips
Revision ID: 014_article_scores_geo
Revises: 013_article_scores_duplicate_of
Create Date: 2026-11-19
Additive nullable columns on article_scores (every graded article keeps
its grading row; geo rides along when derivable). Partial bbox index for
the blips endpoint's bbox= filter. Idempotent DDL mirrors the summarizer's
ensure_tables so either start order is safe.
"""
from alembic import op
revision = "014_article_scores_geo"
down_revision = "013_article_scores_duplicate_of"
branch_labels = None
depends_on = None
def upgrade() -> None:
op.execute("ALTER TABLE article_scores ADD COLUMN IF NOT EXISTS location_name TEXT")
op.execute("ALTER TABLE article_scores ADD COLUMN IF NOT EXISTS lat DOUBLE PRECISION")
op.execute("ALTER TABLE article_scores ADD COLUMN IF NOT EXISTS lon DOUBLE PRECISION")
op.execute(
"ALTER TABLE article_scores ADD COLUMN IF NOT EXISTS location_confidence TEXT"
)
op.execute(
"CREATE INDEX IF NOT EXISTS ix_article_scores_geo_bbox "
"ON article_scores (lon, lat) "
"WHERE lat IS NOT NULL AND lon IS NOT NULL"
)
def downgrade() -> None:
op.execute("DROP INDEX IF EXISTS ix_article_scores_geo_bbox")
op.execute("ALTER TABLE article_scores DROP COLUMN IF EXISTS location_confidence")
op.execute("ALTER TABLE article_scores DROP COLUMN IF EXISTS lon")
op.execute("ALTER TABLE article_scores DROP COLUMN IF EXISTS lat")
op.execute("ALTER TABLE article_scores DROP COLUMN IF EXISTS location_name")