improve mapping

This commit is contained in:
Tykayn 2023-08-05 16:06:44 +02:00 committed by tykayn
parent 59e2bc25c9
commit 32d3834792
5 changed files with 253 additions and 148 deletions

View File

@ -11,6 +11,7 @@ const MappingIRVE: MappingConfigType = {
default_properties_of_point: { default_properties_of_point: {
'amenity': 'charging_station' 'amenity': 'charging_station'
}, },
add_not_mapped_tags_too: false,
tags: { tags: {
// ******* nombres // ******* nombres
@ -31,9 +32,9 @@ const MappingIRVE: MappingConfigType = {
paiement_acte: 'authentication:none', paiement_acte: 'authentication:none',
reservation: { reservation: {
boolean_value_conversion: true, // convertit en yes ou no convert_to_boolean_value: true, // convertit en yes ou no
}, },
observations: 'note', // observations: 'note',
nom_station: 'name', nom_station: 'name',
nom_enseigne: 'network', nom_enseigne: 'network',
@ -46,15 +47,30 @@ const MappingIRVE: MappingConfigType = {
cable_t2_attache: cable_t2_attache:
{ {
key_converted: 'socket:type2_cable', key_converted: 'socket:type2_cable',
// cable_t2_attache // socket:type2_cable vaut 1 dans OSM si vrai
truthy_value: '1', truthy_value: '1',
} }
, ,
prise_type_ef: 'socket:typee', prise_type_ef: {
prise_type_2: 'socket:type2', key_converted: 'socket:typee',
prise_type_combo_ccs: 'socket:type2_combo', ignore_if_falsy: true,
prise_type_chademo: 'socket:chademo', convert_to_boolean_value: true,
},
prise_type_2: {
key_converted: 'socket:type2',
ignore_if_falsy: true,
convert_to_boolean_value: true,
},
prise_type_combo_ccs: {
key_converted: 'socket:type2_combo',
ignore_if_falsy: true,
convert_to_boolean_value: true,
},
prise_type_chademo: {
key_converted: 'socket:chademo',
ignore_if_falsy: true,
convert_to_boolean_value: true,
},
// ******** champs plus complexes // ******** champs plus complexes
horaires: 'opening_hours', // déjà au bon format horaires: 'opening_hours', // déjà au bon format
@ -116,15 +132,20 @@ const MappingIRVE: MappingConfigType = {
} }
// "station_deux_roues": "yes", // "cable_t2_attache": "True"
// "amenity": "charging_station", // "goal": "jeu de données pour tester la mapping engine",
// "capacity": 12, // "prise_type_2": "yes",
// "reservation": "False", // "station_deux_roues": "yes",
// "nom_amenageur": "Bob Lenon", // "accessibilite_pmr": "Non accessible",
// "siren_amenageur": "12345678", // "amenity": "charging_station",
// "socket:typee": "False", // "capacity": 12,
// "socket:type2": "true", // "reservation": "False",
// "cable_t2_attache": "no", // "nom_amenageur": "Bob Lenon",
// "siren_amenageur": "12345678",
// "socket:typee": "False",
// "prise_type_combo_ccs": "no",
// "fee": "no",
// "authentication:none": "yes"
export default MappingIRVE; export default MappingIRVE;

View File

@ -135,161 +135,185 @@ export default class {
debugLog(' ------ convertProperty: pointKeyName', pointKeyName) debugLog(' ------ convertProperty: pointKeyName', pointKeyName)
// debugLog('convertProperty: mappingKeys', mappingKeys) // debugLog('convertProperty: mappingKeys', mappingKeys)
/**
* only use existing keys
*/
if (mappingKeys.indexOf(pointKeyName) > 0) {
let valueConvertedFromMapping = featurePoint.properties[pointKeyName]
let keyConvertedFromMapping = mappingKeys[mappingKeys.indexOf(pointKeyName)]
let mappingConfigOfTag = this.mapping_config.tags[pointKeyName]
debugLog('========== mappingConfigOfTag', mappingConfigOfTag) if (this.mapping_config.add_not_mapped_tags_too && (mappingKeys.indexOf(pointKeyName) === -1)) {
debugLog('convertProperty: found element', pointKeyName, '=>', keyConvertedFromMapping, 'value : ', valueConvertedFromMapping) /**
let convertedValue = '' * add all unmapped tags is enabled
*/
newProperties[pointKeyName] = originalValue;
let typeOfConfigForKey = typeof mappingConfigOfTag } else {
let isStringValue = typeOfConfigForKey === 'string' /**
let isConfigMappingObject = typeOfConfigForKey === 'object' * only use existing keys
*/
if (mappingKeys.indexOf(pointKeyName) > 0) {
let valueConvertedFromMapping = featurePoint.properties[pointKeyName]
let keyConvertedFromMapping = mappingKeys[mappingKeys.indexOf(pointKeyName)]
let mappingConfigOfTag = this.mapping_config.tags[pointKeyName]
debugLog('convertProperty: - typeofValue', typeOfConfigForKey) debugLog('========== mappingConfigOfTag', mappingConfigOfTag)
debugLog('convertProperty: - pointKeyName', pointKeyName) debugLog('convertProperty: found element', pointKeyName, '=>', keyConvertedFromMapping, 'value : ', valueConvertedFromMapping)
debugLog('convertProperty: - valueConvertedFromMapping', valueConvertedFromMapping) let convertedValue = originalValue
debugLog('typeof valueConvertedFromMapping === \'string\'', typeOfConfigForKey)
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\'', typeOfConfigForKey)
debugLog('convertProperty: isStringValue?', valueConvertedFromMapping, isStringValue) debugLog('convertProperty: isStringValue?', valueConvertedFromMapping, isStringValue)
debugLog('convertProperty: isStringValue?', valueConvertedFromMapping, isStringValue) debugLog('convertProperty: isStringValue?', valueConvertedFromMapping, isStringValue)
debugLog('mappingConfigOfTag', mappingConfigOfTag) debugLog('mappingConfigOfTag', mappingConfigOfTag)
debugLog('typeOfConfigForKey', typeOfConfigForKey) debugLog('typeOfConfigForKey', typeOfConfigForKey)
if (isStringValue) { /**
debugLog('convertProperty: -- string value') * conversion si la clé à une config d'une string, on ne change que la clé, pas la valeur
debugLog('convertProperty: -- string value') */
if (this.isBooleanKey(pointKeyName)) { if (isStringValue) {
let lowerValue = (valueConvertedFromMapping + '').toLowerCase() debugLog('convertProperty: -- string value')
debugLog('convertProperty: isBooleanKey: lowerValue', lowerValue) debugLog('convertProperty: -- string value')
convertedValue = this.truthyValues.indexOf(lowerValue) ? 'yes' : 'no' console.log('convertProperty: -- simple conversion : ', pointKeyName, '=> ', mappingConfigOfTag, '_', originalValue, '=>', valueConvertedFromMapping)
debugLog('convertProperty: -- convertedValue', convertedValue)
} else {
debugLog('convertProperty: -- simple conversion : ', pointKeyName, '_', originalValue, '=>', valueConvertedFromMapping)
convertedValue = valueConvertedFromMapping convertedValue = valueConvertedFromMapping
}
debugLog('convertProperty: -- convertedValue', convertedValue)
if (convertedValue) {
newProperties[keyConvertedFromMapping] = convertedValue
}
} else {
debugLog('convertProperty: no string value')
}
if (isConfigMappingObject) { if (convertedValue) {
let configObject = mappingConfigOfTag newProperties[mappingConfigOfTag] = convertedValue
debugLog('convertProperty: is config object', configObject)
let newKey: any = '' + pointKeyName
let remove_original_key = false;
if (configObject.key_converted) {
newKey = configObject.key_converted
}
// else {
// newKey = pointKeyName
// }
/**
* conversion booléenne
*/
if (mappingValueObject.boolean_value_conversion) {
debugLog('convertProperty: is boolean_value_conversion')
debugLog('convertProperty: ==========> original value', originalValue)
if (this.truthyValues.indexOf(originalValue) !== -1) {
convertedValue = 'yes'
}
if (this.falsyValues.indexOf(originalValue) !== -1) {
convertedValue = 'no'
} }
} else { } else {
debugLog('convertProperty: is NOT having boolean_value_conversion', mappingValueObject) debugLog('convertProperty: no string value')
} }
/** if (isConfigMappingObject) {
* gestion des valeurs conditionnelles let configObject = mappingConfigOfTag
* nous pouvons renseigner une string ou un objet décrivant les transformations à réaliser
*/
if (configObject.conditional_values) {
debugLog('convertProperty: conditional_values__________',
configObject.conditional_values)
let keysConditionnalValues: any = Object.keys(configObject.conditional_values) debugLog('convertProperty: is config object', configObject)
let newKey: any = '' + pointKeyName
let remove_original_key = false;
let isFoundValue = keysConditionnalValues.indexOf(originalValue) if (configObject.key_converted) {
debugLog('isFoundValue', isFoundValue) newKey = configObject.key_converted
debugLog('keysConditionnalValues', keysConditionnalValues)
/** ---------------------- }
* gestion des valeurs conditionnelles
* ---------------------- */
if (isFoundValue !== -1) {
let conditionnalConfig: any = configObject.conditional_values[keysConditionnalValues[isFoundValue]]
if (conditionnalConfig.tags_to_add) { if (configObject.truthy_value) {
// on peut définir un ensemble de tags à rajouter // convertir la valeur, si elle est truthy, la transformer en ce que donne la propriété truthy_value
let tagKeys = Object.keys(conditionnalConfig.tags_to_add) // exemple: le jeu de données dit que la colonne cable_t2_attache vaut "True", mais on veut le convertir en "1".
debugLog('conditionnalConfig.tags_to_add', conditionnalConfig.tags_to_add) // on met donc truthy_value: '1'
conditionnalConfig.tags_to_add.forEach((object: any, pair: any) => {
debugLog('object', object)
debugLog('pair', pair)
let key: any = Object.keys(object)
key = key[0]
let value = object[key]
debugLog('key', key) console.log('truthy_value', originalValue)
debugLog('value', value) if (this.truthyValues.indexOf(originalValue) !== -1) {
newProperties[key] = value convertedValue = configObject.truthy_value
})
} }
if (conditionnalConfig.truthy_value) { }
// convertir la valeur, si elle est truthy, la transformer en ce que donne la propriété truthy_value if (configObject.falsy_value) {
// exemple: le jeu de données dit que la colonne cable_t2_attache vaut "True", mais on veut le convertir en "1". if (this.falsyValues.indexOf(originalValue) !== -1) {
// on met donc truthy_value: '1' convertedValue = configObject.falsy_value
if (this.truthyValues.indexOf(valueConvertedFromMapping) !== -1) {
convertedValue = conditionnalConfig.truthy_value
}
}
if (conditionnalConfig.falsy_value) {
if (this.falsyValues.indexOf(valueConvertedFromMapping) !== -1) {
convertedValue = conditionnalConfig.falsy_value
}
} }
}
if (conditionnalConfig.transform_function) { /**
// une transformation de la valeur * conversion booléenne
// apply transformation to value */
convertedValue = conditionnalConfig.transform_function(valueConvertedFromMapping) if (mappingValueObject.convert_to_boolean_value) {
debugLog('convertProperty: is boolean_value_conversion')
debugLog('convertProperty: ==========> original value', originalValue)
if (this.truthyValues.indexOf(originalValue) !== -1) {
convertedValue = 'yes'
} }
// use the value converted if (this.falsyValues.indexOf(originalValue) !== -1) {
else if (conditionnalConfig.value_converted) { convertedValue = 'no'
convertedValue = conditionnalConfig.value_converted
} }
} else {
debugLog('convertProperty: is NOT having boolean_value_conversion', mappingValueObject)
} }
if (configObject.remove_original_key) { if (configObject.remove_original_key) {
remove_original_key = true remove_original_key = true
} }
} if (configObject.ignore_if_falsy && this.falsyValues.indexOf(originalValue) !== -1) {
remove_original_key = true
}
/**
* config pour une clé
* nous pouvons renseigner une string ou un objet décrivant les transformations à réaliser
*/
if (!remove_original_key && configObject.conditional_values) {
debugLog('convertProperty: conditional_values__________',
configObject.conditional_values)
debugLog('convertProperty: convertedValue ==========> {', newKey, ':', convertedValue, '}') let keysConditionnalValues: any = Object.keys(configObject.conditional_values)
debugLog(' =============== remove_original_key', remove_original_key)
if (!remove_original_key && newKey && !configObject.ignore_this_data) {
debugLog('convertProperty: added') let isFoundValue = keysConditionnalValues.indexOf(originalValue)
newProperties[newKey] = convertedValue debugLog('isFoundValue', isFoundValue)
debugLog('keysConditionnalValues', keysConditionnalValues)
if (isFoundValue !== -1) {
let conditionnalConfig: any = configObject.conditional_values[keysConditionnalValues[isFoundValue]]
/** ----------------------
* gestion des valeurs conditionnelles
* ---------------------- */
if (conditionnalConfig.tags_to_add) {
// on peut définir un ensemble de tags à rajouter
let tagKeys = Object.keys(conditionnalConfig.tags_to_add)
debugLog('conditionnalConfig.tags_to_add', conditionnalConfig.tags_to_add)
conditionnalConfig.tags_to_add.forEach((object: any, pair: any) => {
debugLog('object', object)
debugLog('pair', pair)
let key: any = Object.keys(object)
key = key[0]
let value = object[key]
debugLog('key', key)
debugLog('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
// 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'
if (this.truthyValues.indexOf(originalValue) !== -1) {
convertedValue = conditionnalConfig.truthy_value
}
}
if (conditionnalConfig.falsy_value) {
if (this.falsyValues.indexOf(originalValue) !== -1) {
convertedValue = conditionnalConfig.falsy_value
}
}
if (conditionnalConfig.transform_function) {
// une transformation de la valeur
// apply transformation to value
convertedValue = conditionnalConfig.transform_function(originalValue)
}
// use the value converted
else if (conditionnalConfig.value_converted) {
convertedValue = conditionnalConfig.value_converted
}
}
}
debugLog('convertProperty: convertedValue ==========> {', newKey, ':', convertedValue, '}')
debugLog(' =============== remove_original_key', remove_original_key)
if (!remove_original_key && newKey && convertedValue && !configObject.ignore_this_data) {
debugLog('convertProperty: added')
newProperties[newKey] = convertedValue
}
} }
} }
} }
} }
} }

