From e9ec74601bc12d3e000c02b7a6b6665d68f9a006 Mon Sep 17 00:00:00 2001 From: Tykayn Date: Sat, 5 Aug 2023 14:24:19 +0200 Subject: [PATCH] hop --- .../convert_to_osm_tags.ts | 16 ++++----- .../mappings/converters/configIRVE.ts | 25 ++++++-------- .../mappings/engine.ts | 34 ++++++++++++++----- mapping_geojson_to_osm_tags/mappings/utils.ts | 2 +- .../output/my_converted_data_set.json | 5 ++- ...ed_data_set_filtered_zipcode_91_small.json | 8 ++++- 6 files changed, 56 insertions(+), 34 deletions(-) diff --git a/mapping_geojson_to_osm_tags/convert_to_osm_tags.ts b/mapping_geojson_to_osm_tags/convert_to_osm_tags.ts index df18e197..eca4e690 100644 --- a/mapping_geojson_to_osm_tags/convert_to_osm_tags.ts +++ b/mapping_geojson_to_osm_tags/convert_to_osm_tags.ts @@ -195,15 +195,13 @@ function convertDataForIRVE(sourceFilePath: string, mapping: any, pointCounterMa feature_points_after_filter.forEach((feature_point: any) => { // debugLog('featurePoint.properties.consolidated_code_postal', feature_point.properties.consolidated_code_postal) debugLog('convert : work on 1 point') - debugLog('convert :featurePoint', feature_point) - - console.log('convert :feature_point', feature_point) + // debugLog('convert :featurePoint', feature_point) let mapped_point: any = {} if (use_mapping_engine) { - debugLog('convert :using mapping engine on feature point' - , feature_point - ) + // debugLog('convert :using mapping engine on feature point' + // , feature_point + // ) mapped_point = Mapping_engine.mapElementFromConf(feature_point) console.log('mapped_point', mapped_point) } else { @@ -225,13 +223,13 @@ function convertDataForIRVE(sourceFilePath: string, mapping: any, pointCounterMa if (converted_geo_json.features.length) { let fileNameToWrite = 'my_converted_data_set' + filteredName + '.json' - debugLog('write file ', fileNameToWrite) + debugLog('convert : write file ', fileNameToWrite) writeFile(fileNameToWrite, JSON.stringify(converted_geo_json, null, 2)) } else { - debugLog('no writing of file, because there is no converted feature') + debugLog('convert : no writing of file, because there is no converted feature') } - debugLog('mapped output:', converted_geo_json.features) + console.log('convert : converted_geo_json output:', converted_geo_json.features) return converted_geo_json } diff --git a/mapping_geojson_to_osm_tags/mappings/converters/configIRVE.ts b/mapping_geojson_to_osm_tags/mappings/converters/configIRVE.ts index 869dc0f3..4c383588 100644 --- a/mapping_geojson_to_osm_tags/mappings/converters/configIRVE.ts +++ b/mapping_geojson_to_osm_tags/mappings/converters/configIRVE.ts @@ -31,10 +31,7 @@ const MappingIRVE: MappingConfigType = { paiement_acte: 'authentication:none', reservation: { - key_converted: 'reservation', - truthy_value: 'yes', - falsy_value: 'no', - // boolean_value_conversion: true, // convertit en yes ou no + boolean_value_conversion: true, // convertit en yes ou no }, observations: 'note', nom_station: 'name', @@ -88,17 +85,17 @@ const MappingIRVE: MappingConfigType = { // value_converted: "" // } -// choix: + // choix: -// Sa:09:00-19:00 -// 24/7 -// Mo-Fr 08:00-12:00,Mo-Fr 14:00-19:00,Sat 09:00-18:00 -// Mo-Fr 08:00-19:00,Sat 09:00-18:00 -// Sa:08:00-19:00 -// 24/7 -// Mo-Fr 08:30-12:00,Mo-Fr 14:00-19:00,Sat 09:00-18:30 -// Mo-Fr 09:00-16:00 -// Mo-Fr 08:00-12:00,Mo-Fr 14:00-18:00,Th 08:00-18:00 + // Sa:09:00-19:00 + // 24/7 + // Mo-Fr 08:00-12:00,Mo-Fr 14:00-19:00,Sat 09:00-18:00 + // Mo-Fr 08:00-19:00,Sat 09:00-18:00 + // Sa:08:00-19:00 + // 24/7 + // Mo-Fr 08:30-12:00,Mo-Fr 14:00-19:00,Sat 09:00-18:30 + // Mo-Fr 09:00-16:00 + // Mo-Fr 08:00-12:00,Mo-Fr 14:00-18:00,Th 08:00-18:00 } }, diff --git a/mapping_geojson_to_osm_tags/mappings/engine.ts b/mapping_geojson_to_osm_tags/mappings/engine.ts index f7c589d1..796acb96 100644 --- a/mapping_geojson_to_osm_tags/mappings/engine.ts +++ b/mapping_geojson_to_osm_tags/mappings/engine.ts @@ -83,7 +83,7 @@ export default class { * retuns the converted element from mapping config if present, null otherwise */ mapElementFromConf(featurePoint: any): any { - debugLog('mapElementFromConf: mapElementFromConf', featurePoint) + // 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.') } @@ -113,7 +113,7 @@ export default class { basePoint.properties = newProperties - debugLog('mapElementFromConf: basePoint', basePoint) + // debugLog('mapElementFromConf: basePoint', basePoint) return basePoint } @@ -126,9 +126,18 @@ export default class { */ convertProperty(pointKeyName: string, mappingKeys: any, featurePoint: any, newProperties: any) { let originalValue = featurePoint.properties[pointKeyName] + let mappingValueObject: any = ''; - debugLog('convertProperty: pointKeyName', pointKeyName) + if (mappingKeys.indexOf(pointKeyName) > 0) { + mappingValueObject = this.mapping_config.tags[pointKeyName] + debugLog('convertProperty: mappingValueObject ', mappingValueObject) + } + + debugLog(' ------ convertProperty: pointKeyName', pointKeyName) // debugLog('convertProperty: mappingKeys', mappingKeys) + /** + * only use existing keys + */ if (mappingKeys.indexOf(pointKeyName) > 0) { let valueConvertedFromMapping = featurePoint.properties[pointKeyName] let keyConvertedFromMapping = mappingKeys[mappingKeys.indexOf(pointKeyName)] @@ -147,6 +156,7 @@ export default class { debugLog('convertProperty: isStringValue?', isStringValue) if (isStringValue) { + console.log('convertProperty: -- string value') debugLog('convertProperty: -- string value') if (this.isBooleanKey(pointKeyName)) { let lowerValue = (valueConvertedFromMapping + '').toLowerCase() @@ -164,27 +174,32 @@ export default class { debugLog('convertProperty: no string value') } - // TODO handle config object for complex mapping if (isConfigMappingObject) { - debugLog('convertProperty: is config object') - let newKey = '' let configObject = valueConvertedFromMapping + debugLog('convertProperty: is config object', configObject) + let newKey = '' + pointKeyName + if (configObject.key_converted) { newKey = configObject.key_converted + } else { + newKey = pointKeyName } /** * conversion booléenne */ - if (configObject.boolean_value_conversion) { - debugLog('convertProperty: is boolean_value_conversion' ) + 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 { + debugLog('convertProperty: is NOT having boolean_value_conversion', mappingValueObject) } /** @@ -227,7 +242,10 @@ export default class { } } + debugLog('convertProperty: convertedValue ==========> {', newKey, ':', convertedValue, '}') if (newKey && !configObject.ignore_this_data) { + + debugLog('convertProperty: added') newProperties[newKey] = convertedValue } } diff --git a/mapping_geojson_to_osm_tags/mappings/utils.ts b/mapping_geojson_to_osm_tags/mappings/utils.ts index 42752810..145dac23 100644 --- a/mapping_geojson_to_osm_tags/mappings/utils.ts +++ b/mapping_geojson_to_osm_tags/mappings/utils.ts @@ -1,7 +1,7 @@ import fs from 'fs' let show_debug = 0 -show_debug = 1 +// show_debug = 1 let output_folder = 'output'; console.log('----------------------show_debug', show_debug) diff --git a/mapping_geojson_to_osm_tags/output/my_converted_data_set.json b/mapping_geojson_to_osm_tags/output/my_converted_data_set.json index 8aeeb57b..b827d87e 100644 --- a/mapping_geojson_to_osm_tags/output/my_converted_data_set.json +++ b/mapping_geojson_to_osm_tags/output/my_converted_data_set.json @@ -11,7 +11,10 @@ ] }, "properties": { - "reservation": "TRUE" + "amenity": "charging_station", + "reservation": "no", + "nom_amenageur": "Bob Lenon", + "siren_amenageur": "12345678" } } ] diff --git a/mapping_geojson_to_osm_tags/output/my_converted_data_set_filtered_zipcode_91_small.json b/mapping_geojson_to_osm_tags/output/my_converted_data_set_filtered_zipcode_91_small.json index 8aeeb57b..47824f73 100644 --- a/mapping_geojson_to_osm_tags/output/my_converted_data_set_filtered_zipcode_91_small.json +++ b/mapping_geojson_to_osm_tags/output/my_converted_data_set_filtered_zipcode_91_small.json @@ -11,7 +11,13 @@ ] }, "properties": { - "reservation": "TRUE" + "amenity": "charging_station", + "capacity": 12, + "reservation": "False", + "nom_amenageur": "Bob Lenon", + "siren_amenageur": "12345678", + "socket:typee": "no", + "socket:type2": "yes" } } ]