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 = {
} }
// "cable_t2_attache": "True"
// "goal": "jeu de données pour tester la mapping engine",
// "prise_type_2": "yes",
// "station_deux_roues": "yes", // "station_deux_roues": "yes",
// "accessibilite_pmr": "Non accessible",
// "amenity": "charging_station", // "amenity": "charging_station",
// "capacity": 12, // "capacity": 12,
// "reservation": "False", // "reservation": "False",
// "nom_amenageur": "Bob Lenon", // "nom_amenageur": "Bob Lenon",
// "siren_amenageur": "12345678", // "siren_amenageur": "12345678",
// "socket:typee": "False", // "socket:typee": "False",
// "socket:type2": "true", // "prise_type_combo_ccs": "no",
// "cable_t2_attache": "no", // "fee": "no",
// "authentication:none": "yes"
export default MappingIRVE; export default MappingIRVE;

View File

@ -135,6 +135,14 @@ export default class {
debugLog(' ------ convertProperty: pointKeyName', pointKeyName) debugLog(' ------ convertProperty: pointKeyName', pointKeyName)
// debugLog('convertProperty: mappingKeys', mappingKeys) // debugLog('convertProperty: mappingKeys', mappingKeys)
if (this.mapping_config.add_not_mapped_tags_too && (mappingKeys.indexOf(pointKeyName) === -1)) {
/**
* add all unmapped tags is enabled
*/
newProperties[pointKeyName] = originalValue;
} else {
/** /**
* only use existing keys * only use existing keys
*/ */
@ -145,7 +153,7 @@ export default class {
debugLog('========== 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 = originalValue
let typeOfConfigForKey = typeof mappingConfigOfTag let typeOfConfigForKey = typeof mappingConfigOfTag
let isStringValue = typeOfConfigForKey === 'string' let isStringValue = typeOfConfigForKey === 'string'
@ -164,21 +172,19 @@ export default class {
debugLog('typeOfConfigForKey', typeOfConfigForKey) debugLog('typeOfConfigForKey', typeOfConfigForKey)
/**
* conversion si la clé à une config d'une string, on ne change que la clé, pas la valeur
*/
if (isStringValue) { if (isStringValue) {
debugLog('convertProperty: -- string value') debugLog('convertProperty: -- string value')
debugLog('convertProperty: -- string value') debugLog('convertProperty: -- string value')
if (this.isBooleanKey(pointKeyName)) { console.log('convertProperty: -- simple conversion : ', pointKeyName, '=> ', mappingConfigOfTag, '_', originalValue, '=>', valueConvertedFromMapping)
let lowerValue = (valueConvertedFromMapping + '').toLowerCase()
debugLog('convertProperty: isBooleanKey: lowerValue', lowerValue)
convertedValue = this.truthyValues.indexOf(lowerValue) ? 'yes' : 'no'
} else {
debugLog('convertProperty: -- simple conversion : ', pointKeyName, '_', originalValue, '=>', valueConvertedFromMapping)
convertedValue = valueConvertedFromMapping
}
debugLog('convertProperty: -- convertedValue', convertedValue) debugLog('convertProperty: -- convertedValue', convertedValue)
convertedValue = valueConvertedFromMapping
if (convertedValue) { if (convertedValue) {
newProperties[keyConvertedFromMapping] = convertedValue newProperties[mappingConfigOfTag] = convertedValue
} }
} else { } else {
debugLog('convertProperty: no string value') debugLog('convertProperty: no string value')
@ -193,15 +199,29 @@ export default class {
if (configObject.key_converted) { if (configObject.key_converted) {
newKey = configObject.key_converted newKey = configObject.key_converted
}
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'
console.log('truthy_value', originalValue)
if (this.truthyValues.indexOf(originalValue) !== -1) {
convertedValue = configObject.truthy_value
}
}
if (configObject.falsy_value) {
if (this.falsyValues.indexOf(originalValue) !== -1) {
convertedValue = configObject.falsy_value
}
} }
// else {
// newKey = pointKeyName
// }
/** /**
* conversion booléenne * conversion booléenne
*/ */
if (mappingValueObject.boolean_value_conversion) { if (mappingValueObject.convert_to_boolean_value) {
debugLog('convertProperty: is boolean_value_conversion') debugLog('convertProperty: is boolean_value_conversion')
debugLog('convertProperty: ==========> original value', originalValue) debugLog('convertProperty: ==========> original value', originalValue)
if (this.truthyValues.indexOf(originalValue) !== -1) { if (this.truthyValues.indexOf(originalValue) !== -1) {
@ -213,12 +233,17 @@ export default class {
} else { } else {
debugLog('convertProperty: is NOT having boolean_value_conversion', mappingValueObject) debugLog('convertProperty: is NOT having boolean_value_conversion', mappingValueObject)
} }
if (configObject.remove_original_key) {
remove_original_key = true
}
if (configObject.ignore_if_falsy && this.falsyValues.indexOf(originalValue) !== -1) {
remove_original_key = true
}
/** /**
* gestion des valeurs conditionnelles * config pour une clé
* 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 (!remove_original_key && configObject.conditional_values) {
debugLog('convertProperty: conditional_values__________', debugLog('convertProperty: conditional_values__________',
configObject.conditional_values) configObject.conditional_values)
@ -228,12 +253,12 @@ export default class {
debugLog('isFoundValue', isFoundValue) debugLog('isFoundValue', isFoundValue)
debugLog('keysConditionnalValues', keysConditionnalValues) debugLog('keysConditionnalValues', keysConditionnalValues)
if (isFoundValue !== -1) {
let conditionnalConfig: any = configObject.conditional_values[keysConditionnalValues[isFoundValue]]
/** ---------------------- /** ----------------------
* gestion des valeurs conditionnelles * gestion des valeurs conditionnelles
* ---------------------- */ * ---------------------- */
if (isFoundValue !== -1) {
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)
@ -254,20 +279,19 @@ export default class {
// 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
// exemple: le jeu de données dit que la colonne cable_t2_attache vaut "True", mais on veut le convertir en "1". // 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' // on met donc truthy_value: '1'
if (this.truthyValues.indexOf(valueConvertedFromMapping) !== -1) { if (this.truthyValues.indexOf(originalValue) !== -1) {
convertedValue = conditionnalConfig.truthy_value convertedValue = conditionnalConfig.truthy_value
} }
} }
if (conditionnalConfig.falsy_value) { if (conditionnalConfig.falsy_value) {
if (this.falsyValues.indexOf(valueConvertedFromMapping) !== -1) { if (this.falsyValues.indexOf(originalValue) !== -1) {
convertedValue = conditionnalConfig.falsy_value convertedValue = conditionnalConfig.falsy_value
} }
} }
if (conditionnalConfig.transform_function) { if (conditionnalConfig.transform_function) {
// une transformation de la valeur // une transformation de la valeur
// apply transformation to value // apply transformation to value
convertedValue = conditionnalConfig.transform_function(valueConvertedFromMapping) convertedValue = conditionnalConfig.transform_function(originalValue)
} }
// use the value converted // use the value converted
else if (conditionnalConfig.value_converted) { else if (conditionnalConfig.value_converted) {
@ -276,14 +300,12 @@ export default class {
} }
if (configObject.remove_original_key) {
remove_original_key = true
}
} }
debugLog('convertProperty: convertedValue ==========> {', newKey, ':', convertedValue, '}') debugLog('convertProperty: convertedValue ==========> {', newKey, ':', convertedValue, '}')
debugLog(' =============== 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 && convertedValue && !configObject.ignore_this_data) {
debugLog('convertProperty: added') debugLog('convertProperty: added')
newProperties[newKey] = convertedValue newProperties[newKey] = convertedValue
@ -292,4 +314,6 @@ export default class {
} }
} }
}
} }

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
} }
} }
] ]