View File

@ -27,6 +27,7 @@ export interface BoundingBoxCoordinatesType{
export default interface MappingConfigType{ export default interface MappingConfigType{
config_name: string, config_name: string,
config_author: string, config_author: string,
add_not_mapped_tags_too: boolean,
default_properties_of_point: object, default_properties_of_point: object,
tags: FeaturePropertyMappingConfigType tags: FeaturePropertyMappingConfigType
} }
@ -38,7 +39,7 @@ export default interface MappingConfigType{
*/ */
export interface FeaturePropertyMappingConfigType{ export interface FeaturePropertyMappingConfigType{
[key:string]: any, [key:string]: any,
boolean_value_conversion?:boolean, convert_to_boolean_value?:boolean,
remove_original_key?:boolean, remove_original_key?:boolean,
conditionnal_values?:ConditionnalValuesType, conditionnal_values?:ConditionnalValuesType,
transform_function?:Function, transform_function?:Function,

View File

@ -6,14 +6,25 @@
"geometry": { "geometry": {
"type": "Point", "type": "Point",
"coordinates": [ "coordinates": [
2.198339, 4.822159,
48.678843 45.635079
] ]
}, },
"properties": { "properties": {
"bicycle": "yes", "operator": "ELECTRA",
"scooter": "yes", "owner:ref:FR:SIREN": "891624884",
"motorcar": "no" "email": "help@electra.com",
"network": "ELECTRA",
"ref:EU:EVSE": "FRELCPSDRPG",
"name": "Sérézin-du-Rhône - Peugeot",
"socket:type2_combo": "yes",
"fee": "false",
"authentication:none": "true",
"reservation": "yes",
"opening_hours": "24/7",
"wheelchair": "Accessibilité inconnue",
"start_date": "2022-10-27",
"source:date": "2023-07-29"
} }
} }
] ]

