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 mappingConfigOfTag = this.mapping_config.tags[pointKeyName]
console.log('========== mappingConfigOfTag', mappingConfigOfTag)
debugLog('========== mappingConfigOfTag', mappingConfigOfTag)
debugLog('convertProperty: found element', pointKeyName, '=>', keyConvertedFromMapping, 'value : ', valueConvertedFromMapping)
let convertedValue = ''
@ -158,14 +158,14 @@ export default class {
debugLog('convertProperty: isStringValue?', valueConvertedFromMapping, isStringValue)
console.log('convertProperty: isStringValue?', valueConvertedFromMapping, isStringValue)
debugLog('convertProperty: isStringValue?', valueConvertedFromMapping, isStringValue)
console.log('mappingConfigOfTag', mappingConfigOfTag)
console.log('typeOfConfigForKey', typeOfConfigForKey)
debugLog('mappingConfigOfTag', mappingConfigOfTag)
debugLog('typeOfConfigForKey', typeOfConfigForKey)
if (isStringValue) {
console.log('convertProperty: -- string value')
debugLog('convertProperty: -- string value')
debugLog('convertProperty: -- string value')
if (this.isBooleanKey(pointKeyName)) {
let lowerValue = (valueConvertedFromMapping + '').toLowerCase()
@ -173,7 +173,7 @@ export default class {
convertedValue = this.truthyValues.indexOf(lowerValue) ? 'yes' : 'no'
} else {
console.log('convertProperty: -- simple conversion : ', pointKeyName, '_', originalValue, '=>', valueConvertedFromMapping)
debugLog('convertProperty: -- simple conversion : ', pointKeyName, '_', originalValue, '=>', valueConvertedFromMapping)
convertedValue = valueConvertedFromMapping
}
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
*/
if (configObject.conditional_values) {
console.log('convertProperty: conditional_values__________',
debugLog('convertProperty: conditional_values__________',
configObject.conditional_values)
let keysConditionnalValues: any = Object.keys(configObject.conditional_values)
let isFoundValue = keysConditionnalValues.indexOf(originalValue)
console.log('isFoundValue', isFoundValue)
console.log('keysConditionnalValues', keysConditionnalValues)
debugLog('isFoundValue', isFoundValue)
debugLog('keysConditionnalValues', keysConditionnalValues)
/** ----------------------
* gestion des valeurs conditionnelles
* ---------------------- */
if (isFoundValue !== -1) {
let conditionnalConfig: any = configObject.conditional_values[keysConditionnalValues[isFoundValue]]
if (conditionnalConfig.tags_to_add) {
// on peut définir un ensemble de tags à rajouter
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) => {
console.log('object', object)
console.log('pair', pair)
debugLog('object', object)
debugLog('pair', pair)
let key: any = Object.keys(object)
key = key[0]
let value = object[key]
console.log('key', key)
console.log('value', value)
debugLog('key', key)
debugLog('value', value)
newProperties[key] = value
})
}
@ -278,7 +282,7 @@ export default class {
}
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) {
debugLog('convertProperty: added')

View File

@ -33,20 +33,39 @@ export default interface MappingConfigType{
/**
* configuration concernant toutes les valeurs
*/
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,
transform_function?:Function,
}
/**
* choix de conversion de la valeur originale selon des critères donnés
*/
export interface ConditionnalValuesConfigType{
key_converted?:string,
value_converted?:string,
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,
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>
}