2025-01-15 22:20:14 +01:00
import MappingConfigType from "./mapping-config.type" ;
import Formatters from "./formatters" ;
2025-04-11 15:53:23 +02:00
import config from "../config" ;
import custom_utils from "./utils" ;
import { detectSocketOutputFromFeaturePoint } from "./irve.utils" ;
2025-01-15 22:20:14 +01:00
2025-04-10 12:53:03 +02:00
const { debugLog , find_max_in_string , truncate_enums_to_limit } = custom_utils
2025-01-15 22:20:14 +01:00
2025-04-11 15:53:23 +02:00
/ * *
* Class that helps to convert values into predefined formats
* /
export default class MappingEngine {
2025-01-15 22:20:14 +01:00
mapping_config : any = { }
public stats : any ;
2025-04-11 15:53:23 +02:00
2025-01-15 22:20:14 +01:00
private jardinage = false ;
private current_converted_geojson_point : any ;
private current_geojson_point : any ; // currently converting point
constructor ( mappingConfig : MappingConfigType ) {
2025-04-28 00:34:41 +02:00
this . mapping_config = mappingConfig ;
2025-01-15 22:20:14 +01:00
this . stats = {
filtered_by_excluded_tags : 0 ,
phones_updated : 0 ,
power_output : 0 ,
phones_updated_list : [ ] ,
2025-04-27 23:41:47 +02:00
phones_not_updated : 0 ,
enumeration_detected : 0
2025-01-15 22:20:14 +01:00
}
}
setConfig ( mappingConfig : MappingConfigType ) {
2025-04-28 00:34:41 +02:00
//debugLog('load config', mappingConfig.config_name);
this . mapping_config = mappingConfig ;
2025-01-15 22:20:14 +01:00
}
getConfig() {
return this . mapping_config
}
mapFeaturePoint ( featurePointGeoJson : any ) {
let geoJSONConvertedPoint : any = { }
2025-04-10 12:53:03 +02:00
geoJSONConvertedPoint . properties = { . . . this . mapping_config . default_properties_of_point }
2025-01-15 22:20:14 +01:00
geoJSONConvertedPoint . type = featurePointGeoJson . type
geoJSONConvertedPoint . geometry = featurePointGeoJson . geometry
this . current_converted_geojson_point = geoJSONConvertedPoint
return geoJSONConvertedPoint
}
/ * *
* filter : reduce number of features
* @param offsetCount
* @param listOfFeatures
* /
filterFeaturesByOffset ( offsetCount : number , listOfFeatures : any ) : Array < any > {
let filteredList = listOfFeatures
// TODO
return filteredList
}
/ * *
* filterFeaturesByPropertyRegex
* TODO
* @param propertyName
* @param criteriaRegex
* @param listOfFeatures
* /
filterFeaturesByPropertyRegex ( propertyName : string , criteriaRegex : any , listOfFeatures : any ) {
let filteredList = listOfFeatures . filter ( ( feature : any ) = > {
return criteriaRegex . test ( feature ? . properties [ propertyName ] )
} )
return filteredList
}
/ * *
* filter a list of geojson points if one of the given exludedKeys is present in their properties .
* Example , we do not want to convert already present OSM point which have an osm_id value in their properties .
* @param list
* @param excludedKeys
* /
filterListOfPointsByExcludingIfKeyFilled ( list : any , excludedKeys : Array < string > ) : any [ ] {
let newList : Array < any > = [ ]
list . forEach ( ( geojsonPoint : any ) = > {
let pointProperties = Object . keys ( geojsonPoint . properties )
let addPoint = true ;
excludedKeys . forEach ( ( key : any ) = > {
debugLog ( key , 'pointProperties[key]' , pointProperties [ key ] )
let foundProperty : string = pointProperties [ key ]
if ( foundProperty && foundProperty !== 'null' ) {
addPoint = false
}
} )
if ( addPoint ) {
// only add points that pass the not null filter
newList . push ( geojsonPoint )
} else {
this . stats . filtered_by_excluded_tags ++
}
} )
return newList ;
}
2025-04-10 12:53:03 +02:00
filterListOfPointsByExcludingIfColumnBeforeSomeYear ( year : number , column : string , list_of_points : any [ ] ) : any [ ] {
2025-03-13 11:51:47 +01:00
let newList : any [ ] = [ ]
list_of_points . forEach ( ( geojsonPoint : any ) = > {
let pointProperties = Object . keys ( geojsonPoint . properties )
// trouver la valeur
// on inclut les points dont la date de création est de l'année demandée ou supérieure
if ( pointProperties . includes ( column ) &&
2025-04-10 12:53:03 +02:00
( geojsonPoint . properties [ column ] . substring ( 0 , 4 ) * 1 ) >= year
2025-03-13 11:51:47 +01:00
) {
newList . push ( geojsonPoint )
}
} )
return newList ;
}
2025-01-15 22:20:14 +01:00
filterListOfPointsByExcludingIfMaxPowerIsLesserThan ( minValue : number , list_of_points : any [ ] ) : any [ ] {
let newList : any [ ] = [ ]
list_of_points . forEach ( ( geojsonPoint : any ) = > {
let pointProperties = Object . keys ( geojsonPoint . properties )
// trouver la valeur
// socket_output_find_correspondances
if ( pointProperties . includes ( 'puissance_nominale' ) &&
2025-04-10 12:53:03 +02:00
1 * ( geojsonPoint . properties [ 'puissance_nominale' ] . replaceAll ( ' kW' , '' ) ) > minValue
2025-01-15 22:20:14 +01:00
) {
2025-04-10 12:53:03 +02:00
let max_power = find_max_in_string ( geojsonPoint . properties [ 'puissance_nominale' ] )
if ( max_power >= minValue ) {
newList . push ( geojsonPoint )
}
2025-01-15 22:20:14 +01:00
}
} )
return newList ;
}
/ * *
* retuns the converted element from mapping config if present , null otherwise
* /
mapElementFromConf ( featurePoint : any ) : any {
debugLog ( 'mapElementFromConf: mapElementFromConf' , featurePoint )
if ( ! this . mapping_config ) {
throw new Error ( 'no config was loaded in the mapping engine. use setConfig(my_mapping_config) on this instance of mapping engine before using this. Your config should be typed to MappingConfigType Type.' )
}
debugLog ( 'mapElementFromConf: config_name' , this . mapping_config . config_name )
let mappingKeys = Object . keys ( this . mapping_config . tags )
2025-04-10 12:53:03 +02:00
let featurePointPropertiesKeys : string [ ] = [ ] ;
2025-01-15 22:20:14 +01:00
if ( this . mapping_config . osmose ) {
2025-04-10 12:53:03 +02:00
featurePointPropertiesKeys = Object . keys ( featurePoint . properties . fixes [ 0 ] [ 0 ] . create ) ;
2025-01-15 22:20:14 +01:00
} else {
2025-04-10 12:53:03 +02:00
featurePointPropertiesKeys = Object . keys ( featurePoint . properties ) ;
2025-01-15 22:20:14 +01:00
}
2025-04-10 12:53:03 +02:00
let newProperties = { . . . this . mapping_config . default_properties_of_point }
2025-01-15 22:20:14 +01:00
// reinit properties of current point
let basePoint = Object . create ( featurePoint )
basePoint . type = featurePoint . type
basePoint . geometry = featurePoint . geometry
2025-04-10 12:53:03 +02:00
basePoint . properties = { . . . this . mapping_config . default_properties_of_point }
2025-01-15 22:20:14 +01:00
// apply new properties if found in mapping config
featurePointPropertiesKeys . forEach ( pointKeyName = > {
2025-04-11 15:53:23 +02:00
this . convertProperty ( {
pointKeyName , mappingKeys , featurePoint , newProperties
} )
2025-01-15 22:20:14 +01:00
} )
basePoint . properties = newProperties
return basePoint
}
/ * *
2025-04-11 15:53:23 +02:00
* convertit une propriété en une autre selon la config de mapping chargée
2025-01-15 22:20:14 +01:00
* @param pointKeyName
* @param mappingKeys
* @param featurePoint
* @param newProperties
* /
2025-04-11 15:53:23 +02:00
convertProperty ( options : {
pointKeyName : string ,
mappingKeys : any ,
featurePoint : any ,
newProperties : any
} ) {
const { pointKeyName , mappingKeys , featurePoint , newProperties } = options
2025-01-15 22:20:14 +01:00
this . current_geojson_point = featurePoint
let originalValue = ''
if ( this . mapping_config . osmose ) {
originalValue = featurePoint . properties . fixes [ 0 ] [ 0 ] . create [ pointKeyName ]
} else {
originalValue = featurePoint . properties [ pointKeyName ]
}
2025-04-11 15:53:23 +02:00
2025-01-15 22:20:14 +01:00
let mappingValueObject : any = '' ;
if ( mappingKeys . indexOf ( pointKeyName ) !== - 1 ) {
mappingValueObject = this . mapping_config . tags [ pointKeyName ]
debugLog ( 'convertProperty: mappingValueObject ' , mappingValueObject )
}
debugLog ( ' ------ convertProperty: pointKeyName' , pointKeyName )
// debugLog('convertProperty: mappingKeys', mappingKeys)
let remove_original_key = false ;
debugLog ( 'tags_to_ignore_if_value_is' , this . mapping_config . tags_to_ignore_if_value_is )
if ( this . mapping_config . tags_to_ignore_if_value_is && this . mapping_config . tags_to_ignore_if_value_is . length && this . mapping_config . tags_to_ignore_if_value_is ? . indexOf ( originalValue ) !== - 1 ) {
2025-05-13 23:59:21 +02:00
console . log ( '(x) => ignore' , originalValue , ' in ' , pointKeyName )
2025-01-15 22:20:14 +01:00
remove_original_key = true ;
}
if ( this . jardinage ) {
debugLog ( ' ------ on fait du jardinage' )
debugLog ( ' ------ mode mise en qualité activé' )
debugLog ( ' ------ les données en entrée sont des infos geojson extraites depuis overpass turbo.' )
debugLog ( ' ------ les clés des objets sont donc déjà dans le format de tag OSM,' +
'ne pas les convertir pour les mettre en qualité selon le modèle de mapping.' )
}
if ( this . mapping_config . add_not_mapped_tags_too && ( mappingKeys . indexOf ( pointKeyName ) === - 1 ) ) {
/ * *
* add all unmapped tags is enabled
* /
debugLog ( ' ------ add all unmapped tags is enabled' )
newProperties [ pointKeyName ] = originalValue ;
} else {
/ * *
* only use existing keys
* /
2025-04-17 17:34:39 +02:00
// console.log("only use existing keys,", pointKeyName)
2025-01-15 22:20:14 +01:00
if ( mappingKeys . indexOf ( pointKeyName ) !== - 1 ) {
let valueConvertedFromMapping = featurePoint . properties [ pointKeyName ]
let keyConvertedFromMapping = mappingKeys [ mappingKeys . indexOf ( pointKeyName ) ]
let mappingConfigOfTag = this . mapping_config . tags [ pointKeyName ]
2025-04-10 12:53:03 +02:00
2025-01-15 22:20:14 +01:00
debugLog ( '========== mappingConfigOfTag' , mappingConfigOfTag )
debugLog ( 'convertProperty: found element' , pointKeyName , '=>' , keyConvertedFromMapping , 'value : ' , valueConvertedFromMapping )
let convertedValue = originalValue
let typeOfConfigForKey = typeof mappingConfigOfTag
2025-04-17 17:34:39 +02:00
// console.log('typeOfConfigForKey', typeOfConfigForKey)
2025-01-15 22:20:14 +01:00
let isStringValue = typeOfConfigForKey === 'string'
let isConfigMappingObject = typeOfConfigForKey === 'object'
debugLog ( 'convertProperty: - typeofValue' , typeOfConfigForKey )
debugLog ( 'convertProperty: - pointKeyName' , pointKeyName )
debugLog ( 'convertProperty: - valueConvertedFromMapping' , valueConvertedFromMapping )
debugLog ( 'typeof valueConvertedFromMapping === \'string\'' , typeOfConfigForKey )
debugLog ( 'convertProperty: isStringValue?' , valueConvertedFromMapping , isStringValue )
debugLog ( 'convertProperty: isStringValue?' , valueConvertedFromMapping , isStringValue )
debugLog ( 'mappingConfigOfTag' , mappingConfigOfTag )
debugLog ( 'typeOfConfigForKey' , typeOfConfigForKey )
/ * *
* conversion si la clé à une config d ' une string , on ne change que la clé , pas la valeur
* /
if ( isStringValue ) {
debugLog ( 'convertProperty: -- string value' )
debugLog ( 'convertProperty: -- string value' )
debugLog ( 'convertProperty: -- simple conversion : ' , pointKeyName , '=> ' , mappingConfigOfTag , '_' , originalValue , '=>' , valueConvertedFromMapping )
debugLog ( 'convertProperty: -- convertedValue' , convertedValue )
convertedValue = valueConvertedFromMapping
if ( convertedValue ) {
newProperties [ mappingConfigOfTag ] = convertedValue
}
} else {
debugLog ( 'convertProperty: no string value' )
}
let configObject = mappingConfigOfTag
if ( isConfigMappingObject ) {
2025-04-17 17:34:39 +02:00
// console.log('convertProperty: is config object', configObject)
2025-01-15 22:20:14 +01:00
let newKey : any = '' + pointKeyName
if ( configObject . key_converted ) {
newKey = configObject . key_converted
debugLog ( 'key_converted newKey' , newKey )
}
if ( configObject . transform_function ) {
convertedValue = configObject . transform_function ( originalValue )
}
if ( configObject . truthy_value ) {
// convertir la valeur, si elle est truthy, la transformer en ce que donne la propriété truthy_value
// exemple: le jeu de données dit que la colonne cable_t2_attache vaut "True", mais on veut le convertir en "1".
// on met donc truthy_value: '1'
debugLog ( 'truthy_value' , originalValue )
2025-04-11 15:53:23 +02:00
if ( custom_utils . truthyValues . indexOf ( originalValue ) !== - 1 ) {
2025-01-15 22:20:14 +01:00
convertedValue = configObject . truthy_value
}
}
if ( configObject . falsy_value ) {
2025-04-11 15:53:23 +02:00
if ( custom_utils . falsyValues . indexOf ( originalValue ) !== - 1 ) {
2025-01-15 22:20:14 +01:00
convertedValue = configObject . falsy_value
}
}
/ * *
* conversion booléenne
* /
2025-05-13 23:59:21 +02:00
if ( mappingValueObject . keep_only_truthy_yes_or_no_without_enum ) {
if ( originalValue . indexOf ( ";" ) === - 1 && custom_utils . truthyValues . indexOf ( originalValue ) !== - 1 ) {
convertedValue = 'yes'
} else {
remove_original_key = true
}
}
2025-01-15 22:20:14 +01:00
if ( mappingValueObject . convert_to_boolean_value ) {
2025-05-13 23:59:21 +02:00
// debugLog('convertProperty: is boolean_value_conversion')
2025-01-15 22:20:14 +01:00
2025-04-28 22:24:41 +02:00
convertedValue = custom_utils . convertToYesOrNo ( originalValue )
2025-05-13 23:59:21 +02:00
// if (pointKeyName === 'prise_type_2') {
// console.log('convertProperty: is boolean_value_conversion', pointKeyName, keyConvertedFromMapping, originalValue, '=>', convertedValue)
// newProperties[keyConvertedFromMapping] = convertedValue
// }
// console.log('convertProperty: is boolean_value_conversion', pointKeyName, keyConvertedFromMapping, originalValue, '=>', convertedValue)
if ( configObject . ignore_if_falsy && ! custom_utils . convertToBoolean ( originalValue ) ) {
return newProperties
}
if ( configObject . ignore_if_truthy && custom_utils . convertToBoolean ( originalValue ) ) {
return newProperties
}
2025-01-15 22:20:14 +01:00
} else {
debugLog ( 'convertProperty: is NOT having boolean_value_conversion' , mappingValueObject )
}
2025-05-13 23:59:21 +02:00
if ( configObject . invert_boolean_value ) {
convertedValue = ! custom_utils . convertToBoolean ( originalValue ) ? 'yes' : 'no'
debugLog ( 'invert boolean' , convertedValue , originalValue )
}
2025-01-15 22:20:14 +01:00
// gestion des puissances de bornes
// avec une fonction de transformation des valeurs
// parmi le domaine du jeu de données
// nécessite une clé conditionnelle à la valeur true d'autres clés converties.
2025-04-11 15:53:23 +02:00
if ( configObject . keep_only_max_in_enum ) {
let max = custom_utils . find_max_in_string ( originalValue )
if ( max && max < 401 ) {
convertedValue = max + ' kW'
2025-01-15 22:20:14 +01:00
} else {
2025-04-11 15:53:23 +02:00
convertedValue = originalValue
2025-01-15 22:20:14 +01:00
}
2025-04-11 15:53:23 +02:00
}
if ( configObject . socket_output_find_correspondances ) {
2025-01-15 22:20:14 +01:00
2025-04-11 15:53:23 +02:00
convertedValue = detectSocketOutputFromFeaturePoint ( {
pointKeyName , mappingKeys , featurePoint , newProperties , originalValue
} )
2025-01-15 22:20:14 +01:00
}
2025-05-13 23:59:21 +02:00
2025-01-15 22:20:14 +01:00
if ( configObject . remove_stars ) {
2025-04-10 12:53:03 +02:00
// Remplace toutes les occurrences de * de manière greedy
2025-05-13 23:59:21 +02:00
convertedValue = originalValue . replace ( '*' , '' )
2025-01-15 22:20:14 +01:00
debugLog ( 'remove_stars' , convertedValue , originalValue )
}
if ( configObject . convert_to_phone ) {
convertedValue = Formatters . convertToPhone ( originalValue )
if ( originalValue !== convertedValue ) {
this . stats . phones_updated ++
this . stats . phones_updated_list . push ( convertedValue )
} else {
this . stats . phones_not_updated ++
}
debugLog ( 'convertedValue convert_to_phone' , originalValue , '=>' , convertedValue )
}
if ( configObject . convert_to_name ) {
convertedValue = Formatters . convertToName ( originalValue )
}
if ( configObject . remove_original_key ) {
remove_original_key = true
}
2025-05-13 23:59:21 +02:00
if ( configObject . ignore_if_falsy && ( false === custom_utils . convertToBoolean ( originalValue ) ) ) {
2025-01-15 22:20:14 +01:00
remove_original_key = true
}
2025-04-28 22:24:41 +02:00
if ( configObject . ignore_if_truthy && custom_utils . convertToBoolean ( originalValue ) ) {
2025-01-15 22:20:14 +01:00
remove_original_key = true
}
2025-04-10 12:53:03 +02:00
if ( configObject . truncate_enums_to_limit ) {
// console.log('configObject.truncate_enums_to_limit', configObject)
convertedValue = custom_utils . truncate_enums_to_limit ( convertedValue , configObject . truncate_enums_to_limit )
debugLog ( 'truncate_enums_to_limit => ' , convertedValue )
}
2025-04-17 17:57:29 +02:00
let conditionalConfig : any = ''
2025-05-13 23:59:21 +02:00
// console.log('/////////// configObject.ignore_if_falsy', configObject.ignore_if_falsy, "converti en booléen", custom_utils.convertToBoolean(originalValue), "remove?", remove_original_key)
2025-01-15 22:20:14 +01:00
/ * *
* config pour une clé
* nous pouvons renseigner une string ou un objet décrivant les transformations à réaliser
* /
2025-05-13 23:59:21 +02:00
if ( ! remove_original_key && configObject . conditional_values ) {
2025-01-15 22:20:14 +01:00
// convert numbers from json to string to compare them correctly
originalValue = '' + originalValue
let keysConditionnalValues : any = Object . keys ( configObject . conditional_values )
2025-04-17 17:57:29 +02:00
let foundValue = keysConditionnalValues . indexOf ( originalValue )
conditionalConfig = configObject . conditional_values [ keysConditionnalValues [ foundValue ] ]
// par défaut on retire les valeurs qui ne sont pas dans la liste des valeurs conditionnelles
// sauf si on a activé l'option allow_unspecified_conditional_values dans la MappingConfigType
if ( ! this . mapping_config . allow_unspecified_conditional_values && foundValue === - 1 ) {
2025-05-13 23:59:21 +02:00
// console.log('!!!!!!!!!! (x) => ignore', originalValue, ' in ', pointKeyName, 'on vire ', keyConvertedFromMapping)
2025-04-17 17:57:29 +02:00
remove_original_key = true
}
2025-01-15 22:20:14 +01:00
if ( ! remove_original_key ) {
2025-05-13 23:59:21 +02:00
// console.log('-------- on garde la valeur', originalValue, ' dans ', pointKeyName)
2025-01-15 22:20:14 +01:00
2025-04-17 17:57:29 +02:00
if ( foundValue !== - 1 ) {
debugLog ( 'found condition' , foundValue )
2025-01-15 22:20:14 +01:00
/ * * - - - - - - - - - - - - - - - - - - - - - -
* gestion des valeurs conditionnelles
* -- -- -- -- -- -- -- -- -- -- -- * /
2025-04-17 17:57:29 +02:00
debugLog ( 'conditionnalConfig' , conditionalConfig )
2025-01-15 22:20:14 +01:00
2025-04-17 17:57:29 +02:00
if ( conditionalConfig . ignore_this_data ) {
2025-01-15 22:20:14 +01:00
debugLog ( ` on ignore cette clé car sa valeur " ${ originalValue } " est à exclure: ` , pointKeyName , '=>' , newKey )
remove_original_key = true ;
}
2025-05-13 23:59:21 +02:00
let lowerKey = ( originalValue + '' ) . toLowerCase ( )
2025-04-17 17:57:29 +02:00
if ( conditionalConfig . truthy_value ) {
2025-01-15 22:20:14 +01:00
// convertir la valeur, si elle est truthy, la transformer en ce que donne la propriété truthy_value
// exemple: le jeu de données dit que la colonne cable_t2_attache vaut "True", mais on veut le convertir en "1".
// on met donc truthy_value: '1'
2025-05-13 23:59:21 +02:00
if ( custom_utils . truthyValues . indexOf ( lowerKey ) !== - 1 ) {
2025-04-17 17:57:29 +02:00
convertedValue = conditionalConfig . truthy_value
2025-01-15 22:20:14 +01:00
}
}
2025-04-17 17:57:29 +02:00
if ( conditionalConfig . falsy_value ) {
2025-05-13 23:59:21 +02:00
if ( custom_utils . falsyValues . indexOf ( lowerKey ) !== - 1 ) {
2025-04-17 17:57:29 +02:00
convertedValue = conditionalConfig . falsy_value
2025-01-15 22:20:14 +01:00
}
}
// use the value converted
2025-05-13 23:59:21 +02:00
if ( conditionalConfig . value_converted ) {
2025-04-17 17:57:29 +02:00
convertedValue = conditionalConfig . value_converted
2025-01-15 22:20:14 +01:00
}
2025-04-17 17:34:39 +02:00
2025-01-15 22:20:14 +01:00
}
2025-05-13 23:59:21 +02:00
// console.log('convertedValue =>', convertedValue)
if ( conditionalConfig ? . tags_to_add ) {
debugLog ( 'on ajoute des tags' , conditionalConfig . tags_to_add )
// on peut définir un ensemble de tags à rajouter
let tagKeys = Object . keys ( conditionalConfig . tags_to_add )
debugLog ( 'conditionnalConfig.tags_to_add' , conditionalConfig . tags_to_add )
tagKeys . forEach ( ( index : any ) = > {
debugLog ( 'key' , index )
debugLog ( 'value' , conditionalConfig . tags_to_add [ index ] )
newProperties [ index ] = conditionalConfig . tags_to_add [ index ]
} )
}
2025-01-15 22:20:14 +01:00
}
2025-05-13 23:59:21 +02:00
2025-04-17 17:34:39 +02:00
} else {
debugLog ( 'no conditional values' , configObject )
2025-01-15 22:20:14 +01:00
}
debugLog ( 'convertProperty: convertedValue ==========> {' , newKey , ':' , convertedValue , '}' )
debugLog ( ' =============== remove_original_key' , newKey , remove_original_key )
2025-04-10 12:53:03 +02:00
let keysOfConfigObject : string [ ] = [ ] ;
2025-01-15 22:20:14 +01:00
let hasKeyIgnoreThisData = false ;
if ( configObject ) {
keysOfConfigObject = Object . keys ( configObject )
debugLog ( 'keysOfConfigObject' , keysOfConfigObject )
hasKeyIgnoreThisData = ( keysOfConfigObject . indexOf ( 'ignore_this_data' ) !== - 1 )
2025-05-13 23:59:21 +02:00
// console.log('-------- hasKeyIgnoreThisData', hasKeyIgnoreThisData)
2025-01-15 22:20:14 +01:00
}
debugLog ( 'remove_original_key && newKey && convertedValue && hasKeyIgnoreThisData' , remove_original_key , newKey , convertedValue , hasKeyIgnoreThisData )
2025-04-17 17:34:39 +02:00
// console.log('newKey && convertedValue && !hasKeyIgnoreThisData', newKey && convertedValue && !hasKeyIgnoreThisData, newKey, convertedValue, !hasKeyIgnoreThisData)
2025-05-13 23:59:21 +02:00
// failsafe for boolean values, OSM never returns true or false
if ( convertedValue == 'true' ) {
convertedValue = 'yes'
2025-04-17 17:34:39 +02:00
}
2025-05-13 23:59:21 +02:00
if ( convertedValue == 'false' ) {
convertedValue = 'no'
}
if ( newKey && convertedValue && ! hasKeyIgnoreThisData && ! remove_original_key
2025-01-15 22:20:14 +01:00
) {
debugLog ( 'convertedValue' , convertedValue )
debugLog ( 'convertProperty: added' , newKey , ( ` ${ convertedValue } ` ) . trim ( ) )
newProperties [ newKey ] = ( ` ${ convertedValue } ` ) . trim ( )
}
2025-05-13 23:59:21 +02:00
if ( remove_original_key ) {
// console.log('remove_original_key', pointKeyName, originalValue, '=>', convertedValue)
delete newProperties [ pointKeyName ] ;
}
2025-01-15 22:20:14 +01:00
}
2025-04-17 17:34:39 +02:00
else {
debugLog ( '!!!!!! not isConfigMappingObject: ' , isConfigMappingObject )
}
2025-01-15 22:20:14 +01:00
} else {
debugLog ( '!!!!!! property not found in mappingKeys: ' , pointKeyName )
}
}
return newProperties ;
}
2025-04-27 23:41:47 +02:00
2025-01-15 22:20:14 +01:00
}