commande pour créer des stats de toutes les villes insee

# Conflicts:
#	src/Command/ProcessLabourageQueueCommand.php
#	src/Controller/PublicController.php
This commit is contained in:
Tykayn 2025-08-08 18:09:24 +02:00 committed by tykayn
parent dfeaf123f4
commit 8cfea30fdf
6 changed files with 475 additions and 44 deletions

View file

@ -2,16 +2,16 @@
namespace App\Command;
use App\Entity\Stats;
use App\Entity\Place;
use App\Entity\Stats;
use App\Service\FollowUpService;
use App\Service\Motocultrice;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use App\Service\Motocultrice;
use App\Service\FollowUpService;
#[AsCommand(
name: 'app:process-labourage-queue',
@ -21,9 +21,10 @@ class ProcessLabourageQueueCommand extends Command
{
public function __construct(
private EntityManagerInterface $entityManager,
private Motocultrice $motocultrice,
private FollowUpService $followUpService
) {
private Motocultrice $motocultrice,
private FollowUpService $followUpService
)
{
parent::__construct();
}
@ -142,26 +143,36 @@ class ProcessLabourageQueueCommand extends Command
}
}
$stats->setDateLabourageDone(new \DateTime());
// Update city name from API if available
$apiCityName = $this->motocultrice->get_city_osm_from_zip_code($stats->getZone());
if ($apiCityName && $apiCityName !== $stats->getName()) {
$io->info(sprintf('Updating city name from "%s" to "%s" based on API data', $stats->getName(), $apiCityName));
$stats->setName($apiCityName);
}
$io->info('Récupération des followups de cette ville...');
// $this->followUpService->generateCityFollowUps($stats, $this->motocultrice, $this->entityManager);
// update completion
$stats->computeCompletionPercent();
$followups = $stats->getCityFollowUps();
if ($followups) {
$lastFollowUp = $followups[count($followups) - 1];
if ($lastFollowUp) {
$name = $lastFollowUp->getName();
$io->success("Followup le plus récent : $name : " . $lastFollowUp->getDate()->format('d/m/Y') . ' : ' . $lastFollowUp->getMeasure());
}
}
$io->info('Pourcentage de complétion: ' . $stats->getCompletionPercent());
$this->entityManager->persist($stats);
$this->entityManager->flush();
$io->success("Labourage terminé : $processedCount nouveaux lieux, $updatedCount lieux mis à jour.");
return Command::SUCCESS;
}