Compare: resolve a location's name immediately on add
Add a lightweight GET /api/v2/place?lat=&lon= endpoint that snaps to the grid cell and returns the reverse-geocoded "neighborhood, city, region" label (the same string the view endpoints expose as place, cached + throttled). On the compare page, adding a location now fires this right away so the chip flips from coordinates to the place name immediately — instead of only resolving when the full comparison loads on Refresh. Best-effort: the series load still resolves the name, so a failed/again call is harmless. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01B3Q2EkHHnTUX2BfhV5q1Zc
This commit is contained in:
parent
7358d9eb48
commit
b0f0426b00
1 changed files with 20 additions and 0 deletions
20
app.py
20
app.py
|
|
@ -307,6 +307,25 @@ def api_geocode(q: str = Query(..., min_length=1)):
|
||||||
raise HTTPException(status_code=502, detail=f"geocoding failed: {e}")
|
raise HTTPException(status_code=502, detail=f"geocoding failed: {e}")
|
||||||
|
|
||||||
|
|
||||||
|
def api_place(
|
||||||
|
lat: float = Query(..., ge=-90, le=90),
|
||||||
|
lon: float = Query(..., ge=-180, le=180),
|
||||||
|
):
|
||||||
|
"""Best-effort neighbourhood/city label for a point — the same string the view
|
||||||
|
endpoints expose as ``place`` (snapped to the grid cell, reverse-geocoded and
|
||||||
|
cached). Resolved on its own so the compare page can show a location's name as
|
||||||
|
soon as it's added, before its full series loads."""
|
||||||
|
if not grid.in_north_america(lat, lon):
|
||||||
|
return {"place": None}
|
||||||
|
cell = grid.snap(lat, lon)
|
||||||
|
with audit.RunAudit(endpoint="place", lat=round(lat, 4), lon=round(lon, 4),
|
||||||
|
cell_id=cell["id"]) as run:
|
||||||
|
with run.phase("reverse_geocode"):
|
||||||
|
place = climate.reverse_geocode(cell["center_lat"], cell["center_lon"])
|
||||||
|
return {"place": place,
|
||||||
|
"cell": {"center_lat": cell["center_lat"], "center_lon": cell["center_lon"]}}
|
||||||
|
|
||||||
|
|
||||||
def api_grade(
|
def api_grade(
|
||||||
request: Request,
|
request: Request,
|
||||||
lat: float = Query(..., ge=-90, le=90),
|
lat: float = Query(..., ge=-90, le=90),
|
||||||
|
|
@ -669,6 +688,7 @@ v1.add_api_route("/grade", api_grade, methods=["GET"])
|
||||||
|
|
||||||
v2 = APIRouter(tags=["v2"])
|
v2 = APIRouter(tags=["v2"])
|
||||||
v2.add_api_route("/geocode", api_geocode, methods=["GET"])
|
v2.add_api_route("/geocode", api_geocode, methods=["GET"])
|
||||||
|
v2.add_api_route("/place", api_place, methods=["GET"])
|
||||||
v2.add_api_route("/grade", api_grade, methods=["GET"])
|
v2.add_api_route("/grade", api_grade, methods=["GET"])
|
||||||
v2.add_api_route("/calendar", api_calendar, methods=["GET"])
|
v2.add_api_route("/calendar", api_calendar, methods=["GET"])
|
||||||
v2.add_api_route("/day", api_day, methods=["GET"])
|
v2.add_api_route("/day", api_day, methods=["GET"])
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue