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
|
// , feature_point
|
||||||
// )
|
// )
|
||||||
mapped_point = Mapping_engine.mapElementFromConf(feature_point)
|
mapped_point = Mapping_engine.mapElementFromConf(feature_point)
|
||||||
console.log('mapped_point', mapped_point)
|
debugLog('mapped_point', mapped_point)
|
||||||
} else {
|
} else {
|
||||||
debugLog('convert :using simple converter on feature point', feature_point)
|
debugLog('convert :using simple converter on feature point', feature_point)
|
||||||
mapped_point = mapElementFromConfSimple(feature_point, mapping)
|
mapped_point = mapElementFromConfSimple(feature_point, mapping)
|
||||||
|
|
|
@ -47,7 +47,7 @@ const MappingIRVE: MappingConfigType = {
|
||||||
{
|
{
|
||||||
key_converted: 'socket:type2_cable',
|
key_converted: 'socket:type2_cable',
|
||||||
// cable_t2_attache
|
// cable_t2_attache
|
||||||
truthy_value: '1'
|
truthy_value: '1',
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
prise_type_ef: 'socket:typee',
|
prise_type_ef: 'socket:typee',
|
||||||
|
@ -100,7 +100,7 @@ const MappingIRVE: MappingConfigType = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
station_deux_roues: {
|
station_deux_roues: {
|
||||||
key_converted: null,
|
remove_original_key: true,
|
||||||
conditional_values: {
|
conditional_values: {
|
||||||
// ajout de trois tags si la valeur est yes
|
// ajout de trois tags si la valeur est yes
|
||||||
"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;
|
export default MappingIRVE;
|
||||||
|
|
|
@ -51,8 +51,8 @@ export default class {
|
||||||
return listOfBooleanKeys.indexOf(pointKeyName) !== -1
|
return listOfBooleanKeys.indexOf(pointKeyName) !== -1
|
||||||
}
|
}
|
||||||
|
|
||||||
truthyValues = ['true', 'True', 'TRUE', '1', 1]
|
truthyValues = ['true', 'True', 'TRUE', '1', 'yes', 1]
|
||||||
falsyValues = ['false', 'False', 'FALSE', '0', 0]
|
falsyValues = ['false', 'False', 'FALSE', '0', 'no', 0]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* reduce number of features
|
* reduce number of features
|
||||||
|
@ -141,20 +141,29 @@ export default class {
|
||||||
if (mappingKeys.indexOf(pointKeyName) > 0) {
|
if (mappingKeys.indexOf(pointKeyName) > 0) {
|
||||||
let valueConvertedFromMapping = featurePoint.properties[pointKeyName]
|
let valueConvertedFromMapping = featurePoint.properties[pointKeyName]
|
||||||
let keyConvertedFromMapping = mappingKeys[mappingKeys.indexOf(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)
|
debugLog('convertProperty: found element', pointKeyName, '=>', keyConvertedFromMapping, 'value : ', valueConvertedFromMapping)
|
||||||
let convertedValue = ''
|
let convertedValue = ''
|
||||||
|
|
||||||
let typeofValue = typeof valueConvertedFromMapping
|
let typeOfConfigForKey = typeof mappingConfigOfTag
|
||||||
let isStringValue = typeofValue === 'string'
|
let isStringValue = typeOfConfigForKey === 'string'
|
||||||
debugLog('convertProperty: - typeofValue', typeofValue)
|
let isConfigMappingObject = typeOfConfigForKey === 'object'
|
||||||
|
|
||||||
|
debugLog('convertProperty: - typeofValue', typeOfConfigForKey)
|
||||||
debugLog('convertProperty: - pointKeyName', pointKeyName)
|
debugLog('convertProperty: - pointKeyName', pointKeyName)
|
||||||
debugLog('convertProperty: - valueConvertedFromMapping', valueConvertedFromMapping)
|
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) {
|
if (isStringValue) {
|
||||||
console.log('convertProperty: -- string value')
|
console.log('convertProperty: -- string value')
|
||||||
debugLog('convertProperty: -- string value')
|
debugLog('convertProperty: -- string value')
|
||||||
|
@ -164,6 +173,7 @@ export default class {
|
||||||
convertedValue = this.truthyValues.indexOf(lowerValue) ? 'yes' : 'no'
|
convertedValue = this.truthyValues.indexOf(lowerValue) ? 'yes' : 'no'
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
console.log('convertProperty: -- simple conversion : ', pointKeyName, '_', originalValue, '=>', valueConvertedFromMapping)
|
||||||
convertedValue = valueConvertedFromMapping
|
convertedValue = valueConvertedFromMapping
|
||||||
}
|
}
|
||||||
debugLog('convertProperty: -- convertedValue', convertedValue)
|
debugLog('convertProperty: -- convertedValue', convertedValue)
|
||||||
|
@ -175,16 +185,18 @@ export default class {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isConfigMappingObject) {
|
if (isConfigMappingObject) {
|
||||||
let configObject = valueConvertedFromMapping
|
let configObject = mappingConfigOfTag
|
||||||
|
|
||||||
debugLog('convertProperty: is config object', configObject)
|
debugLog('convertProperty: is config object', configObject)
|
||||||
let newKey = '' + pointKeyName
|
let newKey: any = '' + pointKeyName
|
||||||
|
let remove_original_key = false;
|
||||||
|
|
||||||
if (configObject.key_converted) {
|
if (configObject.key_converted) {
|
||||||
newKey = configObject.key_converted
|
newKey = configObject.key_converted
|
||||||
} else {
|
|
||||||
newKey = pointKeyName
|
|
||||||
}
|
}
|
||||||
|
// else {
|
||||||
|
// newKey = pointKeyName
|
||||||
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* conversion booléenne
|
* conversion booléenne
|
||||||
|
@ -207,14 +219,32 @@ export default class {
|
||||||
* 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
|
||||||
*/
|
*/
|
||||||
if (configObject.conditional_values) {
|
if (configObject.conditional_values) {
|
||||||
|
console.log('convertProperty: conditional_values__________',
|
||||||
|
configObject.conditional_values)
|
||||||
|
|
||||||
let keysConditionnalValues: any = Object.keys(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) {
|
if (isFoundValue !== -1) {
|
||||||
let conditionnalConfig: any = keysConditionnalValues[isFoundValue]
|
let conditionnalConfig: any = configObject.conditional_values[keysConditionnalValues[isFoundValue]]
|
||||||
|
|
||||||
if (conditionnalConfig.tags_to_add) {
|
if (conditionnalConfig.tags_to_add) {
|
||||||
// on peut définir un ensemble de tags à rajouter
|
// 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) {
|
if (conditionnalConfig.truthy_value) {
|
||||||
// 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
|
||||||
|
@ -239,11 +269,17 @@ export default class {
|
||||||
else if (conditionnalConfig.value_converted) {
|
else if (conditionnalConfig.value_converted) {
|
||||||
convertedValue = conditionnalConfig.value_converted
|
convertedValue = conditionnalConfig.value_converted
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
if (configObject.remove_original_key) {
|
||||||
|
remove_original_key = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
debugLog('convertProperty: convertedValue ==========> {', newKey, ':', convertedValue, '}')
|
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')
|
debugLog('convertProperty: added')
|
||||||
newProperties[newKey] = convertedValue
|
newProperties[newKey] = convertedValue
|
||||||
|
|
|
@ -17,12 +17,7 @@ export interface FeatureCollection{
|
||||||
type:string,
|
type:string,
|
||||||
features:Array<GeoJsonFeature>,
|
features:Array<GeoJsonFeature>,
|
||||||
}
|
}
|
||||||
export interface FeaturePropertyMappingConfigType{
|
|
||||||
[key:string]: any,
|
|
||||||
key_converted?:string,
|
|
||||||
truthy_value?:any,
|
|
||||||
transformer?:Function,
|
|
||||||
}
|
|
||||||
export interface BoundingBoxCoordinatesType{
|
export interface BoundingBoxCoordinatesType{
|
||||||
xMin: number,
|
xMin: number,
|
||||||
xMax: number,
|
xMax: number,
|
||||||
|
@ -35,3 +30,23 @@ export default interface MappingConfigType{
|
||||||
default_properties_of_point: object,
|
default_properties_of_point: object,
|
||||||
tags: FeaturePropertyMappingConfigType
|
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": {
|
"properties": {
|
||||||
"amenity": "charging_station",
|
"bicycle": "yes",
|
||||||
"reservation": "no",
|
"scooter": "yes",
|
||||||
"nom_amenageur": "Bob Lenon",
|
"motorcar": "no"
|
||||||
"siren_amenageur": "12345678"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
@ -11,13 +11,8 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"properties": {
|
"properties": {
|
||||||
"amenity": "charging_station",
|
"goal": "jeu de données pour tester la mapping engine",
|
||||||
"capacity": 12,
|
"station_deux_roues": "yes"
|
||||||
"reservation": "False",
|
|
||||||
"nom_amenageur": "Bob Lenon",
|
|
||||||
"siren_amenageur": "12345678",
|
|
||||||
"socket:typee": "no",
|
|
||||||
"socket:type2": "yes"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in New Issue