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;
let use_mappping_engine = false
use_mappping_engine = true
let use_mapping_engine = false
use_mapping_engine = true
let Mapping_engine = new mapping_engine(mappingConfigIRVE)
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
let filterOnBoundingBox = true
@ -50,7 +53,7 @@ if (mini_arguments['source']) {
sourceFilePathGeoJson = mini_arguments['source']
}
if (mini_arguments['engine']) {
use_mappping_engine = mini_arguments['engine']
use_mapping_engine = mini_arguments['engine']
}
let filterZipCode = new RegExp(`^${filterDepartment}`)
@ -197,7 +200,7 @@ function convertDataForIRVE(sourceFilePath: string, mapping: any, pointCounterMa
console.log('convert :feature_point', feature_point)
let mapped_point: any = {}
if (use_mappping_engine) {
if (use_mapping_engine) {
debugLog('convert :using mapping engine on feature point'
, feature_point
)
@ -280,7 +283,7 @@ function mapElementFromConfSimple(featurePoint: any, mappingConfig: any) {
return basePoint
}
if (use_mappping_engine) {
if (use_mapping_engine) {
debugLog(' - using mapping engine')
debugLog(' - pointCounterMax', pointCounterMax)
Mapping_engine.setConfig(mappingConfigIRVE)

View File

@ -30,7 +30,12 @@ const MappingIRVE: MappingConfigType = {
gratuit: 'fee',
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',
nom_station: 'name',
nom_enseigne: 'network',

View File

@ -125,6 +125,8 @@ export default class {
* @param newProperties
*/
convertProperty(pointKeyName: string, mappingKeys: any, featurePoint: any, newProperties: any) {
let originalValue = featurePoint.properties[pointKeyName]
debugLog('convertProperty: pointKeyName', pointKeyName)
// debugLog('convertProperty: mappingKeys', mappingKeys)
if (mappingKeys.indexOf(pointKeyName) > 0) {
@ -172,6 +174,19 @@ export default class {
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
* 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
}
}
if (conditionnalConfig.transform_function) {
// une transformation de la valeur
// apply transformation to value

View File

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

View File

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