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

Merged
sirius merged 1 commit from wt/t_bc15eb53 into master 2026-11-20 03:52:58 +00:00
Owner

What

Per-article proximate geolocation for EVERY graded news article + new read-only GET /api/news/blips (backend lane of card t_bc15eb53; frontend=T2, live deploy=T3).

  • parse_map_scores now extracts Location/Lat/Lon/Confidence per block (clamp_coords-validated; Unknown -> no geo; coords without a place name are dropped — never invent a place).
  • Place-name-only blocks resolve via a vendored offline GeoNames gazetteer (news/summerizer/data/: cities15000 + admin1 + country->capital, CC-BY 4.0, ~1.9MB). No paid API, no Nominatim. Gazetteer hits are labelled approx.
  • article_scores gains nullable location_name/lat/lon/location_confidence (alembic 014_article_scores_geo, down_revision=013, single head) + partial bbox index (lon,lat) WHERE lat/lon NOT NULL. ensure_tables mirrors the DDL idempotently (both start orders proven).
  • GET /api/news/blips per the FROZEN contract: exact keys, dedup by article id (latest geo wins), finite lat/lon only (NaN explicitly excluded — PG sorts NaN above finite), created_at DESC, bbox (422 on malformed, same semantics as /api/news/map), since (default now-24h), limit (default 1000, max 5000). Public read allowlist like its news siblings.
  • Map prompt asks for a Confidence: line (additive; grading rubric/thresholds untouched).

Unchanged (verified by diff + tests)

/api/news/map, select_map, MAP_CAP, critical/high pins, ticker, SUMMARY_MIN_SCORE/TOP_N, dedupe_blocks, app/static/index.html, deploy/.

Evidence

  • 161 summarizer tests pass (50 new geo tests: parse with coords / place-name-only / Unknown, clamp out-of-range/NaN/inf, gazetteer city/country/disambiguation, persist sanitization).
  • 18 new blips API contract tests pass; full root suite 415 pass (1 pre-existing failure test_geofence.py::test_camera_publish_and_insert_do_not_notify — stale monkeypatch of run_camera_service.nats, present on master before this PR).
  • alembic upgrade heads clean on TWO fresh DBs (from zero, and summarizer-before-alembic / alembic-before-summarizer orders).
  • Forced ONE batch (NEWS_SUMMARIZE_FORCE=1, production model meituan/longcat-2.5:free) against a TEST DB seeded with 20 live articles: 10 blips, ALL non-critical (scores 15-50), exact contract keys; gazetteer approx path + latest-geo-wins regrade demonstrated end-to-end.
  • Coverage = articles graded going forward; NO historical backfill (per card).

Notes

  • Live app_settings.SUMMARY_MODEL is a stale placeholder "x"; the live deployment's configmap env (meituan/longcat-2.5:free) wins — test batch mirrored production. Not a repo issue; no premise corrections needed.
  • SQLAlchemy pin is >=2.0: DISTINCT ON rendered via prefix_with (works on 2.0 and 2.1; .distinct(col) is deprecated in 2.1, .ext(distinct_on) is 2.1-only).
## What Per-article proximate geolocation for EVERY graded news article + new read-only `GET /api/news/blips` (backend lane of card t_bc15eb53; frontend=T2, live deploy=T3). - `parse_map_scores` now extracts `Location/Lat/Lon/Confidence` per block (clamp_coords-validated; `Unknown` -> no geo; coords without a place name are dropped — never invent a place). - Place-name-only blocks resolve via a **vendored offline GeoNames gazetteer** (`news/summerizer/data/`: cities15000 + admin1 + country->capital, CC-BY 4.0, ~1.9MB). No paid API, no Nominatim. Gazetteer hits are labelled `approx`. - `article_scores` gains nullable `location_name/lat/lon/location_confidence` (alembic **014_article_scores_geo**, down_revision=013, single head) + partial bbox index `(lon,lat) WHERE lat/lon NOT NULL`. `ensure_tables` mirrors the DDL idempotently (both start orders proven). - `GET /api/news/blips` per the FROZEN contract: exact keys, dedup by article id (latest geo wins), finite lat/lon only (NaN explicitly excluded — PG sorts NaN above finite), `created_at DESC`, `bbox` (422 on malformed, same semantics as /api/news/map), `since` (default now-24h), `limit` (default 1000, max 5000). Public read allowlist like its news siblings. - Map prompt asks for a `Confidence:` line (additive; grading rubric/thresholds untouched). ## Unchanged (verified by diff + tests) `/api/news/map`, `select_map`, `MAP_CAP`, critical/high pins, ticker, `SUMMARY_MIN_SCORE/TOP_N`, `dedupe_blocks`, `app/static/index.html`, `deploy/`. ## Evidence - 161 summarizer tests pass (50 new geo tests: parse with coords / place-name-only / Unknown, clamp out-of-range/NaN/inf, gazetteer city/country/disambiguation, persist sanitization). - 18 new blips API contract tests pass; full root suite 415 pass (1 pre-existing failure `test_geofence.py::test_camera_publish_and_insert_do_not_notify` — stale monkeypatch of `run_camera_service.nats`, present on master before this PR). - `alembic upgrade heads` clean on TWO fresh DBs (from zero, and summarizer-before-alembic / alembic-before-summarizer orders). - Forced ONE batch (`NEWS_SUMMARIZE_FORCE=1`, production model meituan/longcat-2.5:free) against a TEST DB seeded with 20 live articles: **10 blips, ALL non-critical (scores 15-50)**, exact contract keys; gazetteer `approx` path + latest-geo-wins regrade demonstrated end-to-end. - Coverage = articles graded going forward; NO historical backfill (per card). ## Notes - Live `app_settings.SUMMARY_MODEL` is a stale placeholder "x"; the live deployment's configmap env (`meituan/longcat-2.5:free`) wins — test batch mirrored production. Not a repo issue; no premise corrections needed. - SQLAlchemy pin is >=2.0: DISTINCT ON rendered via `prefix_with` (works on 2.0 and 2.1; `.distinct(col)` is deprecated in 2.1, `.ext(distinct_on)` is 2.1-only).
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
sirius merged commit 44897a86d4 into master 2026-11-20 03:52:58 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
sirius/osint-dashboard!64
No description provided.