add boolean conversion

This commit is contained in:
Tykayn 2023-08-05 13:45:31 +02:00 committed by tykayn
parent af4f6df4b5
commit 5793737fd6
6 changed files with 11010 additions and 12 deletions

View File

@ -14,15 +14,18 @@ const minimist = require('minimist')
const debugLog = utils.debugLog; const debugLog = utils.debugLog;
let use_mappping_engine = false let use_mapping_engine = false
use_mappping_engine = true use_mapping_engine = true
let Mapping_engine = new mapping_engine(mappingConfigIRVE) let Mapping_engine = new mapping_engine(mappingConfigIRVE)
let mini_arguments: any = minimist(process.argv.slice(2)) let mini_arguments: any = minimist(process.argv.slice(2))
let sourceFilePathGeoJson = './etalab_data/small.json' // let sourceFilePathGeoJson = './etalab_data/small.json'
// let sourceFilePathGeoJson = './etalab_data/all.json'
// let sourceFilePathGeoJson = './output/my_converted_data_set_filtered_zipcode_91.json'
let sourceFilePathGeoJson = './output/my_converted_data_set_filtered_zipcode_91_small.json'
// wip filter // wip filter
let filterOnBoundingBox = true let filterOnBoundingBox = true
@ -50,7 +53,7 @@ if (mini_arguments['source']) {
sourceFilePathGeoJson = mini_arguments['source'] sourceFilePathGeoJson = mini_arguments['source']
} }
if (mini_arguments['engine']) { if (mini_arguments['engine']) {
use_mappping_engine = mini_arguments['engine'] use_mapping_engine = mini_arguments['engine']
} }
let filterZipCode = new RegExp(`^${filterDepartment}`) let filterZipCode = new RegExp(`^${filterDepartment}`)
@ -197,7 +200,7 @@ function convertDataForIRVE(sourceFilePath: string, mapping: any, pointCounterMa
console.log('convert :feature_point', feature_point) console.log('convert :feature_point', feature_point)
let mapped_point: any = {} let mapped_point: any = {}
if (use_mappping_engine) { if (use_mapping_engine) {
debugLog('convert :using mapping engine on feature point' debugLog('convert :using mapping engine on feature point'
, feature_point , feature_point
) )
@ -280,7 +283,7 @@ function mapElementFromConfSimple(featurePoint: any, mappingConfig: any) {
return basePoint return basePoint
} }
if (use_mappping_engine) { if (use_mapping_engine) {
debugLog(' - using mapping engine') debugLog(' - using mapping engine')
debugLog(' - pointCounterMax', pointCounterMax) debugLog(' - pointCounterMax', pointCounterMax)
Mapping_engine.setConfig(mappingConfigIRVE) Mapping_engine.setConfig(mappingConfigIRVE)

View File

@ -30,7 +30,12 @@ const MappingIRVE: MappingConfigType = {
gratuit: 'fee', gratuit: 'fee',
paiement_acte: 'authentication:none', paiement_acte: 'authentication:none',
reservation: 'reservation', reservation: {
key_converted: 'reservation',
truthy_value: 'yes',
falsy_value: 'no',
// boolean_value_conversion: true, // convertit en yes ou no
},
observations: 'note', observations: 'note',
nom_station: 'name', nom_station: 'name',
nom_enseigne: 'network', nom_enseigne: 'network',

View File

@ -125,6 +125,8 @@ export default class {
* @param newProperties * @param newProperties
*/ */
convertProperty(pointKeyName: string, mappingKeys: any, featurePoint: any, newProperties: any) { convertProperty(pointKeyName: string, mappingKeys: any, featurePoint: any, newProperties: any) {
let originalValue = featurePoint.properties[pointKeyName]
debugLog('convertProperty: pointKeyName', pointKeyName) debugLog('convertProperty: pointKeyName', pointKeyName)
// debugLog('convertProperty: mappingKeys', mappingKeys) // debugLog('convertProperty: mappingKeys', mappingKeys)
if (mappingKeys.indexOf(pointKeyName) > 0) { if (mappingKeys.indexOf(pointKeyName) > 0) {
@ -172,6 +174,19 @@ export default class {
newKey = configObject.key_converted newKey = configObject.key_converted
} }
/**
* conversion booléenne
*/
if (configObject.boolean_value_conversion) {
debugLog('convertProperty: is boolean_value_conversion' )
if (this.truthyValues.indexOf(originalValue) !== -1) {
convertedValue = 'yes'
}
if (this.falsyValues.indexOf(originalValue) !== -1) {
convertedValue = 'no'
}
}
/** /**
* gestion des valeurs conditionnelles * gestion des valeurs conditionnelles
* nous pouvons renseigner une string ou un objet décrivant les transformations à réaliser * nous pouvons renseigner une string ou un objet décrivant les transformations à réaliser
@ -199,6 +214,7 @@ export default class {
convertedValue = conditionnalConfig.falsy_value convertedValue = conditionnalConfig.falsy_value
} }
} }
if (conditionnalConfig.transform_function) { if (conditionnalConfig.transform_function) {
// une transformation de la valeur // une transformation de la valeur
// apply transformation to value // apply transformation to value

View File

@ -6,13 +6,12 @@
"geometry": { "geometry": {
"type": "Point", "type": "Point",
"coordinates": [ "coordinates": [
4.822159, 2.198339,
45.635079 48.678843
] ]
}, },
"properties": { "properties": {
"nom_amenageur": "ELECTRA", "reservation": "TRUE"
"siren_amenageur": "891624884"
} }
} }
] ]

View File

@ -0,0 +1,18 @@
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
2.198339,
48.678843
]
},
"properties": {
"reservation": "TRUE"
}
}
]
}