← all branches

feat/atlas-clima

needs attentionviewing older commit
ec02a4d · incrementalPR #315reviewed 2026-07-16 05:05 UTC0H · 3M · 4L · 4I
The branch
Purpose
Add weather context to the CENACE demand atlas — visualize temperature alongside load to reveal the weather-driven component of demand
Goal
Temperature overlay (Fase 1): hourly °C line on right-axis over the demand curve, per CENACE control region, sourced from Open-Meteo, session-cached
Sub-goals
  • SG-1: Load-center coordinates per control region (weighted to population, not centroid)
  • SG-2: Client-side Open-Meteo fetch with session cache
  • SG-3: hora→temperature join (horaIdx helper, off-by-one fix)
  • SG-4: Right-axis °C rendering in buildDemandChart + hover tooltip + legend
  • SG-5: License/timezone documentation and Open-Meteo attribution in footer
The changes (whole branch)
What
This incremental commit (ec02a4d) extracts horaIdx as a named helper — single source of truth for (h-1)%24 — and adds timezone/license comment block. Prior commits added the full temperature overlay feature.
Why
Refactor driven by prior loop-review findings: consolidate the hora→index mapping into one place to eliminate the off-by-one duplication risk, and document the non-obvious Baja California timezone decision.
Areas
apps/web/public/atlas/index.html+405
Blast
1 file, +40/-5. Standalone static HTML SPA; no imports, no build step, no API surface. Change is isolated to the atlas tool.
Open-Meteo non-commercial API — pre-production blocker documented in PR body and LICENSE comment
CI· statusCheckRollup not accessible via PATCodeRabbit· no .coderabbit.yaml in repo

Findings · 6

correctness2

medium

Baja California timezone claim needs source citation

apps/web/public/atlas/index.html:398

Comment asserts CENACE reports hora in Mexico City time for all regions including Baja California, and instructs to never switch to America/Tijuana. Baja California observes US Pacific DST (UTC-8/UTC-7), differing from Mexico City (UTC-6, no DST since 2022) by 1-2h during ~8 months of the year. If CENACE's API reports Baja hora in local Tijuana time, the temperature↔demand hour join would be silently off. The comment says 'verified' but cites no source or methodology. Should link CENACE API docs or describe the verification.

low

horaIdx(0) returns -1 for malformed hora=0 rows

apps/web/public/atlas/index.html:422

JS modulo preserves sign: (0-1)%24 = -1. CENACE hours run 1–24 so hora=0 should never appear, but a malformed row would silently return undefined rather than crashing. Degrades gracefully.

conventions1

low

horaIdx arrow function lacks parameter parens

apps/web/public/atlas/index.html:422

const horaIdx=h=>(h-1)%24 omits parens around the single parameter. Minor style nit; not a bug.

improvement3

medium

Silent catch leaves no diagnostic for failed temperature fetches

apps/web/public/atlas/index.html:416

.catch(()=>{_tempCache[name]=null;}) swallows errors permanently with no console.warn. A transient DNS blip, CORS failure, or Open-Meteo 429 silently caches null and the temperature overlay disappears for the entire page session. Add console.warn('[atlas/temp] fetch failed for', name, e) at minimum so failures are observable in devtools.

medium

Permanent no-retry on transient failure requires full page refresh

apps/web/public/atlas/index.html:407

The name in _tempCache guard (correct for preventing hammering) also permanently suppresses retries for the session after any failure. A momentary network loss or rate-limit means users lose temperature data until refresh. Consider storing {failed:true, at:Date.now()} and retrying once after ~60s, or at minimum logging 'refresh to retry' so the failure mode is understood.

low

horaIdx comment says '24-value temp array' but by is a plain object

apps/web/public/atlas/index.html:422

_tempCache stores by as a plain object with numeric keys, not an Array. Using new Array(24).fill(null) would match the comment and eliminate numeric/string key ambiguity.

History · 2 commits

  1. dea660cneeds attentionfull1H · 6M · 5L2026-07-16 05:16
  2. ec02a4dneeds attentionincremental0H · 3M · 4L2026-07-16 05:05current