Merge pull request #30 from griffemi/feat-compare-place-onadd

Compare: resolve location name immediately on add
This commit is contained in:
Emi Griffith 2026-07-11 07:51:21 -07:00 committed by GitHub
commit d62c3cd61d

20
app.py
View file

@ -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"])