Skip to content

Fix mismatched forecast issuance and unit label, v1.0.8 - #8

Merged
chriselsen merged 3 commits into
mainfrom
fix/forecast-issuance-matching
Aug 25, 2026
Merged

chriselsen merged 3 commits into
mainfrom
fix/forecast-issuance-matching

Conversation

@chriselsen

Copy link
Copy Markdown
Contributor

Summary

Fixes two bugs found while inspecting real gauge output: severity and the
forecast table could describe two different forecast runs, and thresholds
were mislabeled for gauges that don't report discharge.

Bug: severity paired with the wrong forecast issuance

floodStatus:searchLatestFloodStatusByArea and gauges:queryGaugeForecasts
advance independently. Taking whichever forecast issuance was newest,
regardless of which one the status severity actually came from, could pair
an older severity with revised forecast numbers — producing self-contradictory
output like an EXTREME headline above a forecast table whose peak sits below
the warning threshold, after Google revised that day's forecast downward
between issuances.

Observed on two real NZ gauges (hybas_5120622020, hybas_5120621980) — both
showed elevated severity from one issuance rendered next to a forecast table
from a later issuance that had already walked the number back down.

Fix: selectMatchingIssuance() now picks the forecast issuance nearest in
time to the status's issuedTime, so severity, confidence tier, and the
forecast table all describe one forecast run.

Selection by nearest was chosen over an initial attempt that clamped to "the
newest issuance not newer than the status" — that approach was tested against
all 215 currently-elevated NZ gauges and produced 2 contradictions (vs 0 for
plain "always newest"), because it could reach back many hours to an unrelated
issuance when no exact match exists. Nearest resolves to the exact issuance in
212/215 of those cases, and 0/215 contradictions.

For the remaining edge cases where no exact match exists, a
Note: from a different forecast issuance (...) line is added to remarks so
any residual mismatch is visible rather than silent.

Bug: threshold/forecast values always labeled m³/s

Remarks hardcoded m³/s for Thresholds and Forecast regardless of the
gauge model's actual gaugeValueUnit. Per Google's docs, gauges using
agency-set water levels (India/Bangladesh/Brazil) report in meters, not
discharge — those would have been mislabeled. Added displayGaugeValueUnit()
mapping the GaugeValueUnit enum (METERS / CUBIC_METERS_PER_SECOND) to the
correct display unit. (forecastChange.valueChange's m label was verified
correct as-is — Google documents that field as always in meters regardless of
gaugeValueUnit — and was left unchanged.)

Version bump

  • package.json bumped to 1.0.8
  • CHANGELOG updated

Testing

  • Verified against live API data for both affected gauges: confirmed the old
    logic produces the exact contradiction seen in production, and the new logic
    resolves it (severity and forecast table now agree)
  • Cross-checked the new selection logic against all 215 currently-elevated NZ
    gauges: 0 contradictions, 3 gauges show the "different issuance" note
    (compared 3 candidate strategies before picking this one — see above)
  • npx tsc --noEmit — passes
  • npm run lint — passes
  • npm run build — passes
  • npm audit — 0 vulnerabilities

Not verified: unit-label fix against a real non-discharge gauge (all NZ gauges
checked use CUBIC_METERS_PER_SECOND); confirmed correct via the documented
enum values instead.

Housekeeping

This branch was originally committed directly to main by mistake before the
branch existed. Caught before pushing — moved the commit onto this branch and
hard-reset main back to origin/main. No history was lost; main is
unaffected.

floodStatus:searchLatestFloodStatusByArea and gauges:queryGaugeForecasts
advance independently. Taking whichever forecast issuance was newest
regardless of which one the severity came from could pair an older
status severity with revised forecast numbers, producing
self-contradictory output: an EXTREME headline above a forecast table
whose peak sits below the warning threshold, because Google revised
that day's forecast downward between the two issuances (observed on
real NZ gauges: hybas_5120622020, hybas_5120621980).

selectMatchingIssuance() now picks the forecast issuance nearest in
time to the status's issuedTime, so severity, confidence tier and the
forecast table all describe one forecast run. Selection by nearest
issuedTime was chosen over clamping to the newest issuance not newer
than the status: the latter was tested against all 215 currently
elevated NZ gauges and produced 2 contradictions (vs 0 for both the
old 'always newest' behaviour and the new 'nearest' behaviour), by
reaching back many hours to an unrelated issuance when no exact match
exists. Nearest resolves to the exact issuance in 212/215 of those
cases.

A note is added to remarks when the forecast table came from a
different issuance than the severity (the remaining edge case), so a
residual mismatch is visible rather than silent.

Also fixes Thresholds/Forecast remarks always labelling values as
m³/s regardless of the gauge model's actual gaugeValueUnit. Gauges
using agency-set water levels (India/Bangladesh/Brazil per Google's
docs) report in meters, not discharge; the label is now derived from
the API response via displayGaugeValueUnit().
@chriselsen
chriselsen merged commit 90ee130 into main Aug 25, 2026
1 check passed
@chriselsen
chriselsen deleted the fix/forecast-issuance-matching branch August 25, 2026 05:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant