diff --git a/lib/merge/customization.js b/lib/merge/customization.js new file mode 100644 index 0000000..504740f --- /dev/null +++ b/lib/merge/customization.js @@ -0,0 +1,49 @@ +const {chain} = require('lodash') + +const NOM_VOIE_PRIORITY = { + bal: 5, + ban: 4, + cadastre: 3, + bano: 2, + ftth: 1 +} + +function selectByPriority(values, priorityMap) { + if (Object.keys(values).length === 0) { + return + } + return chain(values) + .toPairs() + .map(([source, value]) => ({source, value})) + .maxBy(({source}) => priorityMap[source]) + .value() + .value +} + +function computeNomVoie(nomsVoie) { + return selectByPriority(nomsVoie, NOM_VOIE_PRIORITY) +} + +function computePositionProps(positions) { + if (positions.bal) { + return {...positions.bal, positionSource: 'bal'} + } + if (positions.ban) { + return {...positions.ban, positionSource: 'ban'} + } + if (positions.cadastre && positions.cadastre.positionType === 'entrée') { + return {...positions.cadastre, positionSource: 'cadastre'} + } + if (positions.bano) { + return {...positions.bano, positionSource: 'bano'} + } + if (positions.ftth) { + return {...positions.ftth, positionSource: 'ftth'} + } + if (positions.cadastre) { + return {...positions.cadastre, positionSource: 'cadastre'} // Centre de parcelle + } + return {} +} + +module.exports = {computePositionProps, computeNomVoie} diff --git a/lib/merge/index.js b/lib/merge/index.js index 5bdc3cd..95b5bf9 100644 --- a/lib/merge/index.js +++ b/lib/merge/index.js @@ -5,48 +5,7 @@ const {createPseudoCodeVoieGenerator} = require('../voies') const {rewriteSuffixes} = require('../numeros') const {getNomCommune} = require('./cog') const computeGroups = require('./processing/compute-groups') - -const NOM_VOIE_PRIORITY = { - bal: 5, - ban: 4, - cadastre: 3, - bano: 2, - ftth: 1 -} - -function selectByPriority(values, priorityMap) { - if (Object.keys(values).length === 0) { - return - } - return chain(values) - .toPairs() - .map(([source, value]) => ({source, value})) - .maxBy(({source}) => priorityMap[source]) - .value() - .value -} - -function computePositionProps(positions) { - if (positions.bal) { - return {...positions.bal, positionSource: 'bal'} - } - if (positions.ban) { - return {...positions.ban, positionSource: 'ban'} - } - if (positions.cadastre && positions.cadastre.positionType === 'entrée') { - return {...positions.cadastre, positionSource: 'cadastre'} - } - if (positions.bano) { - return {...positions.bano, positionSource: 'bano'} - } - if (positions.ftth) { - return {...positions.ftth, positionSource: 'ftth'} - } - if (positions.cadastre) { - return {...positions.cadastre, positionSource: 'cadastre'} // Centre de parcelle - } - return {} -} +const {computePositionProps, computeNomVoie} = require('./customization') const SOURCES_LOADERS = { ban: require('./sources/ban'), @@ -101,7 +60,7 @@ async function merge(options) { })) .value() - const nomVoie = selectByPriority(nomsVoie, NOM_VOIE_PRIORITY) + const nomVoie = computeNomVoie(nomsVoie) /* Codes voie */