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:
parent
5ea43a3d0b
commit
ca1c73e1a6
16 changed files with 39639 additions and 10 deletions
|
|
@ -4,7 +4,7 @@ from datetime import datetime, timezone
|
|||
from uuid import uuid4
|
||||
|
||||
from sqlalchemy import (
|
||||
Column, Enum, Float, Index, Integer, String, Text,
|
||||
Boolean, Column, Enum, Float, Index, Integer, String, Text,
|
||||
DateTime, JSON, func, Table, PrimaryKeyConstraint,
|
||||
)
|
||||
from sqlalchemy.dialects.postgresql import UUID, TSVECTOR
|
||||
|
|
@ -242,3 +242,34 @@ news_items = Table(
|
|||
Column("created_at", DateTime(timezone=True), server_default=func.now(), nullable=False),
|
||||
)
|
||||
Index("ix_news_items_kind_created", news_items.c.kind, news_items.c.created_at)
|
||||
|
||||
|
||||
# Per-article map-phase grades (alembic 012/013/014). One row per graded
|
||||
# article per run; PK (article_id, created_at) lets re-grades accumulate.
|
||||
# Geo columns are nullable: only articles with a derivable location carry
|
||||
# coordinates, served by GET /api/news/blips.
|
||||
article_scores = Table(
|
||||
"article_scores",
|
||||
metadata,
|
||||
Column("article_id", Integer, nullable=False),
|
||||
Column("summary_id", Integer),
|
||||
Column("score", Integer, nullable=False),
|
||||
Column("category", Text),
|
||||
Column("selected", Boolean, nullable=False),
|
||||
Column("model", Text),
|
||||
Column("duplicate_of", Integer),
|
||||
Column("location_name", Text),
|
||||
Column("lat", Float),
|
||||
Column("lon", Float),
|
||||
Column("location_confidence", Text),
|
||||
Column("created_at", DateTime(timezone=True),
|
||||
server_default=func.now(), nullable=False),
|
||||
PrimaryKeyConstraint("article_id", "created_at"),
|
||||
)
|
||||
Index("ix_article_scores_summary", article_scores.c.summary_id)
|
||||
Index(
|
||||
"ix_article_scores_geo_bbox",
|
||||
article_scores.c.lon, article_scores.c.lat,
|
||||
postgresql_where=article_scores.c.lat.isnot(None)
|
||||
& article_scores.c.lon.isnot(None),
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue