ajout podium par ville

This commit is contained in:
Tykayn 2025-06-27 11:14:27 +02:00 committed by tykayn
parent c08b49fe48
commit 80bab14bf0
2 changed files with 104 additions and 1 deletions

View file

@ -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
]);
}

View file

@ -219,6 +219,62 @@
</table>
</div>
<div class="card mt-4">
<div class="card-header">
<h2>Podium des contributeurs OSM de cette ville</h2>
</div>
<div class="card-body">
<table class="table table-striped table-bordered mt-4" style="max-width:800px">
<thead class="table-dark">
<tr>
<th scope="col">#</th>
<th scope="col">Utilisateur OSM</th>
<th scope="col">Nombre de lieux</th>
<th scope="col">Score de complétion moyen</th>
<th scope="col">Score de complétion pondéré</th>
<th scope="col">Score pondéré normalisé (0-100)</th>
</tr>
</thead>
<tbody>
{% for row in podium_local %}
<tr>
<th scope="row">{{ loop.index }}</th>
<td>
<a href="https://www.openstreetmap.org/user/{{ row.osm_user|e('url') }}" target="_blank">
{{ row.osm_user }}
</a>
</td>
<td>{{ row.nb }}</td>
<td>
{% if row.completion_moyen is not null %}
{{ row.completion_moyen }}&nbsp;%
{% else %}
<span class="text-muted">N/A</span>
{% endif %}
</td>
<td>
{% if row.completion_pondere is not null %}
{{ row.completion_pondere }}
{% else %}
<span class="text-muted">N/A</span>
{% endif %}
</td>
<td>
{% if row.completion_pondere_normalisee is not null %}
{{ row.completion_pondere_normalisee }}
{% else %}
<span class="text-muted">N/A</span>
{% endif %}
</td>
</tr>
{% else %}
<tr><td colspan="6">Aucun contributeur trouvé pour cette ville.</td></tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{# <div class="card mt-4">
<div class="card-header">
<h2>Requête Overpass</h2>