Repository navigation
Fix mismatched forecast issuance and unit label, v1.0.8 - #8
Merged
Merged
Conversation
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().
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:searchLatestFloodStatusByAreaandgauges:queryGaugeForecastsadvance 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) — bothshowed 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 intime to the status's
issuedTime, so severity, confidence tier, and theforecast 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 soany residual mismatch is visible rather than silent.
Bug: threshold/forecast values always labeled m³/s
Remarks hardcoded
m³/sforThresholdsandForecastregardless of thegauge model's actual
gaugeValueUnit. Per Google's docs, gauges usingagency-set water levels (India/Bangladesh/Brazil) report in meters, not
discharge — those would have been mislabeled. Added
displayGaugeValueUnit()mapping the
GaugeValueUnitenum (METERS/CUBIC_METERS_PER_SECOND) to thecorrect display unit. (
forecastChange.valueChange'smlabel was verifiedcorrect as-is — Google documents that field as always in meters regardless of
gaugeValueUnit— and was left unchanged.)Version bump
package.jsonbumped to1.0.8Testing
logic produces the exact contradiction seen in production, and the new logic
resolves it (severity and forecast table now agree)
gauges: 0 contradictions, 3 gauges show the "different issuance" note
(compared 3 candidate strategies before picking this one — see above)
npx tsc --noEmit— passesnpm run lint— passesnpm run build— passesnpm audit— 0 vulnerabilitiesNot verified: unit-label fix against a real non-discharge gauge (all NZ gauges
checked use
CUBIC_METERS_PER_SECOND); confirmed correct via the documentedenum values instead.
Housekeeping
This branch was originally committed directly to
mainby mistake before thebranch existed. Caught before pushing — moved the commit onto this branch and
hard-reset
mainback toorigin/main. No history was lost;mainisunaffected.