From 8fb7655b3f17530c4438cdf89814f98f726fc6cf Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Fri, 17 Jul 2026 22:00:00 +0000 Subject: [PATCH] chore(central-ripout 2c): relocate gauge sites to env/gauge_sites.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Moves the last non-fire live file out of central/. idaho_gauge_sites.py held USGS stream-gauge site data + threshold ranking — pure hydro/gauge domain, misfiled among the retired Central handlers. Applied the owner's rule with a clean split: - THRESHOLD_RANK (a 5-element list used ONLY by notifications/gating/hydro.py) inlined there — single consumer, belongs next to its use. - The gauge-site lookup (used by env/usgs.py + persistence/curation.py) moved to env/gauge_sites.py, next to the usgs adapter that produces gauge data. - Dropped the redundant "idaho_" prefix (the Idaho scoping is data, not code). Consumers rewired: env/usgs.py, notifications/gating/hydro.py, and tests. central/ is now down to firms_handler.py + wfigs_handler.py (the fire pair, whose relocation is a separate PR because of their cross-file coupling). Move + import-rewire only, no behavior change. Suite: 2059 passed, 0 failed. Co-Authored-By: Claude Opus 4.8 (1M context) --- work/meshai/central/__init__.py | 8 ++++---- .../idaho_gauge_sites.py => env/gauge_sites.py} | 15 ++++++++------- work/meshai/env/usgs.py | 10 +++++----- work/meshai/notifications/gating/hydro.py | 7 ++++++- work/tests/test_hydro_refactor.py | 4 ++-- 5 files changed, 25 insertions(+), 19 deletions(-) rename work/meshai/{central/idaho_gauge_sites.py => env/gauge_sites.py} (80%) diff --git a/work/meshai/central/__init__.py b/work/meshai/central/__init__.py index d4fcda5..e87a682 100644 --- a/work/meshai/central/__init__.py +++ b/work/meshai/central/__init__.py @@ -2,7 +2,7 @@ JetStream firehose and normalized it into meshai pipeline Events. The NATS consumer is retired (Central is gone); this package now only holds the split-file modules still used by the native adapter paths (firms_handler, -wfigs_handler _render, idaho_gauge_sites). The satellite pieces -(satpass_handler, tle_handler, pass_predictor) have moved to -meshai.env.satellite — they're feed-adapter support code, not consumer -leftovers.""" +wfigs_handler _render). The satellite pieces (satpass_handler, tle_handler, +pass_predictor) have moved to meshai.env.satellite, and the gauge-site +lookups have moved to meshai.env.gauge_sites — they're feed-adapter support +code, not consumer leftovers.""" diff --git a/work/meshai/central/idaho_gauge_sites.py b/work/meshai/env/gauge_sites.py similarity index 80% rename from work/meshai/central/idaho_gauge_sites.py rename to work/meshai/env/gauge_sites.py index 392cb8a..cab1f85 100644 --- a/work/meshai/central/idaho_gauge_sites.py +++ b/work/meshai/env/gauge_sites.py @@ -1,4 +1,4 @@ -"""v0.6-4 Idaho gauge-site lookups (now backed by gauge_sites table). +"""v0.6-4 gauge-site lookups (now backed by gauge_sites table). The IDAHO_CURATED_SITES Python dict was migrated to the gauge_sites SQLite table in v8.sql. seed_gauge_sites() (called from init_db on first boot) @@ -6,18 +6,19 @@ populates the table with the original 9 sites. The lookup helpers below read from the table via meshai.persistence.curation. Module exports retained for backward-compat with existing tests: - lookup_site, normalize_site_id, THRESHOLD_RANK, compute_threshold_state. + lookup_site, normalize_site_id, compute_threshold_state. The IDAHO_CURATED_SITES name itself is gone -- new code should call lookup_site() (DB-backed) or the curation accessor directly. + +(Relocated from meshai/central/idaho_gauge_sites.py -- Central is gone; +this is pure hydro/gauge domain code, not a Central handler. The "idaho_" +prefix was dropped on the move: the data is Idaho-scoped but the code +itself is generic gauge/threshold logic. THRESHOLD_RANK, formerly exported +here, was inlined into its sole consumer, meshai.notifications.gating.hydro.) """ from typing import Optional -# Ordered list of threshold names from low to high. Used to compare -# "is current threshold higher than prior" (upward crossing detection). -THRESHOLD_RANK = ["normal", "action", "flood_minor", "flood_moderate", "flood_major"] - - def normalize_site_id(raw: Optional[str]) -> Optional[str]: """Accept 'USGS-13139510', 'USGS:13139510', '13139510', etc. Return the canonical 'USGS-' form so the curation table lookups succeed.""" diff --git a/work/meshai/env/usgs.py b/work/meshai/env/usgs.py index 641853c..dcfd64a 100644 --- a/work/meshai/env/usgs.py +++ b/work/meshai/env/usgs.py @@ -39,11 +39,11 @@ def _cfg_str(config, attr: str, default: str) -> str: # Maps the flood_status strings _fetch() sets (see severity-classification # block above) onto the ranked threshold_state vocabulary the shared hydro -# gating/formatter modules speak (meshai.central.idaho_gauge_sites. -# THRESHOLD_RANK / meshai.notifications.gating.hydro / formatters.hydro). -# Kept local rather than importing from central.idaho_gauge_sites so this -# adapter has no dependency on the (Central-only, reference-only) central -# package -- only the string vocabulary is shared, not the code. +# gating/formatter modules speak (meshai.notifications.gating.hydro. +# THRESHOLD_RANK / formatters.hydro). +# Kept local rather than importing from gating.hydro so this adapter has +# no dependency on the gating package -- only the string vocabulary is +# shared, not the code. _FLOOD_STATUS_TO_THRESHOLD_STATE = { "Action Stage": "action", "Minor Flood": "flood_minor", diff --git a/work/meshai/notifications/gating/hydro.py b/work/meshai/notifications/gating/hydro.py index ccc38ab..d573440 100644 --- a/work/meshai/notifications/gating/hydro.py +++ b/work/meshai/notifications/gating/hydro.py @@ -74,12 +74,17 @@ import logging from typing import Optional from meshai.adapter_config import adapter_config -from meshai.central.idaho_gauge_sites import THRESHOLD_RANK from meshai.notifications.gating.base import GateResult from meshai.persistence import get_db logger = logging.getLogger(__name__) +# Ordered list of threshold names from low to high. Used to compare +# "is current threshold higher than prior" (upward crossing detection). +# Formerly meshai.central.idaho_gauge_sites.THRESHOLD_RANK -- inlined here +# since this decider was its only consumer. +THRESHOLD_RANK = ["normal", "action", "flood_minor", "flood_moderate", "flood_major"] + def _rank(state: Optional[str]) -> int: """THRESHOLD_RANK index for *state*, treating unknown as 0 (normal).""" diff --git a/work/tests/test_hydro_refactor.py b/work/tests/test_hydro_refactor.py index 34556e0..45a01a8 100644 --- a/work/tests/test_hydro_refactor.py +++ b/work/tests/test_hydro_refactor.py @@ -208,8 +208,8 @@ class TestGateSequenceParity: def _canonical(self, fixture): """Build canonical data from a Central-style fixture (as the deleted - handler used to) via the still-live idaho_gauge_sites helpers.""" - from meshai.central.idaho_gauge_sites import ( + handler used to) via the still-live gauge_sites helpers.""" + from meshai.env.gauge_sites import ( compute_threshold_state, lookup_site, normalize_site_id, ) env = fixture["envelope"]