fix: correctness bugs - prediction math, division by zero, unvalidated days, locality filter #3
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/correctness-bugs"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
predictPrice(regression, 7)was predicting 7 days from the start of the data window, not from today. Fixed to useprices.length + 7so predictions are relative to the latest data point. Applied to bothanalyzeTrends()andanalyzeStationTrend().avgPriceis 0 (no data), producingInfinity/NaN. Now shows "Sin datos" gracefully.daysparam:/api/prices/historyhad no bounds checking (unlike/api/trends), allowing?days=999999999to scan the entire table. Now clamped to[1, 365].filterByPostalCodePrefixhad a hardcodedlorcalocality check that causedTypeErrorin tests (and was a hidden business rule bypassing postal code filtering). Removed.priceHistory.find()inanalyzeTrendswith a pre-built Map lookup.Test plan
bun test— all 30 tests pass (3 previously broken tests now fixed)e4ffed224dto3fd73c0458