mirror of
https://forge.chapril.org/tykayn/osm-commerces
synced 2025-10-09 17:02:46 +02:00
thèmes en plus, graph embed
This commit is contained in:
parent
4300278f15
commit
f4e8c70ead
7 changed files with 327 additions and 9 deletions
|
@ -260,18 +260,32 @@ final class AdminController extends AbstractController
|
|||
]);
|
||||
}
|
||||
|
||||
#[Route('/admin/stats/{insee_code}', name: 'app_admin_stats')]
|
||||
public function calculer_stats(string $insee_code): Response
|
||||
#[Route('/admin/stats/{insee_code}', name: 'app_admin_stats', requirements: ['insee_code' => '\\d+'])]
|
||||
public function stats(string $insee_code): Response
|
||||
{
|
||||
// Récupérer les stats existantes pour la zone
|
||||
$stats = $this->entityManager->getRepository(Stats::class)->findOneBy(['zone' => $insee_code]);
|
||||
if (!$stats) {
|
||||
// Si aucune statistique n'existe pour cette zone, rediriger vers le labourage de la zone
|
||||
return $this->redirectToRoute('app_admin_labourer', ['insee_code' => $insee_code]);
|
||||
$this->addFlash('error', 'Aucune stats trouvée pour ce code INSEE.');
|
||||
return $this->redirectToRoute('app_admin');
|
||||
}
|
||||
// Si aucun followup n'existe, on les régénère automatiquement
|
||||
if ($stats->getCityFollowUps()->isEmpty()) {
|
||||
$followups = $stats->getCityFollowUps();
|
||||
$refresh = false;
|
||||
if (!$followups->isEmpty()) {
|
||||
$latest = null;
|
||||
foreach ($followups as $fu) {
|
||||
if ($latest === null || $fu->getDate() > $latest->getDate()) {
|
||||
$latest = $fu;
|
||||
}
|
||||
}
|
||||
if ($latest && $latest->getDate() < (new \DateTime('-1 day'))) {
|
||||
$refresh = true;
|
||||
}
|
||||
} else {
|
||||
$refresh = true;
|
||||
}
|
||||
if ($refresh) {
|
||||
$this->followUpService->generateCityFollowUps($stats, $this->motocultrice, $this->entityManager);
|
||||
$followups = $stats->getCityFollowUps();
|
||||
}
|
||||
$commerces = $stats->getPlaces();
|
||||
$this->actionLogger->log('stats_de_ville', ['insee_code' => $insee_code, 'nom' => $stats->getZone()]);
|
||||
|
|
|
@ -65,7 +65,21 @@ class FollowUpController extends AbstractController
|
|||
return $this->redirectToRoute('app_admin');
|
||||
}
|
||||
$followups = $stats->getCityFollowUps();
|
||||
if ($followups->isEmpty()) {
|
||||
$refresh = false;
|
||||
if (!$followups->isEmpty()) {
|
||||
$latest = null;
|
||||
foreach ($followups as $fu) {
|
||||
if ($latest === null || $fu->getDate() > $latest->getDate()) {
|
||||
$latest = $fu;
|
||||
}
|
||||
}
|
||||
if ($latest && $latest->getDate() < (new \DateTime('-1 day'))) {
|
||||
$refresh = true;
|
||||
}
|
||||
} else {
|
||||
$refresh = true;
|
||||
}
|
||||
if ($refresh) {
|
||||
$this->followUpService->generateCityFollowUps($stats, $motocultrice, $em);
|
||||
$followups = $stats->getCityFollowUps();
|
||||
}
|
||||
|
@ -148,4 +162,56 @@ class FollowUpController extends AbstractController
|
|||
'followup_overpass' => FollowUpService::getFollowUpOverpassQueries(),
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/admin/followup/{insee_code}/embed/{theme}', name: 'admin_followup_embed_graph', requirements: ['insee_code' => '\\d+', 'theme' => '[a-zA-Z0-9_]+'])]
|
||||
public function followupEmbedGraph(
|
||||
string $insee_code,
|
||||
string $theme,
|
||||
EntityManagerInterface $em,
|
||||
Motocultrice $motocultrice
|
||||
) {
|
||||
$stats = $em->getRepository(Stats::class)->findOneBy(['zone' => $insee_code]);
|
||||
if (!$stats) {
|
||||
$this->addFlash('error', 'Aucune stats trouvée pour ce code INSEE.');
|
||||
return $this->redirectToRoute('app_admin');
|
||||
}
|
||||
$followups = $stats->getCityFollowUps();
|
||||
$refresh = false;
|
||||
if (!$followups->isEmpty()) {
|
||||
$latest = null;
|
||||
foreach ($followups as $fu) {
|
||||
if ($latest === null || $fu->getDate() > $latest->getDate()) {
|
||||
$latest = $fu;
|
||||
}
|
||||
}
|
||||
if ($latest && $latest->getDate() < (new \DateTime('-1 day'))) {
|
||||
$refresh = true;
|
||||
}
|
||||
} else {
|
||||
$refresh = true;
|
||||
}
|
||||
if ($refresh) {
|
||||
$this->followUpService->generateCityFollowUps($stats, $motocultrice, $em);
|
||||
$followups = $stats->getCityFollowUps();
|
||||
}
|
||||
$followups = $followups->toArray();
|
||||
usort($followups, fn($a, $b) => $a->getDate() <=> $b->getDate());
|
||||
$series = [];
|
||||
foreach ($followups as $fu) {
|
||||
if (str_starts_with($fu->getName(), $theme)) {
|
||||
$series[$fu->getName()][] = [
|
||||
'date' => $fu->getDate()->format('c'),
|
||||
'value' => $fu->getMeasure(),
|
||||
'name' => $fu->getName(),
|
||||
];
|
||||
}
|
||||
}
|
||||
return $this->render('admin/followup_embed_graph.html.twig', [
|
||||
'stats' => $stats,
|
||||
'series' => $series,
|
||||
'theme' => $theme,
|
||||
'label' => FollowUpService::getFollowUpThemes()[$theme] ?? $theme,
|
||||
'icon' => FollowUpService::getFollowUpIcons()[$theme] ?? 'bi-question-circle',
|
||||
]);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue