This commit is contained in:
Tykayn 2023-08-05 14:24:19 +02:00 committed by tykayn
parent 5793737fd6
commit e9ec74601b
6 changed files with 56 additions and 34 deletions

View File

@ -195,15 +195,13 @@ function convertDataForIRVE(sourceFilePath: string, mapping: any, pointCounterMa
feature_points_after_filter.forEach((feature_point: any) => {
// debugLog('featurePoint.properties.consolidated_code_postal', feature_point.properties.consolidated_code_postal)
debugLog('convert : work on 1 point')
debugLog('convert :featurePoint', feature_point)
console.log('convert :feature_point', feature_point)
// debugLog('convert :featurePoint', feature_point)
let mapped_point: any = {}
if (use_mapping_engine) {
debugLog('convert :using mapping engine on feature point'
, feature_point
)
// debugLog('convert :using mapping engine on feature point'
// , feature_point
// )
mapped_point = Mapping_engine.mapElementFromConf(feature_point)
console.log('mapped_point', mapped_point)
} else {
@ -225,13 +223,13 @@ function convertDataForIRVE(sourceFilePath: string, mapping: any, pointCounterMa
if (converted_geo_json.features.length) {
let fileNameToWrite = 'my_converted_data_set' + filteredName + '.json'
debugLog('write file ', fileNameToWrite)
debugLog('convert : write file ', fileNameToWrite)
writeFile(fileNameToWrite, JSON.stringify(converted_geo_json, null, 2))
} else {
debugLog('no writing of file, because there is no converted feature')
debugLog('convert : no writing of file, because there is no converted feature')
}
debugLog('mapped output:', converted_geo_json.features)
console.log('convert : converted_geo_json output:', converted_geo_json.features)
return converted_geo_json
}

View File

@ -31,10 +31,7 @@ const MappingIRVE: MappingConfigType = {
paiement_acte: 'authentication:none',
reservation: {
key_converted: 'reservation',
truthy_value: 'yes',
falsy_value: 'no',
// boolean_value_conversion: true, // convertit en yes ou no
boolean_value_conversion: true, // convertit en yes ou no
},
observations: 'note',
nom_station: 'name',
@ -88,17 +85,17 @@ const MappingIRVE: MappingConfigType = {
// value_converted: ""
// }
// choix:
// choix:
// Sa:09:00-19:00
// 24/7
// Mo-Fr 08:00-12:00,Mo-Fr 14:00-19:00,Sat 09:00-18:00
// Mo-Fr 08:00-19:00,Sat 09:00-18:00
// Sa:08:00-19:00
// 24/7
// Mo-Fr 08:30-12:00,Mo-Fr 14:00-19:00,Sat 09:00-18:30
// Mo-Fr 09:00-16:00
// Mo-Fr 08:00-12:00,Mo-Fr 14:00-18:00,Th 08:00-18:00
// Sa:09:00-19:00
// 24/7
// Mo-Fr 08:00-12:00,Mo-Fr 14:00-19:00,Sat 09:00-18:00
// Mo-Fr 08:00-19:00,Sat 09:00-18:00
// Sa:08:00-19:00
// 24/7
// Mo-Fr 08:30-12:00,Mo-Fr 14:00-19:00,Sat 09:00-18:30
// Mo-Fr 09:00-16:00
// Mo-Fr 08:00-12:00,Mo-Fr 14:00-18:00,Th 08:00-18:00
}
},

View File

@ -83,7 +83,7 @@ export default class {
* retuns the converted element from mapping config if present, null otherwise
*/
mapElementFromConf(featurePoint: any): any {
debugLog('mapElementFromConf: mapElementFromConf', featurePoint)
// debugLog('mapElementFromConf: mapElementFromConf', featurePoint)
if (!this.mapping_config) {
throw new Error('no config was loaded in the mapping engine. use setConfig(my_mapping_config) on this instance of mapping engine before using this.')
}
@ -113,7 +113,7 @@ export default class {
basePoint.properties = newProperties
debugLog('mapElementFromConf: basePoint', basePoint)
// debugLog('mapElementFromConf: basePoint', basePoint)
return basePoint
}
@ -126,9 +126,18 @@ export default class {
*/
convertProperty(pointKeyName: string, mappingKeys: any, featurePoint: any, newProperties: any) {
let originalValue = featurePoint.properties[pointKeyName]
let mappingValueObject: any = '';
debugLog('convertProperty: pointKeyName', pointKeyName)
if (mappingKeys.indexOf(pointKeyName) > 0) {
mappingValueObject = this.mapping_config.tags[pointKeyName]
debugLog('convertProperty: mappingValueObject ', mappingValueObject)
}
debugLog(' ------ convertProperty: pointKeyName', pointKeyName)
// debugLog('convertProperty: mappingKeys', mappingKeys)
/**
* only use existing keys
*/
if (mappingKeys.indexOf(pointKeyName) > 0) {
let valueConvertedFromMapping = featurePoint.properties[pointKeyName]
let keyConvertedFromMapping = mappingKeys[mappingKeys.indexOf(pointKeyName)]
@ -147,6 +156,7 @@ export default class {
debugLog('convertProperty: isStringValue?', isStringValue)
if (isStringValue) {
console.log('convertProperty: -- string value')
debugLog('convertProperty: -- string value')
if (this.isBooleanKey(pointKeyName)) {
let lowerValue = (valueConvertedFromMapping + '').toLowerCase()
@ -164,27 +174,32 @@ export default class {
debugLog('convertProperty: no string value')
}
// TODO handle config object for complex mapping
if (isConfigMappingObject) {
debugLog('convertProperty: is config object')
let newKey = ''
let configObject = valueConvertedFromMapping
debugLog('convertProperty: is config object', configObject)
let newKey = '' + pointKeyName
if (configObject.key_converted) {
newKey = configObject.key_converted
} else {
newKey = pointKeyName
}
/**
* conversion booléenne
*/
if (configObject.boolean_value_conversion) {
debugLog('convertProperty: is boolean_value_conversion' )
if (mappingValueObject.boolean_value_conversion) {
debugLog('convertProperty: is boolean_value_conversion')
debugLog('convertProperty: ==========> original value', originalValue)
if (this.truthyValues.indexOf(originalValue) !== -1) {
convertedValue = 'yes'
}
if (this.falsyValues.indexOf(originalValue) !== -1) {
convertedValue = 'no'
}
} else {
debugLog('convertProperty: is NOT having boolean_value_conversion', mappingValueObject)
}
/**
@ -227,7 +242,10 @@ export default class {
}
}
debugLog('convertProperty: convertedValue ==========> {', newKey, ':', convertedValue, '}')
if (newKey && !configObject.ignore_this_data) {
debugLog('convertProperty: added')
newProperties[newKey] = convertedValue
}
}

View File

@ -1,7 +1,7 @@
import fs from 'fs'
let show_debug = 0
show_debug = 1
// show_debug = 1
let output_folder = 'output';
console.log('----------------------show_debug', show_debug)

View File

@ -11,7 +11,10 @@
]
},
"properties": {
"reservation": "TRUE"
"amenity": "charging_station",
"reservation": "no",
"nom_amenageur": "Bob Lenon",
"siren_amenageur": "12345678"
}
}
]

View File

@ -11,7 +11,13 @@
]
},
"properties": {
"reservation": "TRUE"
"amenity": "charging_station",
"capacity": 12,
"reservation": "False",
"nom_amenageur": "Bob Lenon",
"siren_amenageur": "12345678",
"socket:typee": "no",
"socket:type2": "yes"
}
}
]