From 949dc71fb80e77880de26046b3173b03910fb8de Mon Sep 17 00:00:00 2001 From: Tykayn Date: Mon, 30 Jun 2025 15:51:51 +0200 Subject: [PATCH] =?UTF-8?q?up=20d=C3=A9compte=20de=20suivi=20des=20lieux?= =?UTF-8?q?=20et=20arbres?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Controller/FollowUpController.php | 10 ++++++ src/Service/FollowUpService.php | 26 ++++++++------ .../admin/followup_embed_graph.html.twig | 34 +++++++++++++++++-- templates/admin/followup_graph.html.twig | 18 +++++----- 4 files changed, 65 insertions(+), 23 deletions(-) diff --git a/src/Controller/FollowUpController.php b/src/Controller/FollowUpController.php index 13f0ae1..a36ee12 100644 --- a/src/Controller/FollowUpController.php +++ b/src/Controller/FollowUpController.php @@ -86,13 +86,22 @@ class FollowUpController extends AbstractController $followups = $followups->toArray(); usort($followups, fn($a, $b) => $a->getDate() <=> $b->getDate()); $series = []; + $all_points = []; foreach ($followups as $fu) { $series[$fu->getName()][] = [ 'date' => $fu->getDate()->format('c'), 'value' => $fu->getMeasure(), 'name' => $fu->getName(), ]; + $all_points[] = [ + 'date' => $fu->getDate()->format('c'), + 'type' => $fu->getName(), + 'name' => $fu->getName(), + 'value' => $fu->getMeasure(), + ]; } + usort($all_points, fn($a, $b) => strcmp($b['date'], $a['date'])); + $all_points = array_slice($all_points, 0, 20); // Tri par date dans chaque série foreach ($series as &$points) { usort($points, function($a, $b) { @@ -103,6 +112,7 @@ class FollowUpController extends AbstractController return $this->render('admin/followup_graph.html.twig', [ 'stats' => $stats, 'series' => $series, + 'all_points' => $all_points, 'followup_labels' => FollowUpService::getFollowUpThemes(), 'followup_icons' => FollowUpService::getFollowUpIcons(), 'followup_overpass' => FollowUpService::getFollowUpOverpassQueries(), diff --git a/src/Service/FollowUpService.php b/src/Service/FollowUpService.php index 8e50aea..817c049 100644 --- a/src/Service/FollowUpService.php +++ b/src/Service/FollowUpService.php @@ -183,20 +183,24 @@ class FollowUpService }); } elseif ($type === 'tree') { $completed = array_filter($data['objects'], function($el) { - // Complet si le tag "species" ou "ref" est présent - return !empty($el['tags']['species'] ?? null) || !empty($el['tags']['ref'] ?? null); + $tags = $el['tags'] ?? []; + $hasTaxonomy = !empty($tags['species'] ?? null) + || !empty($tags['genus'] ?? null) + || !empty($tags['taxon'] ?? null) + || !empty($tags['taxon:binomial'] ?? null); + $hasLeaf = !empty($tags['leaf_type'] ?? null) + || !empty($tags['leaf_cycle'] ?? null) + || !empty($tags['leaf_shape'] ?? null) + || !empty($tags['leaf_color'] ?? null) + || !empty($tags['leaf_fall'] ?? null); + return $hasTaxonomy && $hasLeaf; }); } - if ($type === 'lieux') { - // Si le type est "lieux", on utilise la méthode completionPercent() de $stats - if (method_exists($stats, 'getCompletionPercent')) { - $completion = $stats->getCompletionPercent(); - } else { - $completion = 0; - } + if ($type === 'places') { + $completion = $stats->getCompletionPercent(); + } else { + $completion = count($data['objects']) > 0 ? round(count($completed) / count($data['objects']) * 100) : 0; } - - $completion = count($data['objects']) > 0 ? round(count($completed) / count($data['objects']) * 100) : 0; $followupCompletion = new CityFollowUp(); $followupCompletion->setName($type . '_completion') ->setMeasure($completion) diff --git a/templates/admin/followup_embed_graph.html.twig b/templates/admin/followup_embed_graph.html.twig index 66ba8a4..7fb9309 100644 --- a/templates/admin/followup_embed_graph.html.twig +++ b/templates/admin/followup_embed_graph.html.twig @@ -21,6 +21,7 @@ {{ parent() }} +