fix(resilience): adapt FAO/IPC fetcher to new HDX CSV schema (#2698)

* fix(resilience): adapt FAO/IPC fetcher to new HDX CSV schema

HDX changed column names: "Country (ISO3)" → "Country" (now contains
ISO3 codes), "Phase 3+ #" → "Phase 3+ number current", etc. The old
column names caused every row to fail iso2 resolution, resulting in
fao: null for all 222 countries.

Fix: fall back to new column names for both country code and phase
number fields. Pass the value as both iso3 and name to resolveIso2
so it works regardless of format.

* fix: restore missing year variable in FAO/IPC fetcher
This commit is contained in:
Elie Habib
2026-04-05 07:18:18 +04:00
committed by GitHub
parent c35708bf48
commit bfe5cf25ef

View File

@@ -567,12 +567,12 @@ async function fetchFsinDataset() {
const rows = parseDelimitedText(csvText, ',');
const parsed = new Map();
for (const row of rows) {
const iso3 = String(row['Country (ISO3)'] || '').trim().toUpperCase();
const iso2 = resolveIso2({ iso3 });
const rawIso3 = String(row['Country (ISO3)'] || row['Country'] || '').trim().toUpperCase();
const iso2 = resolveIso2({ iso3: rawIso3, name: rawIso3 });
if (!iso2) continue;
const phase3plus = safeNum(row['Phase 3+ #']);
const phase4 = safeNum(row['Phase 4 #']);
const phase5 = safeNum(row['Phase 5 #']);
const phase3plus = safeNum(row['Phase 3+ #'] ?? row['Phase 3+ number current']);
const phase4 = safeNum(row['Phase 4 #'] ?? row['Phase 4 number current']);
const phase5 = safeNum(row['Phase 5 #'] ?? row['Phase 5 number current']);
if (phase3plus == null && phase4 == null && phase5 == null) continue;
const yearCandidates = Object.keys(row)
.filter((k) => /period|date|year/i.test(k))