From 060b23f87e3c0307a9b8d958347992b3741cbb2d Mon Sep 17 00:00:00 2001 From: Tykayn Date: Mon, 18 Aug 2025 12:41:31 +0200 Subject: [PATCH] =?UTF-8?q?harmoniser=20les=20d=C3=A9comptes=20de=20comple?= =?UTF-8?q?tion=20sur=20la=20page=20stats?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Controller/AdminController.php | 41 +- templates/admin/followup_graph.html.twig | 579 ++++++++++++----------- templates/admin/stats.html.twig | 124 +++-- 3 files changed, 399 insertions(+), 345 deletions(-) diff --git a/src/Controller/AdminController.php b/src/Controller/AdminController.php index b23a0de..a6fd01f 100644 --- a/src/Controller/AdminController.php +++ b/src/Controller/AdminController.php @@ -303,11 +303,11 @@ final class AdminController extends AbstractController return $this->redirectToRoute('app_admin_import_stats'); } - $completion = $stats->getCompletionPercent(); - if (!$completion) { - $stats->computeCompletionPercent(); - $completion = $stats->getCompletionPercent(); - } +// $completion = $stats->getCompletionPercent(); +// if (!$completion) { +// $stats->computeCompletionPercent(); +// $completion = $stats->getCompletionPercent(); +// } $followups = $stats->getCityFollowUps(); $refresh = false; if (!$followups->isEmpty()) { @@ -378,7 +378,7 @@ final class AdminController extends AbstractController // Update the places_count property $stats->setPlacesCount($stats->getPlaces()->count()); - $this->entityManager->persist($stats); +// $this->entityManager->persist($stats); } $this->entityManager->flush(); @@ -433,6 +433,15 @@ final class AdminController extends AbstractController if (isset($commerces) && is_iterable($commerces)) { foreach ($commerces as $commerce) { if ($commerce->getLat() && $commerce->getLon()) { + // Collect missing tags + $missingTags = []; + if (!$commerce->getName()) $missingTags[] = 'name'; + if (!$commerce->hasAddress()) $missingTags[] = 'address'; + if (!$commerce->hasOpeningHours()) $missingTags[] = 'opening_hours'; + if (!$commerce->hasWebsite()) $missingTags[] = 'website'; + if (!$commerce->hasWheelchair()) $missingTags[] = 'wheelchair'; + if (!$commerce->getSiret()) $missingTags[] = 'siret'; + $geojson['features'][] = [ 'type' => 'Feature', 'geometry' => [ @@ -445,7 +454,9 @@ final class AdminController extends AbstractController 'main_tag' => $commerce->getMainTag(), 'address' => $commerce->getStreet() . ' ' . $commerce->getHousenumber(), 'note' => $commerce->getNoteContent(), - 'osm_url' => 'https://www.openstreetmap.org/' . $commerce->getOsmKind() . '/' . $commerce->getOsmId() + 'osm_url' => 'https://www.openstreetmap.org/' . $commerce->getOsmKind() . '/' . $commerce->getOsmId(), + 'completion' => $commerce->getCompletionPercentage(), + 'missing_tags' => $missingTags ] ]; } @@ -1955,8 +1966,24 @@ final class AdminController extends AbstractController } unset($points); + + $now = new \DateTime(); + $last_week = new \DateTime(); + $last_week->sub(new \DateInterval('P7D')); + + $adiff_query = '[timeout:60] +[adiff:"' . $now->format('Y-m-d') . 'T' . $now->format('H:i:s') . 'Z","2025-08-05T00:00:00Z"][out:xml]; + area["ref:INSEE"="91111"]->.searchArea; + ( + nwr(area.searchArea); + ); +out meta;'; + return $this->render('admin/followup_graph.html.twig', [ + 'adiff_query' => $adiff_query, 'stats' => $stats, + + 'completion_tags' => \App\Service\FollowUpService::getFollowUpCompletionTags(), 'followup_labels' => \App\Service\FollowUpService::getFollowUpThemes(), 'followup_icons' => \App\Service\FollowUpService::getFollowUpIcons(), diff --git a/templates/admin/followup_graph.html.twig b/templates/admin/followup_graph.html.twig index 7efc4fe..780ba22 100644 --- a/templates/admin/followup_graph.html.twig +++ b/templates/admin/followup_graph.html.twig @@ -4,69 +4,81 @@ {% block stylesheets %} {{ parent() }} - + {% endblock %} {% block body %} -
-
- -
- {% include 'admin/_city_sidebar.html.twig' with {'stats': stats, 'active_menu': 'followup_graph'} %} -
+
+
+ +
+ {% include 'admin/_city_sidebar.html.twig' with {'stats': stats, 'active_menu': 'followup_graph'} %} +
- -
-
-

