handle jardinage of phones

This commit is contained in:
tykayn 2023-08-30 15:55:45 +02:00
parent ee10a3a7aa
commit 8d3be5817d
10 changed files with 839311 additions and 7013 deletions

View File

@ -24,7 +24,7 @@ let mini_arguments: any = minimist(process.argv.slice(2))
// let sourceFilePathGeoJson = './etalab_data/small.json' // let sourceFilePathGeoJson = './etalab_data/small.json'
let sourceFilePathGeoJson = './etalab_data/all.json' let sourceFilePathGeoJson = './data_other/irve_osm_2023-08-30.json'
// let sourceFilePathGeoJson = './output/my_converted_data_set_filtered_zipcode_91.json' // let sourceFilePathGeoJson = './output/my_converted_data_set_filtered_zipcode_91.json'
// let sourceFilePathGeoJson = './output/my_converted_data_set_filtered_zipcode_91_small.json' // let sourceFilePathGeoJson = './output/my_converted_data_set_filtered_zipcode_91_small.json'
@ -100,11 +100,12 @@ let output_folder = 'output';
* @param fileContent * @param fileContent
*/ */
function writeFile(fileName: string, fileContent: any) { function writeFile(fileName: string, fileContent: any) {
debugLog('write file ', fileName) let write_path = `./${output_folder}/${fileName}`
debugLog('write file ', fileName , write_path)
return fs.writeFile( return fs.writeFile(
`./${output_folder}/${fileName}`, write_path,
fileContent, fileContent,
'utf8', 'utf8',
(err) => { (err) => {
@ -234,12 +235,13 @@ function convertDataForIRVE(sourceFilePath: string, mapping: any, pointCounterMa
let fileNameToWrite = 'my_converted_data_set' + filteredName + '.json' let fileNameToWrite = 'my_converted_data_set' + filteredName + '.json'
console.log('features: ', converted_geo_json.features.length) console.log('features: ', converted_geo_json.features.length)
debugLog('convert : write file ', fileNameToWrite) debugLog('convert : write file ', fileNameToWrite)
console.log('mapping_engine.stats', Mapping_engine.stats)
writeFile(fileNameToWrite, JSON.stringify(converted_geo_json, null, 2)) writeFile(fileNameToWrite, JSON.stringify(converted_geo_json, null, 2))
} else { } else {
console.log('convert : no writing of file, because there is no converted feature') console.log('convert : no writing of file, because there is no converted feature')
} }
// console.log('convert : converted_geo_json output:', converted_geo_json.features)
return converted_geo_json return converted_geo_json
} }
@ -295,7 +297,7 @@ if (use_mapping_engine) {
debugLog(' - using mapping engine') debugLog(' - using mapping engine')
debugLog(' - pointCounterMax', pointCounterMax) debugLog(' - pointCounterMax', pointCounterMax)
// Mapping_engine.setConfig(mappingConfigIRVE) Mapping_engine.setConfig(mappingConfigIRVE)
let currentMappingConfig = Mapping_engine.getConfig(); let currentMappingConfig = Mapping_engine.getConfig();
convertDataForIRVE(sourceFilePathGeoJson, currentMappingConfig, pointCounterMax, boundingBoxCoordinates) convertDataForIRVE(sourceFilePathGeoJson, currentMappingConfig, pointCounterMax, boundingBoxCoordinates)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -43,6 +43,10 @@ const MappingIRVE: MappingConfigType = {
key_converted: 'phone', key_converted: 'phone',
convert_to_phone: true, // conversion en format international si possible convert_to_phone: true, // conversion en format international si possible
}, },
phone: {
key_converted: 'phone',
convert_to_phone: true, // conversion en format international si possible
},
contact_operateur: 'email', // ici, on souhaite convertir la clé contact_operateur=bidule en email=bidule contact_operateur: 'email', // ici, on souhaite convertir la clé contact_operateur=bidule en email=bidule
// id_station_itinerance: 'ref:EU:EVSE', // id_station_itinerance: 'ref:EU:EVSE',

View File

@ -16,10 +16,17 @@ let listOfBooleanKeys = [
export default class { export default class {
mapping_config: any = {} mapping_config: any = {}
private jardinage = true;
public stats: any;
constructor(mappingConfig: MappingConfigType) { constructor(mappingConfig: MappingConfigType) {
this.setConfig(mappingConfig) this.setConfig(mappingConfig)
this.stats = {
phones_updated: 0,
phones_updated_list: [],
phones_not_updated: 0
}
} }
setConfig(mappingConfig: MappingConfigType) { setConfig(mappingConfig: MappingConfigType) {
@ -34,10 +41,13 @@ export default class {
mapFeaturePoint(featurePointGeoJson: any) { mapFeaturePoint(featurePointGeoJson: any) {
let geoJSONConvertedPoint: any = {} let geoJSONConvertedPoint: any = {}
geoJSONConvertedPoint.properties = {...this.mapping_config.default_properties_of_point} geoJSONConvertedPoint.properties = {...this.mapping_config.default_properties_of_point}
geoJSONConvertedPoint.type = featurePointGeoJson.type geoJSONConvertedPoint.type = featurePointGeoJson.type
geoJSONConvertedPoint.geometry = featurePointGeoJson.geometry geoJSONConvertedPoint.geometry = featurePointGeoJson.geometry
// let props = featurePointGeoJson.properties // let props = featurePointGeoJson.properties
// props.forEach((key, value) => { // props.forEach((key, value) => {
@ -144,6 +154,13 @@ export default class {
debugLog(' ------ convertProperty: pointKeyName', pointKeyName) debugLog(' ------ convertProperty: pointKeyName', pointKeyName)
// debugLog('convertProperty: mappingKeys', mappingKeys) // debugLog('convertProperty: mappingKeys', mappingKeys)
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)) { if (this.mapping_config.add_not_mapped_tags_too && (mappingKeys.indexOf(pointKeyName) === -1)) {
/** /**
* add all unmapped tags is enabled * add all unmapped tags is enabled
@ -247,35 +264,39 @@ export default class {
debugLog('convertProperty: is NOT having boolean_value_conversion', mappingValueObject) debugLog('convertProperty: is NOT having boolean_value_conversion', mappingValueObject)
} }
if (configObject.convert_to_phone) { if (configObject.convert_to_phone) {
/**
* nettoyer les numéros de téléphone en ne gardant que les nombres et le préfixe de pays
*/
debugLog('originalValue', originalValue.substring(1)) debugLog('originalValue', originalValue.substring(1))
let original_without_spaces = originalValue.replace(' ','') let original_without_spaces = originalValue.replace(/ /g, '')
let cleaned_value = `${original_without_spaces}` let cleaned_value = `${original_without_spaces}`
cleaned_value = cleaned_value cleaned_value = cleaned_value
.trim() .trim()
.replace('Stations-e', '') .replace('Stations-e', '')
.replace('(numéro unique)', '') .replace(/[a-zA-Zéèà]/ig, '')
.replace(/[\(\)\.\- ]/g, '') .replace(/[\(\)\.\- ]/g, '')
let original_array = originalValue.split('') let original_array = originalValue.split('')
let add_prefix = false; let add_prefix = false;
if ( if (
/^\d/.test(cleaned_value) && /^\d/.test(cleaned_value) &&
! /^\+33 /.test(originalValue) !/^\+33 /.test(original_without_spaces)
){ ) {
add_prefix = true add_prefix = true
} }
cleaned_value = cleaned_value.replace('+33', '') cleaned_value = cleaned_value.replace('+33', '')
if (/^0/.test(cleaned_value) ){ if (/^0/.test(cleaned_value)) {
cleaned_value= cleaned_value.substring(1) cleaned_value = cleaned_value.substring(1)
} }
let array_of_numbers = cleaned_value let array_of_numbers = cleaned_value
.split('') .split('')
let ii = 0; let ii = 0;
if(cleaned_value.length == 4){ if (cleaned_value.length == 4) {
ii=1 ii = 1
} }
convertedValue = '' convertedValue = ''
array_of_numbers.forEach((num: string) => { array_of_numbers.forEach((num: string) => {
@ -292,14 +313,24 @@ export default class {
console.log('convertedValue', convertedValue) console.log('convertedValue', convertedValue)
if ( if (
/^\d/.test(convertedValue) && /^\d/.test(convertedValue) &&
! /^\+33 /.test(convertedValue) !/^\+33 /.test(convertedValue)
){ ) {
add_prefix = true add_prefix = true
} }
if (add_prefix) { if (add_prefix) {
convertedValue = `+33 ` + convertedValue convertedValue = `+33 ` + convertedValue
} }
debugLog('phone: ', originalValue, '=>', convertedValue)
if (originalValue !== convertedValue) {
this.stats.phones_updated++
this.stats.phones_updated_list.push(convertedValue)
} else {
this.stats.phones_not_updated++
}
} }
if (configObject.remove_original_key) { if (configObject.remove_original_key) {
remove_original_key = true remove_original_key = true
@ -393,6 +424,7 @@ export default class {
} }
} }
return newProperties; return newProperties;
} }

View File

@ -1,7 +1,7 @@
import fs from 'fs' import fs from 'fs'
let show_debug = 0 let show_debug = 0
// show_debug = 1 show_debug = 1
let output_folder = 'output'; let output_folder = 'output';
// console.log('----------------------show_debug', show_debug) // console.log('----------------------show_debug', show_debug)

773860
output/build_log.log Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -122,10 +122,19 @@ describe('mapping properties with rich mapping engine', () => {
expect(mapped_point.properties).toStrictEqual({ phone: expected_converted_phone }) expect(mapped_point.properties).toStrictEqual({ phone: expected_converted_phone })
feature_to_test.properties.telephone_operateur = 'Stations-e' feature_to_test.properties.telephone_operateur = 'Stations-e'
mapped_point = Mapping_engine.mapElementFromConf(feature_to_test) mapped_point = Mapping_engine.mapElementFromConf(feature_to_test)
expect(mapped_point.properties).toStrictEqual({ }) expect(mapped_point.properties).toStrictEqual({ })
feature_to_test.properties.telephone_operateur = '+33 0 7 66 38 74 96'
expected_converted_phone = '+33 7 66 38 74 96'
mapped_point = Mapping_engine.mapElementFromConf(feature_to_test)
expect(mapped_point.properties).toStrictEqual({ phone: expected_converted_phone })
feature_to_test.properties.telephone_operateur = '+ 33 1 30 31 30 46 (numéro unique)'
expected_converted_phone = '+33 1 30 31 30 46'
mapped_point = Mapping_engine.mapElementFromConf(feature_to_test)
expect(mapped_point.properties).toStrictEqual({ phone: expected_converted_phone })
// +19 0142056650;+19 0664534050 // +19 0142056650;+19 0664534050
}) })
}) })