feat: normales journalières + dedupe SYNOP + carte plus large
Some checks are pending
Deploy info-canicule / deploy (push) Waiting to run

3 fixes en un :

1. lib/observations.ts : dedupe par validity_time sur le parse hourly.
   L API MF SYNOP retourne chaque obs en doublon exact sur les ranges
   multi-step (bug gateway WSO2). Constaté 7/8 paires identiques sur 24h.

2. Normales 1991-2020 passées de mensuelles à journalières (lissées 7j).
   - scripts/build-normales.mjs : agrégation par day-of-year (1..366)
     avec moving average ±3j pour stabiliser le bruit jour-à-jour.
   - src/data/normales.json : 2.28 MB (vs 78 KB), 96 × 366 entrées.
   - lib/normales.ts : normaleForDay/Date + normalesForRange, computeAnomaly
     compare maintenant chaque jour observé à SA normale (pas à la moyenne
     du mois) → bien plus précis sur les jours de transition mensuelle.
   - TemperatureChartInteractive : overlay normales en COURBE qui suit
     la saison (7j/30j) au lieu d une ligne horizontale unique.
     24h reste ligne horizontale (normale du jour courant).
   - Tooltip 7j/30j ajoute "↳ normale TX X°C (+Y)" pour montrer l écart
     par point.

3. Carte sur la home libérée du container-tight (max-w-5xl = 1024px) :
   wrapper dédié max-w-[1400px] → carte ~37% plus grande sur PC large.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Florian 2026-05-26 01:43:10 +02:00
parent 84e8bd200f
commit cb8d111a12
8 changed files with 283 additions and 118 deletions

View file

@ -7,7 +7,7 @@ import { getDepartement, isDrom } from '../../lib/departements';
import { PHENOMENA, COLOR_LABEL } from '../../lib/phenomena';
import { ADVICE, EMERGENCY_NUMBERS } from '../../lib/advice';
import { getClimatoForDepartement } from '../../lib/climato';
import { computeAnomaly, normaleForMonth } from '../../lib/normales';
import { computeAnomaly, normaleForDate, normalesForRange } from '../../lib/normales';
import { getHourlyForDepartement } from '../../lib/observations';
import TemperatureChartInteractive from '../../components/TemperatureChartInteractive.astro';
import AnomalyBadge from '../../components/AnomalyBadge.astro';
@ -36,20 +36,18 @@ if (!drom) {
let climato = null;
let anomaly = null;
let hourly = null;
let normale = null;
let normales7: Array<{ tx: number | null; tn: number | null }> = [];
let normales30: Array<{ tx: number | null; tn: number | null }> = [];
let normaleHourly: { tx: number | null; tn: number | null } | null = null;
if (!drom) {
try {
climato = await getClimatoForDepartement(dept.code);
if (climato?.days?.length) {
anomaly = await computeAnomaly(dept.code, climato.days);
// Mois représentatif = mois du dernier jour climato dispo
const lastDate = climato.days[climato.days.length - 1].date;
normale = await normaleForMonth(dept.code, parseInt(lastDate.slice(5, 7), 10));
}
} catch (e) {
console.warn('climato fetch failed for', dept.code, (e as Error).message);
}
// Hourly est best-effort : si MF API down ou pas de creds, on n'affiche juste pas l'onglet 24h
try {
hourly = await getHourlyForDepartement(dept.code, 24);
} catch (e) {
@ -59,6 +57,17 @@ if (!drom) {
const last7 = climato?.days?.slice(-7) ?? [];
const last30 = climato?.days?.slice(-30) ?? [];
if (!drom) {
const series7 = await normalesForRange(dept.code, last7.map((d) => d.date));
normales7 = series7.map((n) => ({ tx: n?.tx ?? null, tn: n?.tn ?? null }));
const series30 = await normalesForRange(dept.code, last30.map((d) => d.date));
normales30 = series30.map((n) => ({ tx: n?.tx ?? null, tn: n?.tn ?? null }));
// Normale "du jour courant" (pour overlay du graphe 24h, ligne horizontale)
normaleHourly = await normaleForDate(dept.code, new Date());
if (normaleHourly) normaleHourly = { tx: normaleHourly.tx, tn: normaleHourly.tn };
}
const stationLabel = hourly ? `${hourly.stationName} (${hourly.distKm} km)` : null;
const today = snapshot ? alertsForDepartement(snapshot, dept.code, 'J') : [];
@ -178,7 +187,9 @@ const adviceFor = highest && ADVICE[highest.phenomenonId];
hourly={hourly}
days7={last7}
days30={last30}
normale={normale}
normales7={normales7}
normales30={normales30}
normaleHourly={normaleHourly}
stationLabel={stationLabel}
/>
<p class="mt-2 text-xs text-slate-500">