diff --git a/src/Controller/AdminController.php b/src/Controller/AdminController.php index 33dd81e..0fb0ea1 100644 --- a/src/Controller/AdminController.php +++ b/src/Controller/AdminController.php @@ -317,6 +317,52 @@ final class AdminController extends AbstractController } } + // Générer le podium local des contributeurs OSM pour cette ville + $placeRepo = $this->entityManager->getRepository(\App\Entity\Place::class); + $qb = $placeRepo->createQueryBuilder('p') + ->select( + 'p.osm_user', + 'COUNT(p.id) as nb', + 'AVG((CASE WHEN p.has_opening_hours = true THEN 1 ELSE 0 END) +' + . ' (CASE WHEN p.has_address = true THEN 1 ELSE 0 END) +' + . ' (CASE WHEN p.has_website = true THEN 1 ELSE 0 END) +' + . ' (CASE WHEN p.has_wheelchair = true THEN 1 ELSE 0 END) +' + . ' (CASE WHEN p.has_note = true THEN 1 ELSE 0 END)) / 5 * 100 as completion_moyen' + ) + ->where('p.osm_user IS NOT NULL') + ->andWhere("p.osm_user != ''") + ->andWhere('p.stats = :stats') + ->setParameter('stats', $stats) + ->groupBy('p.osm_user') + ->orderBy('nb', 'DESC') + ->setMaxResults(100); + $podium_local = $qb->getQuery()->getResult(); + // Calcul du score pondéré et normalisation locale + $maxPondere = 0; + foreach ($podium_local as &$row) { + $row['completion_moyen'] = $row['completion_moyen'] !== null ? round($row['completion_moyen'], 1) : null; + $row['completion_pondere'] = ($row['completion_moyen'] !== null && $row['nb'] > 0) + ? round($row['completion_moyen'] * $row['nb'], 1) + : null; + if ($row['completion_pondere'] !== null && $row['completion_pondere'] > $maxPondere) { + $maxPondere = $row['completion_pondere']; + } + } + unset($row); + if ($maxPondere > 0) { + foreach ($podium_local as &$row) { + if ($row['completion_pondere'] !== null) { + $row['completion_pondere_normalisee'] = round($row['completion_pondere'] / $maxPondere * 100, 1); + } else { + $row['completion_pondere_normalisee'] = null; + } + } + unset($row); + } + usort($podium_local, function ($a, $b) { + return ($b['completion_pondere_normalisee'] ?? 0) <=> ($a['completion_pondere_normalisee'] ?? 0); + }); + return $this->render('admin/stats.html.twig', [ 'stats' => $stats, 'commerces' => $commerces, @@ -326,7 +372,8 @@ final class AdminController extends AbstractController 'maptiler_token' => $_ENV['MAPTILER_TOKEN'], 'statsHistory' => $statsHistory, 'CTC_urls' => $urls, - 'overpass' => '' + 'overpass' => '', + 'podium_local' => $podium_local ]); } diff --git a/templates/admin/stats.html.twig b/templates/admin/stats.html.twig index 29c21d2..c3ddbab 100644 --- a/templates/admin/stats.html.twig +++ b/templates/admin/stats.html.twig @@ -219,6 +219,62 @@ +
# | +Utilisateur OSM | +Nombre de lieux | +Score de complétion moyen | +Score de complétion pondéré | +Score pondéré normalisé (0-100) | +
---|---|---|---|---|---|
{{ loop.index }} | ++ + {{ row.osm_user }} + + | +{{ row.nb }} | ++ {% if row.completion_moyen is not null %} + {{ row.completion_moyen }} % + {% else %} + N/A + {% endif %} + | ++ {% if row.completion_pondere is not null %} + {{ row.completion_pondere }} + {% else %} + N/A + {% endif %} + | ++ {% if row.completion_pondere_normalisee is not null %} + {{ row.completion_pondere_normalisee }} + {% else %} + N/A + {% endif %} + | +
Aucun contributeur trouvé pour cette ville. |