engine runs
This commit is contained in:
parent
d57e744db3
commit
177744ca61
@ -10,10 +10,13 @@ import custom_utils from './mappings/utils.mjs'
|
|||||||
|
|
||||||
const { debugLog } = custom_utils
|
const { debugLog } = custom_utils
|
||||||
const { isBooleanKey } = custom_utils
|
const { isBooleanKey } = custom_utils
|
||||||
|
const { writeFile } = custom_utils
|
||||||
|
|
||||||
// let debugLog = custom_utils.debugLog
|
// let debugLog = custom_utils.debugLog
|
||||||
|
|
||||||
let use_mappping_engine = false
|
let use_mappping_engine = false
|
||||||
|
use_mappping_engine = true
|
||||||
|
|
||||||
let Mapping_engine = new mapping_engine(mappingConfigIRVE)
|
let Mapping_engine = new mapping_engine(mappingConfigIRVE)
|
||||||
|
|
||||||
let mini_arguments = minimist(process.argv.slice(2))
|
let mini_arguments = minimist(process.argv.slice(2))
|
||||||
@ -34,6 +37,7 @@ let boundingBoxCoordinates = {
|
|||||||
|
|
||||||
let filterCoordinates = true
|
let filterCoordinates = true
|
||||||
let enable_filter_on_department = true
|
let enable_filter_on_department = true
|
||||||
|
enable_filter_on_department = false
|
||||||
let filterDepartment = 91
|
let filterDepartment = 91
|
||||||
if (mini_arguments['department']) {
|
if (mini_arguments['department']) {
|
||||||
filterDepartment = mini_arguments['department']
|
filterDepartment = mini_arguments['department']
|
||||||
@ -56,7 +60,7 @@ let pointCounterMax = 1000000
|
|||||||
let limitConversionToFirstPoint = false
|
let limitConversionToFirstPoint = false
|
||||||
limitConversionToFirstPoint = true
|
limitConversionToFirstPoint = true
|
||||||
if (limitConversionToFirstPoint) {
|
if (limitConversionToFirstPoint) {
|
||||||
pointCounterMax = 1
|
pointCounterMax = 2
|
||||||
}
|
}
|
||||||
let defaultPropertiesOfPoint = {
|
let defaultPropertiesOfPoint = {
|
||||||
'amenity': 'charging_station'
|
'amenity': 'charging_station'
|
||||||
@ -139,8 +143,9 @@ function convertDataForIRVE (sourceFilePath, mapping, pointCounterMax, boundingB
|
|||||||
let mapped_point = {}
|
let mapped_point = {}
|
||||||
|
|
||||||
if (use_mappping_engine) {
|
if (use_mappping_engine) {
|
||||||
|
console.log('go mapping engine')
|
||||||
Mapping_engine.setConfig(mapping)
|
Mapping_engine.setConfig(mapping)
|
||||||
mapped_point = Mapping_engine.mapFeaturePoint(feature_point)
|
mapped_point = Mapping_engine.mapElementFromConf(feature_point)
|
||||||
} else {
|
} else {
|
||||||
mapped_point = mapElementFromConfSimple(feature_point, mapping)
|
mapped_point = mapElementFromConfSimple(feature_point, mapping)
|
||||||
}
|
}
|
||||||
@ -158,7 +163,7 @@ function convertDataForIRVE (sourceFilePath, mapping, pointCounterMax, boundingB
|
|||||||
// write file on disk
|
// write file on disk
|
||||||
let fileNameToWrite = 'my_converted_data_set' + filteredName + '.json'
|
let fileNameToWrite = 'my_converted_data_set' + filteredName + '.json'
|
||||||
console.log('write file ', fileNameToWrite)
|
console.log('write file ', fileNameToWrite)
|
||||||
writeJsonFile(fileNameToWrite, JSON.stringify(converted_geo_json, null, 2))
|
writeFile(fileNameToWrite, JSON.stringify(converted_geo_json, null, 2))
|
||||||
|
|
||||||
debugLog('mapped output:', converted_geo_json.features)
|
debugLog('mapped output:', converted_geo_json.features)
|
||||||
|
|
||||||
@ -211,29 +216,16 @@ function mapElementFromConfSimple (featurePoint, mappingConfig) {
|
|||||||
return basePoint
|
return basePoint
|
||||||
}
|
}
|
||||||
|
|
||||||
function writeJsonFile (fileName, fileContent) {
|
if (use_mappping_engine) {
|
||||||
debugLog('write file ', fileName)
|
console.log('using mapping engine')
|
||||||
|
console.log('pointCounterMax', pointCounterMax)
|
||||||
return fs.writeFile(
|
|
||||||
`./output/${fileName}`,
|
|
||||||
fileContent,
|
|
||||||
'utf8',
|
|
||||||
(err) => {
|
|
||||||
if (err) {
|
|
||||||
debugLog(`Error writing file: ${err}`)
|
|
||||||
} else {
|
|
||||||
debugLog(`File ${fileName} is written successfully!`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('pointCounterMax', pointCounterMax)
|
|
||||||
|
|
||||||
if (!use_mappping_engine) {
|
|
||||||
convertDataForIRVE(sourceFilePathGeoJson, mappingConfigIRVE_simple, pointCounterMax, boundingBoxCoordinates)
|
|
||||||
} else {
|
|
||||||
convertDataForIRVE(sourceFilePathGeoJson, mappingConfigIRVE, pointCounterMax, boundingBoxCoordinates)
|
convertDataForIRVE(sourceFilePathGeoJson, mappingConfigIRVE, pointCounterMax, boundingBoxCoordinates)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
convertDataForIRVE(sourceFilePathGeoJson, mappingConfigIRVE_simple, pointCounterMax, boundingBoxCoordinates)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,23 @@
|
|||||||
import debugLog from './utils.mjs'
|
|
||||||
|
import custom_utils from './utils.mjs'
|
||||||
|
|
||||||
|
|
||||||
|
const { debugLog } = custom_utils
|
||||||
|
|
||||||
|
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',
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
export default class {
|
export default class {
|
||||||
config = {}
|
mapping_config = {}
|
||||||
|
|
||||||
constructor (mappingConfig) {
|
constructor (mappingConfig) {
|
||||||
|
|
||||||
@ -9,13 +25,13 @@ export default class {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setConfig (mappingConfig) {
|
setConfig (mappingConfig) {
|
||||||
this.config = mappingConfig
|
this.mapping_config = mappingConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
mapFeaturePoint (featurePointGeoJson) {
|
mapFeaturePoint (featurePointGeoJson) {
|
||||||
|
|
||||||
let geoJSONConvertedPoint = {}
|
let geoJSONConvertedPoint = {}
|
||||||
geoJSONConvertedPoint.properties = { ...this.config.default_properties_of_point }
|
geoJSONConvertedPoint.properties = { ...this.mapping_config.default_properties_of_point }
|
||||||
geoJSONConvertedPoint.type = featurePointGeoJson.type
|
geoJSONConvertedPoint.type = featurePointGeoJson.type
|
||||||
geoJSONConvertedPoint.geometry = featurePointGeoJson.geometry
|
geoJSONConvertedPoint.geometry = featurePointGeoJson.geometry
|
||||||
|
|
||||||
@ -39,13 +55,14 @@ export default class {
|
|||||||
/**
|
/**
|
||||||
* retuns the converted element from mapping config if present, null otherwise
|
* retuns the converted element from mapping config if present, null otherwise
|
||||||
*/
|
*/
|
||||||
mapElementFromConf (featurePoint, mappingConfig) {
|
mapElementFromConf (featurePoint) {
|
||||||
let mappingKeys = Object.keys(mappingConfig)
|
console.log('config_name', this.mapping_config.config_name)
|
||||||
|
let mappingKeys = Object.keys(this.mapping_config.tags)
|
||||||
let featurePointPropertiesKeys = Object.keys(featurePoint.properties)
|
let featurePointPropertiesKeys = Object.keys(featurePoint.properties)
|
||||||
|
|
||||||
debugLog('keys', mappingKeys, featurePointPropertiesKeys)
|
console.log('keys', mappingKeys, featurePointPropertiesKeys)
|
||||||
|
|
||||||
let newProperties = defaultPropertiesOfPoint
|
let newProperties = Object.create(this.mapping_config.default_properties_of_point)
|
||||||
|
|
||||||
// reinit properties of current point
|
// reinit properties of current point
|
||||||
let basePoint = Object.create(featurePoint)
|
let basePoint = Object.create(featurePoint)
|
||||||
@ -56,8 +73,8 @@ export default class {
|
|||||||
// apply new properties if found in mapping config
|
// apply new properties if found in mapping config
|
||||||
featurePointPropertiesKeys.forEach(pointKeyName => {
|
featurePointPropertiesKeys.forEach(pointKeyName => {
|
||||||
|
|
||||||
if (mappingKeys.indexOf(pointKeyName) !== -1) {
|
if (!mappingKeys.indexOf(pointKeyName) !== -1) {
|
||||||
debugLog('found element', pointKeyName, '=>', mappingConfig[pointKeyName], 'value : ', featurePoint.properties[pointKeyName])
|
debugLog('found element', pointKeyName, '=>', this.mapping_config[pointKeyName], 'value : ', featurePoint.properties[pointKeyName])
|
||||||
let convertedValue = ''
|
let convertedValue = ''
|
||||||
|
|
||||||
let valueConvertedFromMapping = featurePoint.properties[pointKeyName]
|
let valueConvertedFromMapping = featurePoint.properties[pointKeyName]
|
||||||
@ -68,14 +85,16 @@ export default class {
|
|||||||
let isConfigMappingObject = typeofValue === 'string'
|
let isConfigMappingObject = typeofValue === 'string'
|
||||||
|
|
||||||
if (isStringValue) {
|
if (isStringValue) {
|
||||||
if (isBooleanKey(pointKeyName)) {
|
console.log('string value')
|
||||||
convertedValue = (valueConvertedFromMapping + '').toLowerCase() == 'true' ? 'yes' : 'no'
|
if (this.isBooleanKey(pointKeyName)) {
|
||||||
|
let lowerValue = (valueConvertedFromMapping + '').toLowerCase()
|
||||||
|
convertedValue = this.truthyValues.indexOf(lowerValue) ? 'yes' : 'no'
|
||||||
} else {
|
} else {
|
||||||
convertedValue = valueConvertedFromMapping
|
convertedValue = valueConvertedFromMapping
|
||||||
}
|
}
|
||||||
|
|
||||||
if (convertedValue) {
|
if (convertedValue) {
|
||||||
newProperties[mappingConfig[pointKeyName]] = convertedValue
|
newProperties[this.mapping_config[pointKeyName]] = convertedValue
|
||||||
}
|
}
|
||||||
} else if (isConfigMappingObject) {
|
} else if (isConfigMappingObject) {
|
||||||
let newKey = ''
|
let newKey = ''
|
||||||
@ -103,12 +122,12 @@ export default class {
|
|||||||
// convertir la valeur, si elle est truthy, la transformer en ce que donne la propriété truthy_value
|
// convertir la valeur, si elle est truthy, la transformer en ce que donne la propriété truthy_value
|
||||||
// exemple: le jeu de données dit que la colonne cable_t2_attache vaut "True", mais on veut le convertir en "1".
|
// exemple: le jeu de données dit que la colonne cable_t2_attache vaut "True", mais on veut le convertir en "1".
|
||||||
// on met donc truthy_value: '1'
|
// on met donc truthy_value: '1'
|
||||||
if (this.truthyValues.indexOf( valueConvertedFromMapping) !== -1) {
|
if (this.truthyValues.indexOf(valueConvertedFromMapping) !== -1) {
|
||||||
convertedValue = conditionnalConfig.truthy_value
|
convertedValue = conditionnalConfig.truthy_value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (conditionnalConfig.falsy_value) {
|
if (conditionnalConfig.falsy_value) {
|
||||||
if (this.falsyValues.indexOf( valueConvertedFromMapping) !== -1) {
|
if (this.falsyValues.indexOf(valueConvertedFromMapping) !== -1) {
|
||||||
convertedValue = conditionnalConfig.falsy_value
|
convertedValue = conditionnalConfig.falsy_value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
|
|
||||||
|
|
||||||
let show_debug = 0
|
let show_debug = 0
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -7,26 +5,27 @@ let show_debug = 0
|
|||||||
* @param message
|
* @param message
|
||||||
*/
|
*/
|
||||||
function debugLog (message) {
|
function debugLog (message) {
|
||||||
if (!show_debug) {
|
if (!show_debug) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
console.log('debug: ', ...message)
|
console.log('debug: ', ...message)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* TODO
|
||||||
|
* find the domain of all columns in a csv,
|
||||||
|
* take the header and the values, return only the unique values for each column, save a new csv,
|
||||||
|
and build a config for the mapping engine listing all the possible values.
|
||||||
* @param pointKeyName
|
* @param pointKeyName
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
function openCSV(filePath) {
|
function openCSV (filePath) {
|
||||||
|
|
||||||
console.log('open csv filePath')
|
console.log('open csv filePath')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
export default
|
export default {
|
||||||
{
|
debugLog,
|
||||||
debugLog,
|
isBooleanKey
|
||||||
isBooleanKey
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
|
import fs from 'node-fs'
|
||||||
|
|
||||||
|
let show_debug = 1
|
||||||
let show_debug = 0
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* faire un log
|
* faire un log
|
||||||
@ -10,7 +10,7 @@ function debugLog (message) {
|
|||||||
if (!show_debug) {
|
if (!show_debug) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
console.log('debug: ', ...message)
|
console.log('debug: ', message)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -37,8 +37,25 @@ function isBooleanKey(pointKeyName) {
|
|||||||
return listOfBooleanKeys.indexOf(pointKeyName) !== -1
|
return listOfBooleanKeys.indexOf(pointKeyName) !== -1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function writeFile (fileName, fileContent) {
|
||||||
|
debugLog('write file ', fileName)
|
||||||
|
|
||||||
|
return fs.writeFile(
|
||||||
|
`./output/${fileName}`,
|
||||||
|
fileContent,
|
||||||
|
'utf8',
|
||||||
|
(err) => {
|
||||||
|
if (err) {
|
||||||
|
debugLog(`Error writing file: ${err}`)
|
||||||
|
} else {
|
||||||
|
debugLog(`File ${fileName} is written successfully!`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
export default
|
export default
|
||||||
{
|
{
|
||||||
debugLog,
|
debugLog,
|
||||||
isBooleanKey
|
isBooleanKey,
|
||||||
|
writeFile
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user