From b0f0426b00af55ed5a9de5c0996c8cfa872890f0 Mon Sep 17 00:00:00 2001 From: Emi Griffith Date: Sat, 11 Jul 2026 07:50:48 -0700 Subject: [PATCH] Compare: resolve a location's name immediately on add MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Claude-Session: https://claude.ai/code/session_01B3Q2EkHHnTUX2BfhV5q1Zc --- app.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/app.py b/app.py index b982371..d61614e 100644 --- a/app.py +++ b/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}") +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( request: Request, 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.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("/calendar", api_calendar, methods=["GET"]) v2.add_api_route("/day", api_day, methods=["GET"])