add types and tags to add

This commit is contained in:
Tykayn 2023-08-05 15:16:52 +02:00 committed by tykayn
parent 1405cde5d6
commit 59e2bc25c9
2 changed files with 44 additions and 21 deletions

View File

@ -143,7 +143,7 @@ export default class {
let keyConvertedFromMapping = mappingKeys[mappingKeys.indexOf(pointKeyName)] let keyConvertedFromMapping = mappingKeys[mappingKeys.indexOf(pointKeyName)]
let mappingConfigOfTag = this.mapping_config.tags[pointKeyName] let mappingConfigOfTag = this.mapping_config.tags[pointKeyName]
console.log('========== mappingConfigOfTag', mappingConfigOfTag) debugLog('========== mappingConfigOfTag', mappingConfigOfTag)
debugLog('convertProperty: found element', pointKeyName, '=>', keyConvertedFromMapping, 'value : ', valueConvertedFromMapping) debugLog('convertProperty: found element', pointKeyName, '=>', keyConvertedFromMapping, 'value : ', valueConvertedFromMapping)
let convertedValue = '' let convertedValue = ''
@ -158,14 +158,14 @@ export default class {
debugLog('convertProperty: isStringValue?', valueConvertedFromMapping, isStringValue) debugLog('convertProperty: isStringValue?', valueConvertedFromMapping, isStringValue)
console.log('convertProperty: isStringValue?', valueConvertedFromMapping, isStringValue) debugLog('convertProperty: isStringValue?', valueConvertedFromMapping, isStringValue)
console.log('mappingConfigOfTag', mappingConfigOfTag) debugLog('mappingConfigOfTag', mappingConfigOfTag)
console.log('typeOfConfigForKey', typeOfConfigForKey) debugLog('typeOfConfigForKey', typeOfConfigForKey)
if (isStringValue) { if (isStringValue) {
console.log('convertProperty: -- string value') debugLog('convertProperty: -- string value')
debugLog('convertProperty: -- string value') debugLog('convertProperty: -- string value')
if (this.isBooleanKey(pointKeyName)) { if (this.isBooleanKey(pointKeyName)) {
let lowerValue = (valueConvertedFromMapping + '').toLowerCase() let lowerValue = (valueConvertedFromMapping + '').toLowerCase()
@ -173,7 +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) debugLog('convertProperty: -- simple conversion : ', pointKeyName, '_', originalValue, '=>', valueConvertedFromMapping)
convertedValue = valueConvertedFromMapping convertedValue = valueConvertedFromMapping
} }
debugLog('convertProperty: -- convertedValue', convertedValue) debugLog('convertProperty: -- convertedValue', convertedValue)
@ -219,30 +219,34 @@ 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__________', debugLog('convertProperty: conditional_values__________',
configObject.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(originalValue) let isFoundValue = keysConditionnalValues.indexOf(originalValue)
console.log('isFoundValue', isFoundValue) debugLog('isFoundValue', isFoundValue)
console.log('keysConditionnalValues', keysConditionnalValues) debugLog('keysConditionnalValues', keysConditionnalValues)
/** ----------------------
* gestion des valeurs conditionnelles
* ---------------------- */
if (isFoundValue !== -1) { if (isFoundValue !== -1) {
let conditionnalConfig: any = configObject.conditional_values[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
let tagKeys = Object.keys(conditionnalConfig.tags_to_add) let tagKeys = Object.keys(conditionnalConfig.tags_to_add)
console.log('conditionnalConfig.tags_to_add', conditionnalConfig.tags_to_add) debugLog('conditionnalConfig.tags_to_add', conditionnalConfig.tags_to_add)
conditionnalConfig.tags_to_add.forEach((object: any, pair: any) => { conditionnalConfig.tags_to_add.forEach((object: any, pair: any) => {
console.log('object', object) debugLog('object', object)
console.log('pair', pair) debugLog('pair', pair)
let key: any = Object.keys(object) let key: any = Object.keys(object)
key = key[0] key = key[0]
let value = object[key] let value = object[key]
console.log('key', key) debugLog('key', key)
console.log('value', value) debugLog('value', value)
newProperties[key] = value newProperties[key] = value
}) })
} }
@ -278,7 +282,7 @@ export default class {
} }
debugLog('convertProperty: convertedValue ==========> {', newKey, ':', convertedValue, '}') debugLog('convertProperty: convertedValue ==========> {', newKey, ':', convertedValue, '}')
console.log(' =============== remove_original_key', remove_original_key) debugLog(' =============== remove_original_key', remove_original_key)
if (!remove_original_key && newKey && !configObject.ignore_this_data) { if (!remove_original_key && newKey && !configObject.ignore_this_data) {
debugLog('convertProperty: added') debugLog('convertProperty: added')

View File

@ -33,20 +33,39 @@ export default interface MappingConfigType{
/**
* configuration concernant toutes les valeurs
*/
export interface FeaturePropertyMappingConfigType{ export interface FeaturePropertyMappingConfigType{
[key:string]: any, [key:string]: any,
boolean_value_conversion?:boolean, boolean_value_conversion?:boolean,
remove_original_key?:boolean, remove_original_key?:boolean,
conditionnal_values?:ConditionnalValuesType, conditionnal_values?:ConditionnalValuesType,
transformer?:Function, transform_function?:Function,
}
export interface ConditionnalValuesType{
[key:string]: ConditionnalValuesConfigType,
} }
/**
* choix de conversion de la valeur originale selon des critères donnés
*/
export interface ConditionnalValuesConfigType{ export interface ConditionnalValuesConfigType{
key_converted?:string, key_converted?:string,
value_converted?:string, value_converted?:string,
truthy_value?:any, truthy_value?:any,
falsy_value?:any, falsy_value?:any, // si la valeur originale est falsy, la convertir en la valeur donnée ici
ignore_this_data?:boolean, ignore_this_data?:boolean,
tags_to_add?:TagsToAddConfig,
transform_function?:Function,
} }
export interface ConditionnalValuesType{
[key:string]: ConditionnalValuesConfigType,
}
interface OneOSMTag {
[key:string]: string,
}
export interface TagsToAddConfig{
tags_to_add: Array<OneOSMTag>
}