From 5deda4a01d8d88dd1768bcff822d22f4921ef1a8 Mon Sep 17 00:00:00 2001 From: Tykayn Date: Mon, 18 Aug 2025 12:58:11 +0200 Subject: [PATCH] add logs to main city page --- .../admin/followup_theme_graph.html.twig | 116 +++++++++--------- templates/admin/stats.html.twig | 27 +++- 2 files changed, 79 insertions(+), 64 deletions(-) diff --git a/templates/admin/followup_theme_graph.html.twig b/templates/admin/followup_theme_graph.html.twig index b9af178..f5dc24e 100644 --- a/templates/admin/followup_theme_graph.html.twig +++ b/templates/admin/followup_theme_graph.html.twig @@ -200,17 +200,6 @@ - - {% if theme == 'bicycle_parking' %} - {% include 'admin/_followup_bicycle_parking_extra.html.twig' %} - {% endif %} - - {% if theme == 'camera' %} - {% include 'admin/_followup_cameras_extra.html.twig' %} - {% endif %} - - - {% if josm_url %} Ouvrir tous les objets dans JOSM @@ -226,8 +215,15 @@ Overpass Turbo {% endif %} -
+ {% if theme == 'bicycle_parking' %} + {% include 'admin/_followup_bicycle_parking_extra.html.twig' %} + {% endif %} + + {% if theme == 'camera' %} + {% include 'admin/_followup_cameras_extra.html.twig' %} + {% endif %} +
@@ -527,76 +523,76 @@ if (average_completion && current_completion) { current_completion.textContent = average_completion.toFixed(2) + ' %'; } - + // Send measurement to /api/city-followup const insee_code = '{{ stats.zone }}'; const theme = '{{ theme }}'; - + // Prepare data for the API request const measureData = new FormData(); measureData.append('insee_code', insee_code); measureData.append('measure_label', theme + '_count'); measureData.append('measure_value', count_objects); - + // Send count measurement fetch('/api/city-followup', { method: 'POST', body: measureData }) - .then(response => response.json()) - .then(result => { - console.log('Count measurement saved:', result); - if (result.success) { - // Add the new measurement to the chart data - const newMeasurement = { - date: result.follow_up.date, - value: result.follow_up.measure - }; - - // Add to the global countData array - if (Array.isArray(window.countData)) { - window.countData.push(newMeasurement); - // Update the chart - updateChart(); - } - } - }) - .catch(error => { - console.error('Error saving count measurement:', error); - }); - - // Send completion measurement - if (average_completion) { - const completionData = new FormData(); - completionData.append('insee_code', insee_code); - completionData.append('measure_label', theme + '_completion'); - completionData.append('measure_value', average_completion); - - fetch('/api/city-followup', { - method: 'POST', - body: completionData - }) .then(response => response.json()) .then(result => { - console.log('Completion measurement saved:', result); + console.log('Count measurement saved:', result); if (result.success) { // Add the new measurement to the chart data const newMeasurement = { date: result.follow_up.date, value: result.follow_up.measure }; - - // Add to the global completionData array - if (Array.isArray(window.completionData)) { - window.completionData.push(newMeasurement); + + // Add to the global countData array + if (Array.isArray(window.countData)) { + window.countData.push(newMeasurement); // Update the chart updateChart(); } } }) .catch(error => { - console.error('Error saving completion measurement:', error); + console.error('Error saving count measurement:', error); }); + + // Send completion measurement + if (average_completion) { + const completionData = new FormData(); + completionData.append('insee_code', insee_code); + completionData.append('measure_label', theme + '_completion'); + completionData.append('measure_value', average_completion); + + fetch('/api/city-followup', { + method: 'POST', + body: completionData + }) + .then(response => response.json()) + .then(result => { + console.log('Completion measurement saved:', result); + if (result.success) { + // Add the new measurement to the chart data + const newMeasurement = { + date: result.follow_up.date, + value: result.follow_up.measure + }; + + // Add to the global completionData array + if (Array.isArray(window.completionData)) { + window.completionData.push(newMeasurement); + // Update the chart + updateChart(); + } + } + }) + .catch(error => { + console.error('Error saving completion measurement:', error); + }); } const tbody = document.querySelector('#tags-stats-table tbody'); if (Object.keys(tagCounts).length === 0) { @@ -771,23 +767,23 @@ // Get the chart instance const chartInstance = Chart.getChart('themeChart'); if (!chartInstance) return; - + // Update the datasets - chartInstance.data.datasets[0].data = Array.isArray(window.countData) - ? window.countData.map(d => ({x: new Date(d.date), y: d.value})) + chartInstance.data.datasets[0].data = Array.isArray(window.countData) + ? window.countData.map(d => ({x: new Date(d.date), y: d.value})) : []; - + if (Array.isArray(window.completionData)) { chartInstance.data.datasets[1].data = window.completionData.map(d => ({ x: new Date(d.date), y: d.value })); } - + // Update the chart chartInstance.update(); } - + // Initialiser les statistiques updateStats(); diff --git a/templates/admin/stats.html.twig b/templates/admin/stats.html.twig index 665328f..9f59323 100644 --- a/templates/admin/stats.html.twig +++ b/templates/admin/stats.html.twig @@ -203,7 +203,7 @@ Données OpenStreetMap
- + {% if stats.population %}
@@ -806,6 +806,8 @@ } if (map_token && geojsonData && geojsonData.features.length > 0) { + console.log('geojsonData.features', geojsonData.features) + map = new maplibregl.Map({ container: 'map', style: `https://api.maptiler.com/maps/streets/style.json?key=${map_token}`, @@ -885,6 +887,22 @@ map.on('click', 'unclustered-point', function (e) { const coordinates = e.features[0].geometry.coordinates.slice(); const properties = e.features[0].properties; + let missing_tags = []; + + const tags_for_completion = ['name', 'wheelchair', 'siret', 'opening_hours']; + tags_for_completion.forEach(function (tag) { + if (!properties[tag]) { + missing_tags.push(tag); + } + }) + + if (!properties['phone'] && properties['contact:phone']) { + missing_tags.push('contact:phone'); + } + if (!properties['website'] && properties['contact:website']) { + missing_tags.push('contact:website'); + } + properties.missing_tags = missing_tags; let popupContent = `${properties.name || 'Sans nom'}
`; if (properties.address) popupContent += `${properties.address}
`; @@ -892,9 +910,10 @@ if (properties.note) popupContent += `Note: ${properties.note}
`; popupContent += `Complétion : ${properties.completion !== null ? properties.completion + '%' : '–'}`; const missingTags = Array.isArray(properties.missing_tags) ? properties.missing_tags : []; - if (missingTags.length > 0) { - popupContent += `
Manque : ${missingTags.map(t => `${t}`).join(', ')}
`; - } + console.log('e.features[0]', e.features[0], missingTags, 'tags', properties) + // if (missingTags.length > 0) { + // popupContent += `
Manque : ${missingTags.map(t => `${t}`).join(', ')}
`; + // } popupContent += `
Voir sur OSM`; while (Math.abs(e.lngLat.lng - coordinates[0]) > 180) {