fix(stations): parse CSV en CRLF robust (le name était stripped \r → undefined)
Some checks are pending
Deploy info-canicule / deploy (push) Waiting to run

Le CSV liste-stations-synop de Météo France arrive en CRLF, le split('\n')
laissait un \r en fin de chaque header → header.indexOf('name') = -1
→ stations[].name = undefined → 'station undefined' affiché côté front.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Florian 2026-05-26 00:37:09 +02:00
parent 5fbbec4902
commit a007f340dc
2 changed files with 6 additions and 5 deletions

View file

@ -33,8 +33,9 @@ function distKm(lat1, lon1, lat2, lon2) {
} }
// Parse CSV stations // Parse CSV stations
const rows = readFileSync(STATIONS_CSV, 'utf-8').trim().split('\n'); // CSV Météo France peut être en CRLF — split robuste sur les 2 EOLs.
const header = rows[0].split(';'); const rows = readFileSync(STATIONS_CSV, 'utf-8').trim().split(/\r?\n/);
const header = rows[0].split(';').map((h) => h.trim());
const idx = { const idx = {
lat: header.indexOf('lat'), lat: header.indexOf('lat'),
lon: header.indexOf('lon'), lon: header.indexOf('lon'),
@ -44,8 +45,8 @@ const idx = {
const stations = rows.slice(1).map((line) => { const stations = rows.slice(1).map((line) => {
const c = line.split(';'); const c = line.split(';');
return { return {
id: c[idx.wmo], id: (c[idx.wmo] ?? '').trim(),
name: c[idx.name], name: (c[idx.name] ?? '').trim(),
lat: parseFloat(c[idx.lat]), lat: parseFloat(c[idx.lat]),
lon: parseFloat(c[idx.lon]), lon: parseFloat(c[idx.lon]),
}; };

File diff suppressed because one or more lines are too long