feat/atlas-clima
needs attentiondea660c · fullPR #315reviewed 2026-07-16 05:16 UTC1H · 6M · 5L · 4I- Purpose
- Atlas is Batu's public grid-intelligence map at batuenergy.com/atlas, showing Mexico's live electrical demand, solar generation, and MDA prices. Clima × Demanda Fase 1 adds weather context to the demand curve.
- Goal
- Add an hourly temperature overlay on the CENACE live demand chart so users can visually correlate grid demand with temperature in real time.
- Sub-goals
- SG-1: Fetch Open-Meteo hourly temp per CENACE control region (lazy, on region-open)
- SG-2: Join temp to demand curve by hora via horaIdx helper
- SG-3: Render orange polyline on a secondary right-hand °C axis
- SG-4: Show/hide legend item and source attribution dynamically
- What
- apps/web/public/atlas/index.html: added DEM_TEMP region→coordinates lookup, fetchRegionTemp async helper with session-scoped cache, horaIdx join function, temperature polyline + axis rendering in buildDemandChart, tooltip augmentation in onDMove, and legend/attribution updates.
- Why
- Give solar operators and energy managers weather context alongside real-time demand to support load/generation correlation — differentiating the Atlas from raw CENACE dashboards.
- Areas
- apps/web/public/atlas/index.html+43−5
- Blast
- 1 file, +43/−5. Static HTML/JS only — no TypeScript build, no domain logic, no database changes. Browser-only side effects.
Findings · 17
correctness4
Axis tick labels render without polyline when only one temp slot exists
apps/web/public/atlas/index.html:618
Three °C labels are emitted inside if(fin.length) but the polyline requires tp.length>=2. Early in the day with one point, labels appear with no curve.
forecast_days=1 date misalignment if DEM is stale from yesterday
apps/web/public/atlas/index.html:413
Permanent no-retry on failure with no user-visible indicator
apps/web/public/atlas/index.html:410
horaIdx mapping confirmed correct — no off-by-one
apps/web/public/atlas/index.html:422
security2
Open-Meteo response values not validated as finite numbers before storage
apps/web/public/atlas/index.html
CSP must allow connect-src https://api.open-meteo.com
apps/web/public/atlas/index.html
conventions3
Open-Meteo non-commercial license active in a commercial product
apps/web/public/atlas/index.html:404
Free Open-Meteo tier is CC-BY non-commercial; atlas runs on batuenergy.com. Comment acknowledges this as a pre-production TODO but the fetch is already live. Must resolve before merge: commercial plan or server-side proxy in atlas-sen.
#about overlay missing Open-Meteo attribution (CC-BY requirement)
apps/web/public/atlas/index.html:135
Map control and chart footer updated; the static Fuentes de datos list in the #about overlay was not. CC-BY requires reasonably prominent attribution.
ADR-016 / FCIS patterns correctly not applied to static HTML
apps/web/public/atlas/index.html
tests3
horaIdx has no unit test despite prior off-by-one bug
apps/web/public/atlas/index.html:424
The formula was wrong before (fixed in 1e550764). A two-line Vitest test (horaIdx(1)===0, horaIdx(24)===23) would guard against regression.
tempFor cache-state logic untested despite two post-landing fixes
apps/web/public/atlas/index.html:422
The four-state guard (absent/pending/null/object) was patched post-landing. Trivially testable in isolation.
No Playwright smoke test verifies the atlas page loads without JS errors
apps/web/public/atlas/index.html
improvement4
Visible layout jump on first open: mR shifts 14→32 when temp loads async
apps/web/public/atlas/index.html:607
Chart renders without temp (mR=14) then re-renders with temp (mR=32), shrinking the plot area visibly. Fix: use mR=32 unconditionally for regions in DEM_TEMP.
Stale cache past midnight — forecast_days=1 gives today only, no TTL
apps/web/public/atlas/index.html:408
Page open past midnight serves yesterday's temperatures against new-day demand. Fix: include date in cache key.
No UX feedback while temperature is loading (pending state invisible)
apps/web/public/atlas/index.html:618
Axis tick labels can crowd when temperature range is narrow (< 4°)
apps/web/public/atlas/index.html:623
seo1
No SEO-relevant changes
apps/web/public/atlas/index.html