View File

@ -6,13 +6,61 @@
"geometry": { "geometry": {
"type": "Point", "type": "Point",
"coordinates": [ "coordinates": [
2.198339, 4.822159,
48.678843 45.635079
] ]
}, },
"properties": { "properties": {
"goal": "jeu de données pour tester la mapping engine", "nom_amenageur": "ELECTRA",
"station_deux_roues": "yes" "siren_amenageur": "891624884",
"contact_amenageur": "help@electra.com",
"nom_operateur": "ELECTRA",
"contact_operateur": "help@electra.com",
"telephone_operateur": "",
"nom_enseigne": "ELECTRA",
"id_station_itinerance": "FRELCPSDRPG",
"id_station_local": "",
"nom_station": "S\u00e9r\u00e9zin-du-Rh\u00f4ne - Peugeot",
"implantation_station": "Station d\u00e9di\u00e9e \u00e0 la recharge rapide",
"adresse_station": "12 chemin d\u00e9partemental 12, Peugeot 69360 S\u00e9r\u00e9zin-du-Rh\u00f4ne",
"code_insee_commune": "69294",
"coordonneesXY": "[4.82215900,45.63507900]",
"nbre_pdc": "8",
"id_pdc_itinerance": "FRELCECURS",
"id_pdc_local": "",
"puissance_nominale": "225",
"prise_type_ef": "false",
"prise_type_2": "false",
"prise_type_combo_ccs": "true",
"prise_type_chademo": "false",
"prise_type_autre": "false",
"gratuit": "false",
"paiement_acte": "true",
"paiement_cb": "true",
"paiement_autre": "true",
"tarification": "",
"condition_acces": "Acc\u00e8s libre",
"reservation": "true",
"horaires": "24/7",
"accessibilite_pmr": "Accessibilit\u00e9 inconnue",
"restriction_gabarit": "Inconnu",
"station_deux_roues": "false",
"raccordement": "Direct",
"num_pdl": "N/A",
"date_mise_en_service": "2022-10-27",
"observations": "T\u00e9l\u00e9charger l'application ELECTRA pour r\u00e9server et payer sur go-electra.com",
"date_maj": "2023-07-29",
"cable_t2_attache": "",
"last_modified": "2023-07-29T03:05:24.360000+00:00",
"datagouv_dataset_id": "623ca46c13130c3228abd018",
"datagouv_resource_id": "e9bb3424-77cd-40ba-8bbd-5a19362d0365",
"datagouv_organization_or_owner": "electra",
"consolidated_longitude": 4.822159,
"consolidated_latitude": 45.635079,
"consolidated_code_postal": "69360",
"consolidated_commune": "S\u00e9r\u00e9zin-du-Rh\u00f4ne",
"consolidated_is_lon_lat_correct": true,
"consolidated_is_code_insee_verified": true
} }
} }
] ]