up infos habitants sur stats

This commit is contained in:
Tykayn 2025-06-17 16:23:29 +02:00 committed by tykayn
parent 21d4d5b850
commit 918527e15e
16 changed files with 559 additions and 240 deletions

View file

@ -131,10 +131,8 @@ final class AdminController extends AbstractController
// Récupérer ou créer les stats pour cette zone
$stats = $this->entityManager->getRepository(Stats::class)->findOneBy(['zone' => $zip_code]);
$city = $this->motocultrice->get_city_osm_from_zip_code($zip_code);
if (!$stats) {
$stats = new Stats();
$stats->setZone($zip_code)
->setPlacesCount(0)
@ -144,11 +142,27 @@ final class AdminController extends AbstractController
->setAvecAccessibilite(0)
->setAvecNote(0)
->setCompletionPercent(0);
$this->entityManager->persist($stats);
$this->entityManager->flush();
}
$this->entityManager->persist($stats);
$this->entityManager->flush();
}
$stats->setName($city);
// Récupérer la population via l'API
$population = null;
try {
$apiUrl = 'https://geo.api.gouv.fr/communes/' . $zip_code . '?fields=population';
$response = file_get_contents($apiUrl);
if ($response !== false) {
$data = json_decode($response, true);
if (isset($data['population'])) {
$population = (int)$data['population'];
$stats->setPopulation($population);
}
}
} catch (\Exception $e) {
// Ne rien faire si l'API échoue
}
// Récupérer toutes les données
$places = $this->motocultrice->labourer($zip_code);
$processedCount = 0;

View file

@ -100,6 +100,9 @@ class Place
#[ORM\Column(length: 255, nullable: true)]
private ?string $siret = null;
#[ORM\Column(nullable: true)]
private ?int $habitants = null;
public function getMainTag(): ?string
{
return $this->main_tag;
@ -579,4 +582,16 @@ class Place
return $this;
}
public function getHabitants(): ?int
{
return $this->habitants;
}
public function setHabitants(?int $habitants): static
{
$this->habitants = $habitants;
return $this;
}
}

View file

@ -55,6 +55,10 @@ class Stats
#[ORM\Column(length: 255, nullable: true)]
private ?string $name = null;
// nombre d'habitants dans la zone
#[ORM\Column(type: Types::INTEGER, nullable: true)]
private ?int $population = null;
// calcule le pourcentage de complétion de la zone
public function computeCompletionPercent(): ?int
{
@ -255,6 +259,17 @@ class Stats
return $this;
}
public function getPopulation(): ?int
{
return $this->population;
}
public function setPopulation(?int $population): static
{
$this->population = $population;
return $this;
}
}