From b09a5843ce86b1a7402ab1aa1ec24b7b81adb103 Mon Sep 17 00:00:00 2001 From: "Matt Johnson (via Claude)" Date: Sun, 7 Jun 2026 07:52:36 +0000 Subject: [PATCH] fix(wfigs): add IncidentSize to acres keys and curated town_anchors lookup Acres: prepend IncidentSize to _WFIGS_ACRES_RAW_KEYS so the normalizer picks up the primary size field before falling back to DiscoveryAcres and FinalAcres. Location anchor: query the curated town_anchors table before falling back to the Photon geocoder nearest_town call, giving consistent anchor names for Idaho fires. Co-Authored-By: Claude Opus 4.6 --- meshai/central/wfigs_handler.py | 24 ++++++++++++++++++++++++ meshai/central_normalizer.py | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/meshai/central/wfigs_handler.py b/meshai/central/wfigs_handler.py index c2657e3..5086aa7 100644 --- a/meshai/central/wfigs_handler.py +++ b/meshai/central/wfigs_handler.py @@ -401,6 +401,30 @@ def _location_anchor(n: dict) -> str: lat = n.get("lat") lon = n.get("lon") if isinstance(lat, (int, float)) and isinstance(lon, (int, float)): + # Try curated town_anchors first + try: + from meshai.persistence import get_db + from meshai.central_normalizer import _haversine_miles as _haversine_mi + from meshai.central_normalizer import _bearing_compass + rows = get_db().execute( + "SELECT name, lat, lon FROM town_anchors WHERE lat IS NOT NULL AND lon IS NOT NULL" + ).fetchall() + best = None + best_d = float("inf") + for row in rows: + d = _haversine_mi(lat, lon, row["lat"], row["lon"]) + if d < best_d: + best_d = d + best = row + if best and best_d <= float(adapter_config.wfigs.anchor_max_mi): + bearing = _bearing_compass(lat, lon, best["lat"], best["lon"]) + d_int = int(round(best_d)) + if d_int < 1: + return f"near {best['name']}" + return f"{d_int} mi {bearing} of {best['name']}" + except Exception: + logger.exception("town_anchors lookup failed; falling back to Photon") + try: from meshai.central_normalizer import nearest_town nt = nearest_town(lat, lon, max_distance_mi=float(adapter_config.wfigs.anchor_max_mi)) diff --git a/meshai/central_normalizer.py b/meshai/central_normalizer.py index fe44b68..66dfdad 100644 --- a/meshai/central_normalizer.py +++ b/meshai/central_normalizer.py @@ -618,7 +618,7 @@ def _parse_wzdx_federal(inner_data: dict, geo: dict) -> dict: # them through verbatim per Matt's call -- they at least signal "new fire # in " even without an interesting name. _WFIGS_ACRES_KEYS = ("DailyAcres", "IncidentSize") -_WFIGS_ACRES_RAW_KEYS = ("DiscoveryAcres", "FinalAcres") +_WFIGS_ACRES_RAW_KEYS = ("IncidentSize", "DiscoveryAcres", "FinalAcres") _WFIGS_CONTAINED_KEYS = ("PercentContained",) _WFIGS_CONTAINED_RAW_KEYS = ("PercentContained",)