From 4300278f158e2234967e3ec37f9c174a1396c0f9 Mon Sep 17 00:00:00 2001 From: Tykayn Date: Sun, 29 Jun 2025 20:02:51 +0200 Subject: [PATCH] =?UTF-8?q?up=20d=C3=A9compte=20lieux?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Controller/AdminController.php | 20 +++++++++++++------- src/Service/FollowUpService.php | 15 ++++++++++++++- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/Controller/AdminController.php b/src/Controller/AdminController.php index 933a516..931725e 100644 --- a/src/Controller/AdminController.php +++ b/src/Controller/AdminController.php @@ -385,20 +385,22 @@ final class AdminController extends AbstractController // Récupérer les derniers followups pour chaque type $latestFollowups = []; - $types = [ - 'fire_hydrant', 'charging_station', 'toilets', 'bus_stop', 'defibrillator', 'camera', 'recycling', 'substation', 'places' - ]; + $types = array_keys(\App\Service\FollowUpService::getFollowUpThemes()); foreach ($types as $type) { $count = null; $completion = null; foreach ($stats->getCityFollowUps() as $fu) { if ($fu->getName() === $type . '_count') { - if ($count === null || $fu->getDate() > $count->getDate()) { + if ($count === null) { + $count = $fu; + } else if ($fu->getDate() > $count->getDate()) { $count = $fu; } } if ($fu->getName() === $type . '_completion') { - if ($completion === null || $fu->getDate() > $completion->getDate()) { + if ($completion === null) { + $completion = $fu; + } else if ($fu->getDate() > $completion->getDate()) { $completion = $fu; } } @@ -412,12 +414,16 @@ final class AdminController extends AbstractController $completion = null; foreach ($stats->getCityFollowUps() as $fu) { if ($fu->getName() === 'places_count') { - if ($count === null || $fu->getDate() > $count->getDate()) { + if ($count === null) { + $count = $fu; + } else if ($fu->getDate() > $count->getDate()) { $count = $fu; } } if ($fu->getName() === 'places_completion') { - if ($completion === null || $fu->getDate() > $completion->getDate()) { + if ($completion === null) { + $completion = $fu; + } else if ($fu->getDate() > $completion->getDate()) { $completion = $fu; } } diff --git a/src/Service/FollowUpService.php b/src/Service/FollowUpService.php index 3450c0a..b83ec9c 100644 --- a/src/Service/FollowUpService.php +++ b/src/Service/FollowUpService.php @@ -48,6 +48,8 @@ class FollowUpService }) ?? []; } elseif ($type === 'bicycle_parking') { $objects = array_filter($elements, fn($el) => ($el['tags']['amenity'] ?? null) === 'bicycle_parking') ?? []; + } elseif ($type === 'places') { + $objects = []; } else { $objects = []; } @@ -61,10 +63,12 @@ class FollowUpService // Suivi du nombre $followupCount = new CityFollowUp(); $followupCount->setName($type . '_count') - ->setMeasure(count($data['objects'])) + ->setMeasure($type === 'places' ? $stats->getPlacesCount() : count($data['objects'])) ->setDate($now) ->setStats($stats); $em->persist($followupCount); + + // Suivi de la complétion personnalisé (exemples) $completed = []; if ($type === 'fire_hydrant') { @@ -125,6 +129,15 @@ class FollowUpService return !empty($el['tags']['capacity'] ?? null) || !empty($el['tags']['covered'] ?? null); }); } + 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; + } + } + $completion = count($data['objects']) > 0 ? round(count($completed) / count($data['objects']) * 100) : 0; $followupCompletion = new CityFollowUp(); $followupCompletion->setName($type . '_completion')