recompute percent completion if needed on load of city stats

This commit is contained in:
Tykayn 2025-08-12 11:42:23 +02:00 committed by tykayn
parent b959c695ae
commit 46f8b3f6ab

View file

@ -302,6 +302,12 @@ final class AdminController extends AbstractController
$this->addFlash('error', '1 Aucune stats trouvée pour ce code INSEE. Veuillez d\'abord ajouter la ville.'); $this->addFlash('error', '1 Aucune stats trouvée pour ce code INSEE. Veuillez d\'abord ajouter la ville.');
return $this->redirectToRoute('app_admin_import_stats'); return $this->redirectToRoute('app_admin_import_stats');
} }
$completion = $stats->getCompletionPercent();
if (!$completion) {
$stats->computeCompletionPercent();
$completion = $stats->getCompletionPercent();
}
$followups = $stats->getCityFollowUps(); $followups = $stats->getCityFollowUps();
$refresh = false; $refresh = false;
if (!$followups->isEmpty()) { if (!$followups->isEmpty()) {
@ -735,15 +741,15 @@ final class AdminController extends AbstractController
// Calculate current metrics from objects array (from Overpass data) // Calculate current metrics from objects array (from Overpass data)
$currentCount = count($objects); $currentCount = count($objects);
// Calculate current completion percentage // Calculate current completion percentage
$completionTags = \App\Service\FollowUpService::getFollowUpCompletionTags()[$theme] ?? []; $completionTags = \App\Service\FollowUpService::getFollowUpCompletionTags()[$theme] ?? [];
$currentCompletion = 0; $currentCompletion = 0;
if ($currentCount > 0 && !empty($completionTags)) { if ($currentCount > 0 && !empty($completionTags)) {
$totalTags = count($completionTags) * $currentCount; $totalTags = count($completionTags) * $currentCount;
$filledTags = 0; $filledTags = 0;
foreach ($objects as $obj) { foreach ($objects as $obj) {
// Get the original Place object to check tags // Get the original Place object to check tags
$place = null; $place = null;
@ -753,7 +759,7 @@ final class AdminController extends AbstractController
break; break;
} }
} }
if ($place) { if ($place) {
foreach ($completionTags as $tag) { foreach ($completionTags as $tag) {
// Simple check for name tag // Simple check for name tag
@ -764,10 +770,10 @@ final class AdminController extends AbstractController
} }
} }
} }
$currentCompletion = $totalTags > 0 ? round(($filledTags / $totalTags) * 100) : 0; $currentCompletion = $totalTags > 0 ? round(($filledTags / $totalTags) * 100) : 0;
} }
// Add current data to history if empty // Add current data to history if empty
if (empty($countData)) { if (empty($countData)) {
$countData[] = [ $countData[] = [
@ -775,14 +781,14 @@ final class AdminController extends AbstractController
'value' => $currentCount 'value' => $currentCount
]; ];
} }
if (empty($completionData)) { if (empty($completionData)) {
$completionData[] = [ $completionData[] = [
'date' => (new \DateTime())->format('Y-m-d'), 'date' => (new \DateTime())->format('Y-m-d'),
'value' => $currentCompletion 'value' => $currentCompletion
]; ];
} }
return $this->render('admin/followup_theme_graph.html.twig', [ return $this->render('admin/followup_theme_graph.html.twig', [
'stats' => $stats, 'stats' => $stats,
'theme' => $theme, 'theme' => $theme,