Show source location (city/state/zip) in list_sources output
CI / test (push) Successful in 17s
CI / build-push (push) Successful in 5s

/api/data/sources now returns per-source geo; surface it as a Location column
in the sources table.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-30 11:07:34 -04:00
parent a3b77414d8
commit ffc705f485
2 changed files with 13 additions and 3 deletions
+11 -3
View File
@@ -302,18 +302,26 @@ def fmt_basis_detail(payload: dict, max_rows: int = 80) -> str:
# ---------- sources / health ----------
def _location(s: dict) -> str:
city, state = s.get("city"), s.get("state")
loc = ", ".join(p for p in (city, state) if p)
if s.get("zip"):
loc = f"{loc} {s['zip']}".strip()
return loc or ""
def fmt_sources(payload: dict) -> str:
src = payload.get("sources") or []
if not src:
return "### Sources\n\nNo active sources.\n"
lines = [
"### Tracked sources", "",
"| Source | Kind | Last success | Consecutive failures | Last error |",
"|---|---|---|---:|---|",
"| Source | Kind | Location | Last success | Consecutive failures | Last error |",
"|---|---|---|---|---:|---|",
]
for s in src:
lines.append(
f"| {s['name']} | {s['kind']} | {s.get('last_success_at') or ''} | "
f"| {s['name']} | {s['kind']} | {_location(s)} | {s.get('last_success_at') or ''} | "
f"{s.get('consecutive_failures') or 0} | {s.get('last_error') or ''} |"
)
return "\n".join(lines) + "\n"
+2
View File
@@ -200,12 +200,14 @@ def test_fmt_basis_detail_per_series():
def test_fmt_sources_table():
payload = {"sources": [
{"id": 1, "name": "Test Elev", "kind": "elevator",
"city": "Ada", "state": "OH", "zip": "45810",
"last_success_at": "2026-05-20T14:55:00+00:00",
"consecutive_failures": 0, "last_error": None},
]}
out = fmt.fmt_sources(payload)
assert "Test Elev" in out
assert "elevator" in out
assert "Ada, OH 45810" in out # location column
def test_fmt_health_buckets():