diff --git a/mappings/converters/configPlaquesCommémorativesParis.ts b/mappings/converters/configPlaquesCommémorativesParis.ts index 67018fa..bb96c7f 100644 --- a/mappings/converters/configPlaquesCommémorativesParis.ts +++ b/mappings/converters/configPlaquesCommémorativesParis.ts @@ -25,17 +25,36 @@ const MappingPlaquesCommémorativesParis: MappingConfigType = { add_not_mapped_tags_too: false, boolean_keys: [], tags_to_ignore_if_value_is: ['Non renseigne', 'null'], + // allow_unspecified_conditional_values: false, tags: { "index_plaque": "ref:FR:Paris:plaques", - // "retranscription": "inscription", + "retranscription": "inscription", "materiau": { key_converted: "material", // remove_original_key: true, conditional_values: { + "comblanchien": { + value_converted: "stone", + tags_to_add: [{ "color": "white" }] + }, + "bronze": { + value_converted: "metal", + // tags_to_add: [{ "color": "orange" }] + }, + "Méthacrylate": { + value_converted: "plastic" + }, + + "granit": { + value_converted: "stone" + }, "pierre": { value_converted: "stone" }, + "Pierre": { + value_converted: "stone" + }, "pierre blanche": { value_converted: "stone" }, @@ -48,8 +67,18 @@ const MappingPlaquesCommémorativesParis: MappingConfigType = { "marbre fonc\u00e9": { value_converted: "marbre" }, + + "marbre gris": { + value_converted: "marbre", + tags_to_add: [{ "color": "grey" }] + }, "marbre clair": { - value_converted: "marbre" + value_converted: "marbre", + tags_to_add: [{ "color": "white" }] + }, + "marbre rose": { + value_converted: "marbre", + tags_to_add: [{ "color": "pink" }] }, "cuivre": { value_converted: "copper" @@ -57,6 +86,9 @@ const MappingPlaquesCommémorativesParis: MappingConfigType = { "métal": { value_converted: "metal" }, + "fonte": { + value_converted: "metal" + }, "plexiglas transparent": { value_converted: "glass" }, @@ -72,10 +104,20 @@ const MappingPlaquesCommémorativesParis: MappingConfigType = { "céramique": { value_converted: "ceramic" }, + "résine": { + value_converted: "resin" + }, + "acier": { + value_converted: "steel" + }, + "Marbre": { + value_converted: "marbre" + }, + } }, - // "titre": "name", + "titre": "name", // "personnalite": "subject", // ----------------------------------------- diff --git a/mappings/engine.ts b/mappings/engine.ts index ebb4af7..2b3533b 100644 --- a/mappings/engine.ts +++ b/mappings/engine.ts @@ -423,57 +423,63 @@ export default class MappingEngine { debugLog('truncate_enums_to_limit => ', convertedValue) } - let conditionnalConfig: any = '' + let conditionalConfig: any = '' /** * config pour une clé * nous pouvons renseigner une string ou un objet décrivant les transformations à réaliser */ if (configObject.conditional_values) { - // console.log('configObject.conditional_values', configObject.conditional_values) - // convert numbers from json to string to compare them correctly originalValue = '' + originalValue let keysConditionnalValues: any = Object.keys(configObject.conditional_values) - let isFoundValue = keysConditionnalValues.indexOf(originalValue) - conditionnalConfig = configObject.conditional_values[keysConditionnalValues[isFoundValue]] + 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) { + + // console.log('(x) => ignore', originalValue, ' in ', pointKeyName) + remove_original_key = true + } if (!remove_original_key) { - if (isFoundValue !== -1) { - debugLog('found condition', isFoundValue) + if (foundValue !== -1) { + debugLog('found condition', foundValue) /** ---------------------- * gestion des valeurs conditionnelles * ---------------------- */ - debugLog('conditionnalConfig', conditionnalConfig) + debugLog('conditionnalConfig', conditionalConfig) - if (conditionnalConfig.ignore_this_data) { + if (conditionalConfig.ignore_this_data) { debugLog(`on ignore cette clé car sa valeur "${originalValue}" est à exclure: `, pointKeyName, '=>', newKey) remove_original_key = true; } - if (conditionnalConfig.truthy_value) { + if (conditionalConfig.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 (custom_utils.truthyValues.indexOf(originalValue) !== -1) { - convertedValue = conditionnalConfig.truthy_value + convertedValue = conditionalConfig.truthy_value } } - if (conditionnalConfig.falsy_value) { + if (conditionalConfig.falsy_value) { if (custom_utils.falsyValues.indexOf(originalValue) !== -1) { - convertedValue = conditionnalConfig.falsy_value + convertedValue = conditionalConfig.falsy_value } } // use the value converted - else if (conditionnalConfig.value_converted) { - convertedValue = conditionnalConfig.value_converted + else if (conditionalConfig.value_converted) { + convertedValue = conditionalConfig.value_converted } @@ -482,15 +488,15 @@ export default class MappingEngine { } // console.log('convertedValue =>', convertedValue) - if (conditionnalConfig?.tags_to_add) { - debugLog('on ajoute des tags', conditionnalConfig.tags_to_add) + 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(conditionnalConfig.tags_to_add) - debugLog('conditionnalConfig.tags_to_add', conditionnalConfig.tags_to_add) + 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', conditionnalConfig.tags_to_add[index]) - newProperties[index] = conditionnalConfig.tags_to_add[index] + debugLog('value', conditionalConfig.tags_to_add[index]) + newProperties[index] = conditionalConfig.tags_to_add[index] }) } diff --git a/mappings/mapping-config.type.ts b/mappings/mapping-config.type.ts index d1e81bd..553651e 100644 --- a/mappings/mapping-config.type.ts +++ b/mappings/mapping-config.type.ts @@ -58,6 +58,7 @@ export default interface MappingConfigType { default_properties_of_point?: object, // tag to add to every converted point by default source: sourceConfig, filters?: filteringConfig, + allow_unspecified_conditional_values?: boolean, // by default, we do not add tags from properties that we do not specify in conditional_values, set this to true to change it tags: FeaturePropertyMappingConfigType } @@ -77,7 +78,7 @@ export interface FeaturePropertyMappingConfigType { truncate_enums_to_limit?: number, conditional_values?: ConditionnalValuesConfigType, transform_function?: Function, - keep_only_max_in_enum?:boolean, + keep_only_max_in_enum?: boolean, [key: string]: any, }