up stats of watched tags in osm extract

This commit is contained in:
Tykayn 2025-05-04 21:17:02 +02:00 committed by tykayn
parent 41b543cece
commit 872d14e17c
4 changed files with 31 additions and 8 deletions

View file

@ -1,7 +1,7 @@
import fs from 'fs';
import fetch from 'node-fetch';
import * as cheerio from 'cheerio';
import lcm_config from './js/lcm_config.js';
let stats = {};
@ -46,6 +46,8 @@ async function compterFeaturesInOpenDataEtalab() {
let count_nb_pdc_ok = 0;
let unique_id_station_itinerance = []
let count_id_station_itinerance_duplicate = 0;
geojson.features.forEach(feature => {
if (feature.properties.id_station_itinerance) {
if (!unique_id_station_itinerance.includes(feature.properties.id_station_itinerance)) {
@ -64,6 +66,7 @@ async function compterFeaturesInOpenDataEtalab() {
}
count_capacity += nbre_pdc;
}
;
});
// Créer l'objet de statistiques
stats = {
@ -74,7 +77,7 @@ async function compterFeaturesInOpenDataEtalab() {
count_nb_pdc_okOpenData: count_nb_pdc_ok,
count_id_station_itinerance_duplicate: count_id_station_itinerance_duplicate,
count_unique_id_station_itinerance: unique_id_station_itinerance.length,
dateGeneration: new Date().toISOString()
dateGeneration: new Date().toISOString(),
};
@ -156,20 +159,36 @@ function compterFeaturesInOpenStreetMapFromFile() {
const nombreFeaturesInOSM = data.elements.length;
let countPointsDeChargeOSM = 0;
// Initialiser le compteur pour chaque tag
let tagsCountOSM = {};
lcm_config.tags_to_display_in_popup.forEach(tag => {
tagsCountOSM[tag] = 0;
});
data.elements.forEach(element => {
if (element.type === 'node' && element.tags.capacity) {
if (element.type === 'node' && element.tags && element.tags.capacity) {
let capa = parseInt(element.tags.capacity)
if (isNaN(capa)) {
capa = 1;
}
countPointsDeChargeOSM += capa;
}
// Compter les tags présents
if (element.tags) {
lcm_config.tags_to_display_in_popup.forEach(tag => {
if (element.tags[tag] !== undefined && element.tags[tag] !== null && element.tags[tag] !== "") {
tagsCountOSM[tag]++;
}
});
}
});
stats = {
...stats,
countStationsOSM: nombreFeaturesInOSM,
countPointsDeChargeOSM: countPointsDeChargeOSM
countPointsDeChargeOSM: countPointsDeChargeOSM,
tagsCountOSM
};
} catch (erreur) {
console.error('Erreur lors du traitement du fichier OSM:', erreur.message);