add conditionnal tags
This commit is contained in:
parent
e9ec74601b
commit
1405cde5d6
|
@ -203,7 +203,7 @@ function convertDataForIRVE(sourceFilePath: string, mapping: any, pointCounterMa
|
|||
// , feature_point
|
||||
// )
|
||||
mapped_point = Mapping_engine.mapElementFromConf(feature_point)
|
||||
console.log('mapped_point', mapped_point)
|
||||
debugLog('mapped_point', mapped_point)
|
||||
} else {
|
||||
debugLog('convert :using simple converter on feature point', feature_point)
|
||||
mapped_point = mapElementFromConfSimple(feature_point, mapping)
|
||||
|
|
|
@ -47,7 +47,7 @@ const MappingIRVE: MappingConfigType = {
|
|||
{
|
||||
key_converted: 'socket:type2_cable',
|
||||
// cable_t2_attache
|
||||
truthy_value: '1'
|
||||
truthy_value: '1',
|
||||
}
|
||||
,
|
||||
prise_type_ef: 'socket:typee',
|
||||
|
@ -100,7 +100,7 @@ const MappingIRVE: MappingConfigType = {
|
|||
}
|
||||
},
|
||||
station_deux_roues: {
|
||||
key_converted: null,
|
||||
remove_original_key: true,
|
||||
conditional_values: {
|
||||
// ajout de trois tags si la valeur est yes
|
||||
"yes": {
|
||||
|
@ -115,4 +115,16 @@ const MappingIRVE: MappingConfigType = {
|
|||
},
|
||||
}
|
||||
|
||||
|
||||
// "station_deux_roues": "yes",
|
||||
// "amenity": "charging_station",
|
||||
// "capacity": 12,
|
||||
// "reservation": "False",
|
||||
// "nom_amenageur": "Bob Lenon",
|
||||
// "siren_amenageur": "12345678",
|
||||
// "socket:typee": "False",
|
||||
// "socket:type2": "true",
|
||||
// "cable_t2_attache": "no",
|
||||
|
||||
|
||||
export default MappingIRVE;
|
||||
|
|
|
@ -51,8 +51,8 @@ export default class {
|
|||
return listOfBooleanKeys.indexOf(pointKeyName) !== -1
|
||||
}
|
||||
|
||||
truthyValues = ['true', 'True', 'TRUE', '1', 1]
|
||||
falsyValues = ['false', 'False', 'FALSE', '0', 0]
|
||||
truthyValues = ['true', 'True', 'TRUE', '1', 'yes', 1]
|
||||
falsyValues = ['false', 'False', 'FALSE', '0', 'no', 0]
|
||||
|
||||
/**
|
||||
* reduce number of features
|
||||
|
@ -141,20 +141,29 @@ export default class {
|
|||
if (mappingKeys.indexOf(pointKeyName) > 0) {
|
||||
let valueConvertedFromMapping = featurePoint.properties[pointKeyName]
|
||||
let keyConvertedFromMapping = mappingKeys[mappingKeys.indexOf(pointKeyName)]
|
||||
let mappingConfigOfTag = this.mapping_config.tags[pointKeyName]
|
||||
|
||||
console.log('========== mappingConfigOfTag', mappingConfigOfTag)
|
||||
debugLog('convertProperty: found element', pointKeyName, '=>', keyConvertedFromMapping, 'value : ', valueConvertedFromMapping)
|
||||
let convertedValue = ''
|
||||
|
||||
let typeofValue = typeof valueConvertedFromMapping
|
||||
let isStringValue = typeofValue === 'string'
|
||||
debugLog('convertProperty: - typeofValue', typeofValue)
|
||||
let typeOfConfigForKey = typeof mappingConfigOfTag
|
||||
let isStringValue = typeOfConfigForKey === 'string'
|
||||
let isConfigMappingObject = typeOfConfigForKey === 'object'
|
||||
|
||||
debugLog('convertProperty: - typeofValue', typeOfConfigForKey)
|
||||
debugLog('convertProperty: - pointKeyName', pointKeyName)
|
||||
debugLog('convertProperty: - valueConvertedFromMapping', valueConvertedFromMapping)
|
||||
debugLog('typeof valueConvertedFromMapping === \'string\'', typeofValue)
|
||||
debugLog('typeof valueConvertedFromMapping === \'string\'', typeOfConfigForKey)
|
||||
|
||||
|
||||
debugLog('convertProperty: isStringValue?', valueConvertedFromMapping, isStringValue)
|
||||
console.log('convertProperty: isStringValue?', valueConvertedFromMapping, isStringValue)
|
||||
|
||||
console.log('mappingConfigOfTag', mappingConfigOfTag)
|
||||
console.log('typeOfConfigForKey', typeOfConfigForKey)
|
||||
|
||||
let isConfigMappingObject = typeofValue === 'string'
|
||||
|
||||
debugLog('convertProperty: isStringValue?', isStringValue)
|
||||
if (isStringValue) {
|
||||
console.log('convertProperty: -- string value')
|
||||
debugLog('convertProperty: -- string value')
|
||||
|
@ -164,6 +173,7 @@ export default class {
|
|||
convertedValue = this.truthyValues.indexOf(lowerValue) ? 'yes' : 'no'
|
||||
|
||||
} else {
|
||||
console.log('convertProperty: -- simple conversion : ', pointKeyName, '_', originalValue, '=>', valueConvertedFromMapping)
|
||||
convertedValue = valueConvertedFromMapping
|
||||
}
|
||||
debugLog('convertProperty: -- convertedValue', convertedValue)
|
||||
|
@ -175,16 +185,18 @@ export default class {
|
|||
}
|
||||
|
||||
if (isConfigMappingObject) {
|
||||
let configObject = valueConvertedFromMapping
|
||||
let configObject = mappingConfigOfTag
|
||||
|
||||
debugLog('convertProperty: is config object', configObject)
|
||||
let newKey = '' + pointKeyName
|
||||
let newKey: any = '' + pointKeyName
|
||||
let remove_original_key = false;
|
||||
|
||||
if (configObject.key_converted) {
|
||||
newKey = configObject.key_converted
|
||||
} else {
|
||||
newKey = pointKeyName
|
||||
}
|
||||
// else {
|
||||
// newKey = pointKeyName
|
||||
// }
|
||||
|
||||
/**
|
||||
* conversion booléenne
|
||||
|
@ -207,14 +219,32 @@ export default class {
|
|||
* nous pouvons renseigner une string ou un objet décrivant les transformations à réaliser
|
||||
*/
|
||||
if (configObject.conditional_values) {
|
||||
console.log('convertProperty: conditional_values__________',
|
||||
configObject.conditional_values)
|
||||
|
||||
let keysConditionnalValues: any = Object.keys(configObject.conditional_values)
|
||||
let isFoundValue = keysConditionnalValues.indexOf(valueConvertedFromMapping)
|
||||
|
||||
let isFoundValue = keysConditionnalValues.indexOf(originalValue)
|
||||
console.log('isFoundValue', isFoundValue)
|
||||
console.log('keysConditionnalValues', keysConditionnalValues)
|
||||
if (isFoundValue !== -1) {
|
||||
let conditionnalConfig: any = keysConditionnalValues[isFoundValue]
|
||||
let conditionnalConfig: any = configObject.conditional_values[keysConditionnalValues[isFoundValue]]
|
||||
|
||||
if (conditionnalConfig.tags_to_add) {
|
||||
// on peut définir un ensemble de tags à rajouter
|
||||
newProperties.push(...conditionnalConfig.tags_to_add)
|
||||
let tagKeys = Object.keys(conditionnalConfig.tags_to_add)
|
||||
console.log('conditionnalConfig.tags_to_add', conditionnalConfig.tags_to_add)
|
||||
conditionnalConfig.tags_to_add.forEach((object: any, pair: any) => {
|
||||
console.log('object', object)
|
||||
console.log('pair', pair)
|
||||
let key: any = Object.keys(object)
|
||||
key = key[0]
|
||||
let value = object[key]
|
||||
|
||||
console.log('key', key)
|
||||
console.log('value', value)
|
||||
newProperties[key] = value
|
||||
})
|
||||
}
|
||||
if (conditionnalConfig.truthy_value) {
|
||||
// convertir la valeur, si elle est truthy, la transformer en ce que donne la propriété truthy_value
|
||||
|
@ -239,11 +269,17 @@ export default class {
|
|||
else if (conditionnalConfig.value_converted) {
|
||||
convertedValue = conditionnalConfig.value_converted
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
if (configObject.remove_original_key) {
|
||||
remove_original_key = true
|
||||
}
|
||||
}
|
||||
|
||||
debugLog('convertProperty: convertedValue ==========> {', newKey, ':', convertedValue, '}')
|
||||
if (newKey && !configObject.ignore_this_data) {
|
||||
console.log(' =============== remove_original_key', remove_original_key)
|
||||
if (!remove_original_key && newKey && !configObject.ignore_this_data) {
|
||||
|
||||
debugLog('convertProperty: added')
|
||||
newProperties[newKey] = convertedValue
|
||||
|
|
|
@ -17,12 +17,7 @@ export interface FeatureCollection{
|
|||
type:string,
|
||||
features:Array<GeoJsonFeature>,
|
||||
}
|
||||
export interface FeaturePropertyMappingConfigType{
|
||||
[key:string]: any,
|
||||
key_converted?:string,
|
||||
truthy_value?:any,
|
||||
transformer?:Function,
|
||||
}
|
||||
|
||||
export interface BoundingBoxCoordinatesType{
|
||||
xMin: number,
|
||||
xMax: number,
|
||||
|
@ -34,4 +29,24 @@ export default interface MappingConfigType{
|
|||
config_author: string,
|
||||
default_properties_of_point: object,
|
||||
tags: FeaturePropertyMappingConfigType
|
||||
}
|
||||
|
||||
|
||||
|
||||
export interface FeaturePropertyMappingConfigType{
|
||||
[key:string]: any,
|
||||
boolean_value_conversion?:boolean,
|
||||
remove_original_key?:boolean,
|
||||
conditionnal_values?:ConditionnalValuesType,
|
||||
transformer?:Function,
|
||||
}
|
||||
export interface ConditionnalValuesType{
|
||||
[key:string]: ConditionnalValuesConfigType,
|
||||
}
|
||||
export interface ConditionnalValuesConfigType{
|
||||
key_converted?:string,
|
||||
value_converted?:string,
|
||||
truthy_value?:any,
|
||||
falsy_value?:any,
|
||||
ignore_this_data?:boolean,
|
||||
}
|
|
@ -11,10 +11,9 @@
|
|||
]
|
||||
},
|
||||
"properties": {
|
||||
"amenity": "charging_station",
|
||||
"reservation": "no",
|
||||
"nom_amenageur": "Bob Lenon",
|
||||
"siren_amenageur": "12345678"
|
||||
"bicycle": "yes",
|
||||
"scooter": "yes",
|
||||
"motorcar": "no"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
|
@ -11,13 +11,8 @@
|
|||
]
|
||||
},
|
||||
"properties": {
|
||||
"amenity": "charging_station",
|
||||
"capacity": 12,
|
||||
"reservation": "False",
|
||||
"nom_amenageur": "Bob Lenon",
|
||||
"siren_amenageur": "12345678",
|
||||
"socket:typee": "no",
|
||||
"socket:type2": "yes"
|
||||
"goal": "jeu de données pour tester la mapping engine",
|
||||
"station_deux_roues": "yes"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue