Scope dial v2: Nearby / Region / Country / World radius on the homepage
Codex-approved evolution: the reader controls the "emotional radius" of the landing. - Census-region "Regional" grain (geo.region_of / region_states). Scope-aware tiering (queries.home_tiers): closest->widest lead, confidence-gated on state + region, never a hard filter — blends outward so the set is always full. 'world' = the global brief. - queries.home_brief takes a scope; /api/brief gains a scope param (nearby|region| country|world). Country-only / non-US homes collapse to country. - Homepage dial replaces the 2-button toggle: adaptive stops (4 with a US state, else Country/World), persisted scope, "Good news closest first" framing. Concrete, soft section labels (Around New Jersey / Across the Northeast / Across the US / Around the world) so the reader sees the dial worked. Backend 366 + frontend tests green. (Latest feed still on v1 local-first; aligning it to the dial is the immediate follow-up.) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -38,6 +38,34 @@ US_STATES = {
|
||||
"district of columbia": "DC", "washington dc": "DC", "washington d c": "DC",
|
||||
}
|
||||
|
||||
# US Census Bureau regions — the "Regional" grain for the scope dial. Standard,
|
||||
# explainable, not arbitrary. DC sits in the South (South Atlantic) per Census.
|
||||
US_REGIONS = {
|
||||
"Northeast": {"CT", "ME", "MA", "NH", "RI", "VT", "NJ", "NY", "PA"},
|
||||
"Midwest": {"IL", "IN", "MI", "OH", "WI", "IA", "KS", "MN", "MO", "NE", "ND", "SD"},
|
||||
"South": {"DE", "FL", "GA", "MD", "NC", "SC", "VA", "DC", "WV", "AL", "KY", "MS",
|
||||
"TN", "AR", "LA", "OK", "TX"},
|
||||
"West": {"AZ", "CO", "ID", "MT", "NV", "NM", "UT", "WY", "AK", "CA", "HI", "OR", "WA"},
|
||||
}
|
||||
|
||||
|
||||
def region_of(state_code: str | None) -> str | None:
|
||||
"""The Census region name containing a US state code, or None."""
|
||||
if not state_code:
|
||||
return None
|
||||
sc = state_code.upper()
|
||||
for name, states in US_REGIONS.items():
|
||||
if sc in states:
|
||||
return name
|
||||
return None
|
||||
|
||||
|
||||
def region_states(state_code: str | None) -> list[str]:
|
||||
"""Sorted state codes in the same Census region as a state (incl. it)."""
|
||||
name = region_of(state_code)
|
||||
return sorted(US_REGIONS[name]) if name else []
|
||||
|
||||
|
||||
# Common countries + aliases (extensible). Anything not here returns None -> we drop
|
||||
# the country rather than store garbage. breadth still captures national/global, etc.
|
||||
COUNTRY_TO_ISO = {
|
||||
|
||||
Reference in New Issue
Block a user