fix simple config

This commit is contained in:
Tykayn 2023-07-30 19:18:17 +02:00 committed by tykayn
parent 4c6dfbd198
commit 431ba2e558
7 changed files with 7393 additions and 4971 deletions

View File

@ -3,24 +3,24 @@
*/
import fs from 'node-fs'
import minimist from 'minimist'
import mappingConfigIRVE from './mappings/configIRVE.mjs'
import mapping_engine from "./mappings/engine.mjs";
import custom_utils from "./mappings/utils.mjs";
import mappingConfigIRVE from './mappings/converters/configIRVE.mjs'
import mappingConfigIRVE_simple from './mappings/converters/mappingConfigIRVE_simple.mjs'
import mapping_engine from './mappings/engine.mjs'
import custom_utils from './mappings/utils.mjs'
const {debugLog} = custom_utils;
const { debugLog } = custom_utils
const { isBooleanKey } = custom_utils
// let debugLog = custom_utils.debugLog
let use_mappping_engine = false;
let Mapping_engine = new mapping_engine(mappingConfigIRVE);
let use_mappping_engine = false
let Mapping_engine = new mapping_engine(mappingConfigIRVE)
let mini_arguments = minimist(process.argv.slice(2))
// let sourceFileChargemapJson = './chargemap_data/hurepoix.json'
let sourceFilePathGeoJson = './etalab_data/latest.json'
// wip filter
let filterOnBoundingBox = true
filterOnBoundingBox = false
@ -54,7 +54,7 @@ if (enable_filter_on_department) {
let pointCounterMax = 1000000
let limitConversionToFirstPoint = false
// limitConversionToFirstPoint = true;
limitConversionToFirstPoint = true
if (limitConversionToFirstPoint) {
pointCounterMax = 1
}
@ -62,23 +62,11 @@ let defaultPropertiesOfPoint = {
'amenity': 'charging_station'
}
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',
})
let converted_geo_json = {
type: 'FeatureCollection',
features: []
}
/**
*
* @param sourceFilePath
@ -86,10 +74,9 @@ let converted_geo_json = {
* @param pointCounterMax
* @param boundingBoxCoordinates
*/
function convertDataForIRVE(sourceFilePath, mapping, pointCounterMax, boundingBoxCoordinates) {
function convertDataForIRVE (sourceFilePath, mapping, pointCounterMax, boundingBoxCoordinates) {
debugLog('convertDataFromChargemap from ', sourceFilePath)
fs.readFile(sourceFilePath, 'utf8', function (err, data) {
let point_counter = 0
if (err) {
@ -113,14 +100,14 @@ function convertDataForIRVE(sourceFilePath, mapping, pointCounterMax, boundingBo
let regex_filter_test_result = true
if (enable_filter_on_department) {
console.log('filtre sur les départements activé')
debugLog('filtre sur les départements activé')
regex_filter_test_result = (
filterZipCode.test(feature_point.properties.consolidated_code_postal)
||
filterZipCodeAdresse.test(feature_point.properties.adresse_station)
)
} else if (filterOnBoundingBox) {
console.log('filtre sur les coordonnées activé')
debugLog('filtre sur les coordonnées activé')
let x = feature_point.properties.coordonneesXY[0]
let xMin = boundingBoxCoordinates.xMin
@ -149,7 +136,7 @@ function convertDataForIRVE(sourceFilePath, mapping, pointCounterMax, boundingBo
debugLog('featurePoint', feature_point)
let mapped_point = {};
let mapped_point = {}
if (use_mappping_engine) {
Mapping_engine.setConfig(mapping)
@ -180,12 +167,10 @@ function convertDataForIRVE(sourceFilePath, mapping, pointCounterMax, boundingBo
})
}
/**
* retuns the converted element from mapping config if present, null otherwise
*/
function mapElementFromConfSimple(featurePoint, mappingConfig)
{
function mapElementFromConfSimple (featurePoint, mappingConfig) {
let mappingKeys = Object.keys(mappingConfig)
let featurePointPropertiesKeys = Object.keys(featurePoint.properties)
@ -207,7 +192,11 @@ function mapElementFromConfSimple(featurePoint, mappingConfig)
let convertedValue = ''
if (isBooleanKey(pointKeyName)) {
convertedValue = featurePoint.properties[pointKeyName].toLowerCase() == 'true' ? 'yes' : 'no'
let copyOfValue = '' + featurePoint.properties[pointKeyName]
if (typeof copyOfValue === typeof Object && copyOfValue.key_converted) {
copyOfValue = copyOfValue.key_converted
}
convertedValue = copyOfValue.toLowerCase() == 'true' ? 'yes' : 'no'
} else {
convertedValue = featurePoint.properties[pointKeyName]
}
@ -222,7 +211,7 @@ function mapElementFromConfSimple(featurePoint, mappingConfig)
return basePoint
}
function writeJsonFile(fileName, fileContent) {
function writeJsonFile (fileName, fileContent) {
debugLog('write file ', fileName)
return fs.writeFile(
@ -240,4 +229,11 @@ function writeJsonFile(fileName, fileContent) {
}
console.log('pointCounterMax', pointCounterMax)
convertDataForIRVE(sourceFilePathGeoJson, mappingConfigIRVE, pointCounterMax, boundingBoxCoordinates)
if (!use_mappping_engine) {
convertDataForIRVE(sourceFilePathGeoJson, mappingConfigIRVE_simple, pointCounterMax, boundingBoxCoordinates)
} else {
convertDataForIRVE(sourceFilePathGeoJson, mappingConfigIRVE, pointCounterMax, boundingBoxCoordinates)
}

View File

@ -0,0 +1,43 @@
/**
* plan de conversion des clés du jeu de données vers les tags OSM
* détail dans le tableau
* https://wiki.openstreetmap.org/wiki/France/data.gouv.fr/Bornes_de_Recharge_pour_V%C3%A9hicules_%C3%89lectriques
*/
export default {
// ******* nombres
nbre_pdc: 'capacity',
// ******* textes
amenity: 'amenity', // conserver le tag de base
capacity: 'capacity', // conserver le tag de base
nom_amenageur: 'operator',
siren_amenageur: 'owner:ref:FR:SIREN',
nom_operateur: 'operator',
telephone_operateur: 'phone',
contact_operateur: 'email', // ici, on souhaite convertir la clé contact_operateur=bidule en email=bidule
id_station_itinerance: 'ref:EU:EVSE',
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',
// ******** champs booléens
prise_type_ef: 'socket:typee',
prise_type_2: 'socket:type2',
prise_type_combo_ccs: 'socket:type2_combo',
prise_type_chademo: 'socket:chademo',
// ******** champs plus complexes
horaires: 'opening_hours', // déjà au bon format
}

View File

@ -12,7 +12,33 @@ function debugLog (message) {
}
console.log('debug: ', ...message)
}
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',
})
/**
*
* @param pointKeyName
* @returns {boolean}
*/
function isBooleanKey(pointKeyName) {
return listOfBooleanKeys.indexOf(pointKeyName) !== -1
}
export default
{
debugLog
debugLog,
isBooleanKey
}

File diff suppressed because one or more lines are too long