convert to yes no values boolean fields

This commit is contained in:
Tykayn 2023-07-29 23:04:11 +02:00 committed by tykayn
parent bfb59df09c
commit 9eaef4dbf9
5 changed files with 9643 additions and 11594 deletions

View File

@ -17,16 +17,15 @@ let boundingBoxCoordinates = {
} }
let filterCoordinates = true let filterCoordinates = true
let enableFilterOnDepartment = false let enableFilterOnDepartment = true
let filterDepartment = 91 let filterDepartment = 974
let filterZipCode = new RegExp(`^${filterDepartment}`) let filterZipCode = new RegExp(`^${filterDepartment}`)
let filterZipCodeAdresse = new RegExp(` ${filterDepartment}`) let filterZipCodeAdresse = new RegExp(` ${filterDepartment}`)
let filteredName = '' let filteredName = ''
if (enableFilterOnDepartment) { if (enableFilterOnDepartment) {
filteredName = '_filtered_zipcode_' + filterDepartment filteredName = '_filtered_zipcode_' + filterDepartment
} } else if (filterOnBoundingBox) {
if (filterOnBoundingBox) {
filteredName = '_filtered_bbox_' + boundingBoxCoordinates.xMin + '-' + boundingBoxCoordinates.xMax + '_' + boundingBoxCoordinates.yMin + '-' + boundingBoxCoordinates.yMax filteredName = '_filtered_bbox_' + boundingBoxCoordinates.xMin + '-' + boundingBoxCoordinates.xMax + '_' + boundingBoxCoordinates.yMin + '-' + boundingBoxCoordinates.yMax
} }
let pointCounterMax = 1000000 let pointCounterMax = 1000000
@ -39,12 +38,18 @@ if (limitConversionToFirstPoint) {
// let sourceFileChargemapJson = './chargemap_data/hurepoix.json' // let sourceFileChargemapJson = './chargemap_data/hurepoix.json'
let sourceFileIRVEGeoJson = './etalab_data/latest.json' let sourceFileIRVEGeoJson = './etalab_data/latest.json'
let defaultPropertiesOfPoint = {
'amenity': 'charging_station'
}
/** /**
* plan de conversion des clés du jeu de données vers les tags OSM * plan de conversion des clés du jeu de données vers les tags OSM
* détail dans le tableau * détail dans le tableau
* https://wiki.openstreetmap.org/wiki/France/data.gouv.fr/Bornes_de_Recharge_pour_V%C3%A9hicules_%C3%89lectriques * https://wiki.openstreetmap.org/wiki/France/data.gouv.fr/Bornes_de_Recharge_pour_V%C3%A9hicules_%C3%89lectriques
*/ */
let mappingConfigIRVE = { let mappingConfigIRVE = {
// ******* nombres
nbre_pdc: 'capacity',
// ******* textes
amenity: 'amenity', // conserver le tag de base amenity: 'amenity', // conserver le tag de base
capacity: 'capacity', // conserver le tag de base capacity: 'capacity', // conserver le tag de base
nom_amenageur: 'operator', nom_amenageur: 'operator',
@ -52,26 +57,36 @@ let mappingConfigIRVE = {
nom_operateur: 'operator', nom_operateur: 'operator',
telephone_operateur: 'phone', telephone_operateur: 'phone',
contact_operateur: 'email', // ici, on souhaite convertir la clé contact_operateur=bidule en email=bidule contact_operateur: 'email', // ici, on souhaite convertir la clé contact_operateur=bidule en email=bidule
nbre_pdc: 'capacity',
id_station_itinerance: 'ref:EU:EVSE', id_station_itinerance: 'ref:EU:EVSE',
id_station_local: 'ref', id_station_local: 'ref',
gratuit: 'fee',
paiement_acte: 'authentication:none',
reservation: 'reservation',
observations: 'note',
nom_station: 'name',
nom_enseigne: 'network',
// ******* dates
date_mise_en_service: 'start_date',
date_maj: 'source:date',
// TODO gestion des types dont on doit convertir la valeur
// ******** champs booléens
cable_t2_attache: 'socket:type2_cable',
prise_type_ef: 'socket:typee', prise_type_ef: 'socket:typee',
prise_type_2: 'socket:type2', prise_type_2: 'socket:type2',
prise_type_combo_ccs: 'socket:type2_combo', prise_type_combo_ccs: 'socket:type2_combo',
prise_type_chademo: 'socket:chademo', prise_type_chademo: 'socket:chademo',
gratuit: 'fee',
paiement_acte: 'authentication:none',
paiement_cb: 'payment:credit_cards',
reservation: 'reservation',
accessibilite_pmr: 'wheelchair',
date_mise_en_service: 'start_date',
observations: 'note',
date_maj: 'source:date',
nom_station: 'name',
nom_enseigne: 'network',
cable_t2_attache: 'socket:type2_cable',
// TODO gestion des types dont on doit convertir la valeur // ******** champs plus complexes
horaires: 'opening_hours', // déjà au bon format
// accessibilite_pmr: 'wheelchair',
// paiement_cb: 'payment:credit_cards',
// station_deux_roues => // station_deux_roues =>
// ajout de trois tags: // ajout de trois tags:
// bicycle=yes // bicycle=yes
@ -80,6 +95,16 @@ let mappingConfigIRVE = {
// consolidated_code_postal: "zipcode", // consolidated_code_postal: "zipcode",
} }
let listOfBooleanKeys = Object.keys({
prise_type_ef: 'socket:typee',
prise_type_2: 'socket:type2',
prise_type_combo_ccs: 'socket:type2_combo',
prise_type_chademo: 'socket:chademo',
gratuit: 'fee',
paiement_acte: 'authentication:none',
paiement_cb: 'payment:credit_cards',
cable_t2_attache: 'socket:type2_cable',
})
function debugLog (message) { function debugLog (message) {
if (!show_debug) { if (!show_debug) {
@ -179,6 +204,11 @@ function convertDataForIRVE (sourceFilePath, mapping, pointCounterMax, boundingB
}) })
} }
function isBooleanKey (pointKeyName) {
return listOfBooleanKeys.indexOf(pointKeyName) !== -1
}
/** /**
* retuns the converted element from mapping config if present, null otherwise * retuns the converted element from mapping config if present, null otherwise
*/ */
@ -189,7 +219,7 @@ function mapElementFromConf (featurePoint, mappingConfig) {
debugLog('keys', mappingKeys, featurePointPropertiesKeys) debugLog('keys', mappingKeys, featurePointPropertiesKeys)
let newProperties = {} let newProperties = defaultPropertiesOfPoint
// reinit properties of current point // reinit properties of current point
let basePoint = Object.create(featurePoint) let basePoint = Object.create(featurePoint)
@ -202,7 +232,17 @@ function mapElementFromConf (featurePoint, mappingConfig) {
if (mappingKeys.indexOf(pointKeyName) !== -1) { if (mappingKeys.indexOf(pointKeyName) !== -1) {
debugLog('found element', pointKeyName, '=>', mappingConfig[pointKeyName], 'value : ', featurePoint.properties[pointKeyName]) debugLog('found element', pointKeyName, '=>', mappingConfig[pointKeyName], 'value : ', featurePoint.properties[pointKeyName])
newProperties[mappingConfig[pointKeyName]] = featurePoint.properties[pointKeyName] let convertedValue = ''
if (isBooleanKey(pointKeyName)) {
convertedValue = featurePoint.properties[pointKeyName].toLowerCase() == 'true' ? 'yes' : 'no'
} else {
convertedValue = featurePoint.properties[pointKeyName]
}
if (convertedValue) {
newProperties[mappingConfig[pointKeyName]] = convertedValue
}
} }
}) })

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long