From 711fc277be657727094aeaf48d37fd372a72529d Mon Sep 17 00:00:00 2001 From: Tykayn Date: Sat, 21 Jun 2025 12:24:06 +0200 Subject: [PATCH] up stats dashboard --- assets/app.js | 95 +---------- src/Controller/PublicController.php | 2 + templates/admin/stats.html.twig | 2 +- templates/admin/stats/row.html.twig | 2 +- templates/public/dashboard.html.twig | 241 ++++++++++++++++++++++++++- 5 files changed, 246 insertions(+), 96 deletions(-) diff --git a/assets/app.js b/assets/app.js index 52a290f..782e2a7 100644 --- a/assets/app.js +++ b/assets/app.js @@ -29,96 +29,6 @@ window.getLabourerUrl = getLabourerUrl; Chart.register(ChartDataLabels); -function initDashboardChart() { - const chartCanvas = document.getElementById('statsBubbleChart'); - if (!chartCanvas) { - return; - } - - if (!chartCanvas.dataset.stats || chartCanvas.dataset.stats.length <= 2) { // <= 2 pour ignorer '[]' - console.log("Les données du graphique sont vides ou absentes, le graphique ne sera pas affiché."); - return; - } - - const statsData = JSON.parse(chartCanvas.dataset.stats); - - if (statsData && statsData.length > 0) { - const bubbleChartData = statsData.map(stat => { - const population = parseInt(stat.population, 10); - const placesCount = parseInt(stat.placesCount, 10); - const ratio = population > 0 ? (placesCount / population) * 1000 : 0; - - return { - x: population, - y: ratio, - r: Math.sqrt(placesCount) * 2, - label: stat.name, - completion: stat.completionPercent || 0 - }; - }); - - new Chart(chartCanvas.getContext('2d'), { - type: 'bubble', - data: { - datasets: [{ - label: 'Villes', - data: bubbleChartData, - backgroundColor: bubbleChartData.map(d => `rgba(255, 99, 132, ${d.completion / 100})`), - borderColor: 'rgba(255, 99, 132, 1)', - }] - }, - options: { - responsive: true, - plugins: { - datalabels: { - anchor: 'center', - align: 'center', - color: '#000', - font: { - weight: 'bold' - }, - formatter: (value, context) => { - return context.dataset.data[context.dataIndex].label; - } - }, - legend: { - display: false - }, - tooltip: { - callbacks: { - label: (context) => { - const d = context.raw; - return [ - `${d.label}`, - `Population: ${d.x.toLocaleString()}`, - `Lieux / 1000 hab: ${d.y.toFixed(2)}`, - `Total lieux: ${Math.round(Math.pow(d.r / 2, 2))}`, - `Complétion: ${d.completion}%` - ]; - } - } - } - }, - scales: { - x: { - type: 'logarithmic', - title: { - display: true, - text: 'Population (échelle log)' - } - }, - y: { - title: { - display: true, - text: 'Commerces pour 1000 habitants' - } - } - } - } - }); - } -} - // Attendre le chargement du DOM document.addEventListener('DOMContentLoaded', () => { console.log('DOMContentLoaded'); @@ -266,8 +176,7 @@ document.addEventListener('DOMContentLoaded', () => { }); } - enableLabourageForm(); - initDashboardChart(); - + enableLabourageForm(); adjustListGroupFontSize('.list-group-item'); }); + diff --git a/src/Controller/PublicController.php b/src/Controller/PublicController.php index cb89a3c..09c8ed3 100644 --- a/src/Controller/PublicController.php +++ b/src/Controller/PublicController.php @@ -183,6 +183,8 @@ class PublicController extends AbstractController 'placesCount' => $stat->getPlacesCount(), 'completionPercent' => $stat->getCompletionPercent(), 'population' => $stat->getPopulation(), + 'zone' => $stat->getZone(), + 'osmDataDateAvg' => $stat->getOsmDataDateAvg() ? $stat->getOsmDataDateAvg()->format('Y-m-d') : null, ]; } } diff --git a/templates/admin/stats.html.twig b/templates/admin/stats.html.twig index f987e83..1a9cd17 100644 --- a/templates/admin/stats.html.twig +++ b/templates/admin/stats.html.twig @@ -632,7 +632,7 @@ function getCompletionColor(completion) { if (completion.percentage < 100) { content += `
-
Informations manquantes :
+
Infos manquantes :
diff --git a/templates/admin/stats/row.html.twig b/templates/admin/stats/row.html.twig index 7774e71..136dc24 100644 --- a/templates/admin/stats/row.html.twig +++ b/templates/admin/stats/row.html.twig @@ -23,7 +23,7 @@ data-bs-html="true" data-bs-content="
-
Informations manquantes :
+
Infos manquantes :
    {% if not commerce.name %}
  • Nom du commerce
  • diff --git a/templates/public/dashboard.html.twig b/templates/public/dashboard.html.twig index 366d51b..dd6eea2 100644 --- a/templates/public/dashboard.html.twig +++ b/templates/public/dashboard.html.twig @@ -68,6 +68,20 @@
    +
    +            
+
+ + +
+
+
+
+ Fraîcheur des données OSM (âge moyen par trimestre) +
+
+ +
@@ -160,5 +174,230 @@ {% block javascripts %} {{ parent() }} - {# Le script du graphique est maintenant dans assets/app.js #} + + + {% endblock %} \ No newline at end of file