up change percentage message

This commit is contained in:
Tykayn 2024-10-08 12:25:51 +02:00 committed by tykayn
parent 04c3bd8d53
commit 01482e1411
4 changed files with 18952 additions and 20 deletions

View File

@ -150,8 +150,6 @@ function convertDataFromSource(sourceFilePath: string, mapping: MappingConfigTyp
return debugLog(err) return debugLog(err)
} }
let data_transformed: FeatureCollection = JSON.parse(data) let data_transformed: FeatureCollection = JSON.parse(data)
// debug('data keys ', Object.keys(dataTransformed))
// debugLog('properties of point 0', data_transformed.features[0])
if (data_transformed.features) { if (data_transformed.features) {
@ -171,6 +169,7 @@ function convertDataFromSource(sourceFilePath: string, mapping: MappingConfigTyp
debugLog('filter offset enabled', mapping.filters.offset) debugLog('filter offset enabled', mapping.filters.offset)
list_of_points = list_of_points.splice(0,mapping.filters.offset) list_of_points = list_of_points.splice(0,mapping.filters.offset)
} }
console.log('list_of_points.length', list_of_points.length) console.log('list_of_points.length', list_of_points.length)
@ -179,6 +178,10 @@ function convertDataFromSource(sourceFilePath: string, mapping: MappingConfigTyp
* run filters before mapping OSM tags * run filters before mapping OSM tags
* TODO: do it in the engine * TODO: do it in the engine
*/ */
if(mapping.filters && mapping.filters.exclude_point_if_tag_not_empty){
list_of_points = Mapping_engine.filterListOfPointsByExcludingIfKeyFilled(list_of_points, mapping.filters.exclude_point_if_tag_not_empty)
}
// for each point from the data source, filter if we take it or not // for each point from the data source, filter if we take it or not
list_of_points.forEach((feature_point: any) => { list_of_points.forEach((feature_point: any) => {
@ -236,6 +239,8 @@ function convertDataFromSource(sourceFilePath: string, mapping: MappingConfigTyp
point_counter++ point_counter++
} }
}) })
/** /**
@ -274,6 +279,11 @@ function convertDataFromSource(sourceFilePath: string, mapping: MappingConfigTyp
let fileNameToWrite = '_' + filteredName + output_supplement + '.json' let fileNameToWrite = '_' + filteredName + output_supplement + '.json'
console.log('converted features:', converted_geo_json.features.length) console.log('converted features:', converted_geo_json.features.length)
console.log('diff: ', data_transformed.features.length - converted_geo_json.features.length) console.log('diff: ', data_transformed.features.length - converted_geo_json.features.length)
let percentChange = 100-((1-(data_transformed.features.length / converted_geo_json.features.length))*-1)
console.log('Changement de features', percentChange,'%')
if(percentChange>5){
console.log(' /!\\ pas mal de points en moins, plus de '+percentChange+'%')
}
debugLog('convert : write file ', fileNameToWrite) debugLog('convert : write file ', fileNameToWrite)
// console.log('mapping_engine.stats', Mapping_engine.stats) // console.log('mapping_engine.stats', Mapping_engine.stats)

View File

@ -16,8 +16,8 @@ const mappingRouenParkingVelos: MappingConfigType = {
url: 'https://data.metropole-rouen-normandie.fr/api/explore/v2.1/catalog/datasets/liste-des-stationnements-cyclables-metropole-rouen-normandie/exports/geojson?lang=fr&timezone=Europe%2FBerlin' url: 'https://data.metropole-rouen-normandie.fr/api/explore/v2.1/catalog/datasets/liste-des-stationnements-cyclables-metropole-rouen-normandie/exports/geojson?lang=fr&timezone=Europe%2FBerlin'
}, },
filters: { filters: {
exclude_point_if_tag_not_empty: ['osm_id'], exclude_point_if_tag_not_empty: ['id_osm'],
// offset: 1 // offset: 100
}, },
add_not_mapped_tags_too: false, add_not_mapped_tags_too: false,
boolean_keys: [ boolean_keys: [
@ -77,16 +77,8 @@ const mappingRouenParkingVelos: MappingConfigType = {
}, },
] ]
}, },
// "Anneaux": {
// "tags_to_add": [
// {
// "bicycle_parking": "stands"
// },
// ]
// },
} }
}, },
// type_aire: 'nb_pl_moto', // Poteaux => bicycle_parking=bollard, Arceaux, Anneaux => bicycle_parking=stands, Marquage, null, Non renseigné, Range-vélos, Sans, Trottoir
id_local: 'ref:FR:rouen_veloparking_id', id_local: 'ref:FR:rouen_veloparking_id',
// acces_reglement: 'access', // acces_reglement: 'access',

View File

@ -25,12 +25,14 @@ export default class {
private jardinage = false; private jardinage = false;
public stats: any; public stats: any;
private current_converted_geojson_point: any; private current_converted_geojson_point: any;
private current_geojson_point: any; private current_geojson_point: any; // currently converting point
private list_of_points: any; // list of geojson points
constructor(mappingConfig: MappingConfigType) { constructor(mappingConfig: MappingConfigType) {
this.setConfig(mappingConfig) this.setConfig(mappingConfig)
this.stats = { this.stats = {
filtered_by_excluded_tags: 0,
phones_updated: 0, phones_updated: 0,
power_output: 0, power_output: 0,
phones_updated_list: [], phones_updated_list: [],
@ -86,13 +88,13 @@ export default class {
return filteredList return filteredList
} }
// filterFeaturesByPropertyRegex(bboxConfig:any, listOfFeatures:any) { /**
// debugLog('bboxConfig', bboxConfig) * filterFeaturesByPropertyRegex
// let filteredList = listOfFeatures * TODO
// // TODO * @param propertyName
// return filteredList * @param criteriaRegex
// } * @param listOfFeatures
*/
filterFeaturesByPropertyRegex(propertyName: string, criteriaRegex: any, listOfFeatures: any) { filterFeaturesByPropertyRegex(propertyName: string, criteriaRegex: any, listOfFeatures: any) {
let filteredList = listOfFeatures.filter((feature: any) => { let filteredList = listOfFeatures.filter((feature: any) => {
return criteriaRegex.test(feature?.properties[propertyName]) return criteriaRegex.test(feature?.properties[propertyName])
@ -100,6 +102,35 @@ export default class {
return filteredList return filteredList
} }
/**
* filter a list of geojson points if one of the given exludedKeys is present in their properties.
* Example, we do not want to convert already present OSM point which have an osm_id value in their properties.
* @param list
* @param excludedKeys
*/
filterListOfPointsByExcludingIfKeyFilled(list: any, excludedKeys: Array<string>):any[] {
let newList: Array<any> = []
list.forEach((geojsonPoint: any) => {
let pointProperties = Object.keys(geojsonPoint.properties)
let addPoint = true;
excludedKeys.forEach((key: any) => {
debugLog(key, 'pointProperties[key]', pointProperties[key])
let foundProperty:string = pointProperties[key]
if ( foundProperty && foundProperty !== 'null') {
addPoint = false
}
})
if (addPoint) {
// only add points that pass the not null filter
newList.push(geojsonPoint)
} else {
this.stats.filtered_by_excluded_tags++
}
})
return newList;
}
/** /**
* retuns the converted element from mapping config if present, null otherwise * retuns the converted element from mapping config if present, null otherwise
*/ */

File diff suppressed because it is too large Load Diff