fix: API health check — correct TIGERweb CD field detection in admin test
Same bug as members.py: health check used old CD\d+FP$ regex (no match for CD119) and skipped GEOID. Now mirrors members.py logic: GEOID primary, STATE+CD\d+ fallback, Congressional layer filter. Authored by: Jack Levy
This commit is contained in:
@@ -473,9 +473,18 @@ def _test_rep_lookup() -> dict:
|
|||||||
r2.raise_for_status()
|
r2.raise_for_status()
|
||||||
results = r2.json().get("results", [])
|
results = r2.json().get("results", [])
|
||||||
for item in results:
|
for item in results:
|
||||||
|
if "Congressional" not in (item.get("layerName") or ""):
|
||||||
|
continue
|
||||||
attrs = item.get("attributes", {})
|
attrs = item.get("attributes", {})
|
||||||
cd_field = next((k for k in attrs if _re.match(r"CD\d+FP$", k)), None)
|
# Primary: GEOID = state FIPS (2) + district (2)
|
||||||
if cd_field:
|
geoid = str(attrs.get("GEOID") or "").strip()
|
||||||
|
if len(geoid) == 4 and geoid.isdigit():
|
||||||
|
district = str(int(geoid[2:])) if geoid[2:].strip("0") else "At-large"
|
||||||
|
return {"status": "ok", "detail": f"Nominatim + TIGERweb reachable — district {district} found for ZIP 20001"}
|
||||||
|
# Fallback: STATE + CD{session} (e.g. STATE="06", CD119="30")
|
||||||
|
state_val = attrs.get("STATE")
|
||||||
|
cd_field = next((k for k in attrs if _re.match(r"CD\d+$", k)), None)
|
||||||
|
if state_val and cd_field:
|
||||||
district = str(int(str(attrs[cd_field]))) if str(attrs[cd_field]).strip("0") else "At-large"
|
district = str(int(str(attrs[cd_field]))) if str(attrs[cd_field]).strip("0") else "At-large"
|
||||||
return {"status": "ok", "detail": f"Nominatim + TIGERweb reachable — district {district} found for ZIP 20001"}
|
return {"status": "ok", "detail": f"Nominatim + TIGERweb reachable — district {district} found for ZIP 20001"}
|
||||||
layers = [r.get("layerName") for r in results]
|
layers = [r.get("layerName") for r in results]
|
||||||
|
|||||||
Reference in New Issue
Block a user