Skip to content

Commit

Permalink
Move merge customization into its own file
Browse files Browse the repository at this point in the history
  • Loading branch information
jdesboeufs committed Jan 25, 2019
1 parent cb0f751 commit e349df2
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 43 deletions.
49 changes: 49 additions & 0 deletions lib/merge/customization.js
Original file line number Diff line number Diff line change
@@ -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}
45 changes: 2 additions & 43 deletions lib/merge/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -101,7 +60,7 @@ async function merge(options) {
}))
.value()

const nomVoie = selectByPriority(nomsVoie, NOM_VOIE_PRIORITY)
const nomVoie = computeNomVoie(nomsVoie)

/* Codes voie */

Expand Down

0 comments on commit e349df2

Please sign in to comment.