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
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:
parent
5fbbec4902
commit
a007f340dc
2 changed files with 6 additions and 5 deletions
|
|
@ -33,8 +33,9 @@ function distKm(lat1, lon1, lat2, lon2) {
|
|||
}
|
||||
|
||||
// Parse CSV stations
|
||||
const rows = readFileSync(STATIONS_CSV, 'utf-8').trim().split('\n');
|
||||
const header = rows[0].split(';');
|
||||
// CSV Météo France peut être en CRLF — split robuste sur les 2 EOLs.
|
||||
const rows = readFileSync(STATIONS_CSV, 'utf-8').trim().split(/\r?\n/);
|
||||
const header = rows[0].split(';').map((h) => h.trim());
|
||||
const idx = {
|
||||
lat: header.indexOf('lat'),
|
||||
lon: header.indexOf('lon'),
|
||||
|
|
@ -44,8 +45,8 @@ const idx = {
|
|||
const stations = rows.slice(1).map((line) => {
|
||||
const c = line.split(';');
|
||||
return {
|
||||
id: c[idx.wmo],
|
||||
name: c[idx.name],
|
||||
id: (c[idx.wmo] ?? '').trim(),
|
||||
name: (c[idx.name] ?? '').trim(),
|
||||
lat: parseFloat(c[idx.lat]),
|
||||
lon: parseFloat(c[idx.lon]),
|
||||
};
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue