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

@ -54,7 +54,7 @@ class Stats
#[ORM\Column(type: Types::INTEGER, nullable: true)]
private ?int $avec_note = null;
#[ORM\Column(length: 255, nullable: true, options: ['charset' => 'utf8mb4'] )]
#[ORM\Column(length: 255, nullable: true, options: ['charset' => 'utf8mb4'])]
private ?string $name = null;
// nombre d'habitants dans la zone
@ -118,6 +118,15 @@ class Stats
#[ORM\Column(type: 'datetime', nullable: true)]
private ?\DateTime $date_labourage_done = null;
/**
* Defines the source of the stat creation:
* - 'request': created from a request of the object Demande
* - 'command': created from a Symfony command
* - 'user': created by a user using the route to add their city
*/
#[ORM\Column(length: 20, nullable: true)]
private ?string $kind = 'command';
public function getCTCurlBase(): ?string
{
$base = 'https://complete-tes-commerces.fr/';
@ -126,7 +135,7 @@ class Stats
$departement = substr($zone, 0, 2);
$insee_code = $zone;
$slug = strtolower(str_replace(' ', '-', $this->getName()));
$url = $base . $departement . '/' . $insee_code . '-'.$slug.'/json/' . $slug ;
$url = $base . $departement . '/' . $insee_code . '-' . $slug . '/json/' . $slug;
return $url;
}
@ -140,7 +149,7 @@ class Stats
{
return $this->getParametricJsonFromCTC('_dailystats');
}
public function getOSMClosedSirets(): string
{
return $this->getParametricJsonFromCTC('_osm_closed_siret');
@ -171,15 +180,14 @@ class Stats
return $this->getParametricJsonFromCTC('_sirene_matches');
}
public function getParametricJsonFromCTC($suffixe): string
{
$url = $this->getCTCurlBase().$suffixe.'.json';
$url = $this->getCTCurlBase() . $suffixe . '.json';
return $url;
}
public function getAllCTCUrlsMap(): ?array
{
@ -197,7 +205,7 @@ class Stats
}
return $urls;
}
// calcule le pourcentage de complétion de la zone
public function computeCompletionPercent(): ?int
@ -218,9 +226,9 @@ class Stats
$this->avec_note = 0;
$this->avec_siret = 0;
$this->avec_name = 0;
$somme_completions = 0;
// On boucle sur chaque place pour compter les attributs renseignés
foreach ($this->places as $place) {
@ -230,7 +238,7 @@ class Stats
$place_completions++;
}
if ($place->hasWebsite()) {
$this->avec_site++;
$this->avec_site++;
$place_completions++;
}
if ($place->hasWheelchair()) {
@ -241,19 +249,19 @@ class Stats
$this->avec_horaires++;
$place_completions++;
}
if($place->getSiret()) {
if ($place->getSiret()) {
$this->avec_siret++;
$place_completions++;
}
if($place->getName()) {
if ($place->getName()) {
$this->avec_name++;
$place_completions++;
}
if($place->getNoteContent()) {
if ($place->getNoteContent()) {
$this->avec_note++;
// on ne compte pas les notes comme indice de complétion
}
$somme_completions += $place_completions / 6;
}
@ -263,9 +271,9 @@ class Stats
}
public function __construct()
{
$this->setKind('command');
$this->places = new ArrayCollection();
$this->statsHistories = new ArrayCollection();
$this->cityFollowUps = new ArrayCollection();
@ -365,7 +373,7 @@ class Stats
return $this;
}
public function getAvecSite(): ?int
{
return $this->avec_site;
@ -377,7 +385,7 @@ class Stats
return $this;
}
public function getAvecAccessibilite(): ?int
{
return $this->avec_accessibilite;
@ -635,24 +643,37 @@ class Stats
$this->lon = $lon;
return $this;
}
public function getDateLabourageRequested(): ?\DateTime
{
return $this->date_labourage_requested;
}
public function setDateLabourageRequested(?\DateTime $date): static
{
$this->date_labourage_requested = $date;
return $this;
}
public function getDateLabourageDone(): ?\DateTime
{
return $this->date_labourage_done;
}
public function setDateLabourageDone(?\DateTime $date): static
{
$this->date_labourage_done = $date;
return $this;
}
}
public function getKind(): ?string
{
return $this->kind;
}
public function setKind(?string $kind): static
{
$this->kind = $kind;
return $this;
}
}