diff --git a/build/cog.js b/build/cog.js index 9588566..37c0f68 100644 --- a/build/cog.js +++ b/build/cog.js @@ -9,13 +9,22 @@ async function extractDepartements(path) { const rows = await readCsvFile(path) return rows.map(row => { + let zone + if (row.ZONE) { + zone = row.ZONE + } else if (row.DEP.length > 2) { + zone = 'dom' + } else { + zone = 'metro' + } + return { code: row.DEP, region: row.REG, chefLieu: row.CHEFLIEU, nom: row.LIBELLE, typeLiaison: parseTypeLiaison(row.TNCC), - zone: row.ZONE ? row.ZONE : row.DEP.length > 2 ? 'dom' : 'metro' + zone } }) } @@ -24,12 +33,21 @@ async function extractRegions(path) { const rows = await readCsvFile(path) return rows.map(row => { + let zone + if (row.ZONE) { + zone = row.ZONE + } else if (['01', '02', '03', '04', '06'].includes(row.REG)) { + zone = 'dom' + } else { + zone = 'metro' + } + return { code: row.REG, chefLieu: row.CHEFLIEU, nom: row.LIBELLE, typeLiaison: parseTypeLiaison(row.TNCC), - zone: row.ZONE ? row.ZONE : ['01', '02', '03', '04', '06'].includes(row.REG) ? 'dom' : 'metro' + zone } }) } @@ -118,11 +136,20 @@ async function extractCommunes(communesPath, mouvementsCommunesPath, arrondissem const anciensCodesIndex = computeAnciensCodesCommunes(communesRows, mouvementsRows) const communes = communesRows.map(row => { + let zone + if (row.zone) { + zone = row.zone + } else if (row.DEP.length > 2) { + zone = 'dom' + } else { + zone = 'metro' + } + const commune = { code: row.COM, nom: row.LIBELLE, typeLiaison: parseTypeLiaison(row.TNCC), - zone: row.zone ? row.zone : row.DEP.length > 2 ? 'dom' : 'metro' + zone } if (row.TYPECOM === 'COM') { diff --git a/build/index.js b/build/index.js index 73da3cd..8d9a1e2 100644 --- a/build/index.js +++ b/build/index.js @@ -70,12 +70,12 @@ async function main() { communes: {...populationHorsMayotte.communes, ...populationMayotte.communes} } const arrondissements = await extractArrondissements(getSourceFilePath('arrondissements.csv')) - const departements_metro_and_dom = await extractDepartements(getSourceFilePath('departements.csv')) - const departements_com = await extractDepartements(getSourceFilePath('departements-outremer.csv')) - const departements = [...departements_metro_and_dom, ...departements_com] - const regions_metro_and_dom = await extractRegions(getSourceFilePath('regions.csv')) - const regions_com = await extractRegions(getSourceFilePath('regions-outremer.csv')) - const regions = [...regions_metro_and_dom, ...regions_com] + const departementsMetroAndDom = await extractDepartements(getSourceFilePath('departements.csv')) + const departementsCom = await extractDepartements(getSourceFilePath('departements-outremer.csv')) + const departements = [...departementsMetroAndDom, ...departementsCom] + const regionsMetroAndDom = await extractRegions(getSourceFilePath('regions.csv')) + const regionsCom = await extractRegions(getSourceFilePath('regions-outremer.csv')) + const regions = [...regionsMetroAndDom, ...regionsCom] await buildRegions(regions) await buildDepartements(departements)