Suivi des objets OSM pour {{ stats.name }} ({{ stats.zone }})

- -

Historique des objets suivis (nombre et complétion).

-
- {% set has_change = false %} - - - - - - - - - - - {% for type, diff in latest_diffs %} - {% set has_period_change = (diff.count_diff_7j != 0 or diff.count_diff_30j != 0 or diff.count_diff_6mois != 0) %} - {% if has_period_change %} - {% set has_change = true %} - - - + + {% endif %} + {% endfor %} + {% if not has_change %} + + + + {% endif %} + +
ThèmeÉvolution 7jÉvolution 30jÉvolution 6 mois
- - {{ tag_emoji(type) }} {{ diff.label }} - - - {% if diff.count_diff_7j > 0 %} - - {% elseif diff.count_diff_7j < 0 %} - - {% else %} - - {% endif %} - {{ diff.count_diff_7j > 0 ? '+' ~ diff.count_diff_7j : diff.count_diff_7j }} objets -
- Complétion : + +
+
+

Suivi des objets OSM pour {{ stats.name }} ({{ stats.zone }})

+ +

Historique des objets suivis (nombre et complétion).

+
+ {% set has_change = false %} + + + + + + + + + + + {% for type, diff in latest_diffs %} + {% set has_period_change = (diff.count_diff_7j != 0 or diff.count_diff_30j != 0 or diff.count_diff_6mois != 0) %} + {% if has_period_change %} + {% set has_change = true %} + + + - + - + - - {% endif %} - {% endfor %} - {% if not has_change %} - - {% endif %} - -
Thème + {#
 #}
+
+                                    {#                                     {{ dump(adiff_query ) }} #}
+                                    {#                                    
#} + {# Évolution 7j #} + {# #} +
Évolution 30jÉvolution 6 mois
+ + {{ tag_emoji(type) }} {{ diff.label }} + + + {% if diff.count_diff_7j > 0 %} + + {% elseif diff.count_diff_7j < 0 %} + + {% else %} + + {% endif %} + {{ diff.count_diff_7j > 0 ? '+' ~ diff.count_diff_7j : diff.count_diff_7j }} + objets +
+ Complétion : {% if diff.completion_diff_7j > 0 %} {% elseif diff.completion_diff_7j < 0 %} @@ -74,20 +86,21 @@ {% else %} {% endif %} - {{ diff.completion_diff_7j > 0 ? '+' ~ diff.completion_diff_7j : diff.completion_diff_7j }}% + {{ diff.completion_diff_7j > 0 ? '+' ~ diff.completion_diff_7j : diff.completion_diff_7j }}% -
- {% if diff.count_diff_30j > 0 %} - - {% elseif diff.count_diff_30j < 0 %} - - {% else %} - - {% endif %} - {{ diff.count_diff_30j > 0 ? '+' ~ diff.count_diff_30j : diff.count_diff_30j }} objets -
- Complétion : +
+ {% if diff.count_diff_30j > 0 %} + + {% elseif diff.count_diff_30j < 0 %} + + {% else %} + + {% endif %} + {{ diff.count_diff_30j > 0 ? '+' ~ diff.count_diff_30j : diff.count_diff_30j }} + objets +
+ Complétion : {% if diff.completion_diff_30j > 0 %} {% elseif diff.completion_diff_30j < 0 %} @@ -95,20 +108,21 @@ {% else %} {% endif %} - {{ diff.completion_diff_30j > 0 ? '+' ~ diff.completion_diff_30j : diff.completion_diff_30j }}% + {{ diff.completion_diff_30j > 0 ? '+' ~ diff.completion_diff_30j : diff.completion_diff_30j }}% -
- {% if diff.count_diff_6mois > 0 %} - - {% elseif diff.count_diff_6mois < 0 %} - - {% else %} - - {% endif %} - {{ diff.count_diff_6mois > 0 ? '+' ~ diff.count_diff_6mois : diff.count_diff_6mois }} objets -
- Complétion : +
+ {% if diff.count_diff_6mois > 0 %} + + {% elseif diff.count_diff_6mois < 0 %} + + {% else %} + + {% endif %} + {{ diff.count_diff_6mois > 0 ? '+' ~ diff.count_diff_6mois : diff.count_diff_6mois }} + objets +
+ Complétion : {% if diff.completion_diff_6mois > 0 %} {% elseif diff.completion_diff_6mois < 0 %} @@ -116,225 +130,248 @@ {% else %} {% endif %} - {{ diff.completion_diff_6mois > 0 ? '+' ~ diff.completion_diff_6mois : diff.completion_diff_6mois }}% + {{ diff.completion_diff_6mois > 0 ? '+' ~ diff.completion_diff_6mois : diff.completion_diff_6mois }}% -
Aucun changement significatif cette semaine.
-
+
Aucun changement significatif cette semaine.
+
- {% for type, label in followup_labels %} -

{{ label }}

- -
- {% set overpass_query = '[out:json][timeout:60];\narea["ref:INSEE"="' ~ stats.zone ~ '"]->.searchArea;\n(' ~ followup_overpass[type]|default('') ~ ');\n\n(._;>;);\n\nout meta;\n>;' %} - - Voir sur Overpass Turbo - - - Ouvrir dans JOSM - - - Version embarquée - -
- {% include 'admin/_followup_completion_tags.html.twig' with { - 'completion_tags': completion_tags, - 'followup_labels': followup_labels, - 'all_types': [type] - } %} - {% endfor %} + {% for type, label in followup_labels %} +

{{ label }} +

+ +
+ {% set overpass_query = '[out:json][timeout:60];\narea["ref:INSEE"="' ~ stats.zone ~ '"]->.searchArea;\n(' ~ followup_overpass[type]|default('') ~ ');\n\n(._;>;);\n\nout meta;\n>;' %} + + Voir sur Overpass Turbo + + + Ouvrir dans JOSM + + + Version embarquée + + + Détails + +
+ {% include 'admin/_followup_completion_tags.html.twig' with { + 'completion_tags': completion_tags, + 'followup_labels': followup_labels, + 'all_types': [type] + } %} + {% endfor %} -

Évolution du taux de complétion (CTC - Complète tes commerces)

- +

Évolution du taux de complétion (CTC - Complète tes commerces)

+ -

Données brutes

- - - - - - - - - - - {% for point in all_points %} - - - - - - - {% endfor %} - -
DateTypeLabelValeur
{{ point.date }}{{ point.type }}{{ point.name }}{{ point.value }}
- Retour à la fiche ville +

Données brutes

+ + + + + + + + + + + {% for point in all_points %} + + + + + + + {% endfor %} + +
DateTypeLabelValeur
{{ point.date }}{{ point.type }}{{ point.name }}{{ point.value }}
+ Retour à la fiche ville +
-
{% endblock %} {% block javascripts %} -{{ parent() }} - - - - - + + + + + }); + {% endblock %} diff --git a/templates/admin/stats.html.twig b/templates/admin/stats.html.twig index dfa6361..665328f 100644 --- a/templates/admin/stats.html.twig +++ b/templates/admin/stats.html.twig @@ -150,6 +150,60 @@ {{ stats.name }} - {{ stats.completionPercent }}% complété
+ + +
+

Carte

+
+
+ + Chargement de la carte... +
+
+
+
+ + +
+ +
+
+ +
+

Graphiques

+
+
+ +
+ +
+
+
+ Fréquence des mises à jour par + trimestre pour {{ stats.name }} +
+
+ +
+
+
+
+
+ + + +
+ {% if stats.population %}
@@ -466,57 +520,6 @@
-
-

Carte

-
-
- - Chargement de la carte... -
-
-
-
- - -
- -
-
- -
-

Graphiques

-
-
- -
- -
-
-
- Fréquence des mises à jour par - trimestre pour {{ stats.name }} -
-
- -
-
-
-
-
- - - -
{% include 'admin/stats_history.html.twig' with {stat: stats} %} @@ -718,23 +721,10 @@ document.addEventListener('DOMContentLoaded', function () { const geojsonData = {{ geojson|raw }}; const map_token = "{{ maptiler_token }}"; - // Liste des tags attendus pour la complétion des lieux - const completionTags = {{ completion_tags['places']|json_encode|raw }}; - // Calcul de la complétion et des tags manquants pour chaque lieu + // Les valeurs de complétion et tags manquants sont maintenant calculées côté serveur + // et incluses directement dans les données GeoJSON geojsonData.features.forEach(f => { - let filled = 0; - let missing = []; - if (completionTags && completionTags.length > 0) { - completionTags.forEach(tag => { - if (f.properties && typeof f.properties[tag] !== 'undefined' && f.properties[tag] !== null && f.properties[tag] !== '') { - filled++; - } else { - missing.push(tag); - } - }); - } - f.properties.completion = completionTags && completionTags.length > 0 ? Math.round(100 * filled / completionTags.length) : null; - // Correction : toujours un tableau + // Assurons-nous que missing_tags est toujours un tableau f.properties.missing_tags = Array.isArray(f.properties.missing_tags) ? f.properties.missing_tags : (f.properties.missing_tags ? [f.properties.missing_tags] : []); });