mirror of
https://forge.chapril.org/tykayn/osm-commerces
synced 2025-10-04 17:04:53 +02:00
ajout de followup sur plusieurs thèmes
This commit is contained in:
parent
ab1b9a9d3d
commit
0cdb2f9ae9
6 changed files with 501 additions and 120 deletions
35
migrations/Version20250629142706.php
Normal file
35
migrations/Version20250629142706.php
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace DoctrineMigrations;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-generated Migration: Please modify to your needs!
|
||||||
|
*/
|
||||||
|
final class Version20250629142706 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
// this up() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
ALTER TABLE place CHANGE email email VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_0900_ai_ci`, CHANGE note note VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_0900_ai_ci`, CHANGE name name VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_0900_ai_ci`, CHANGE note_content note_content VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_0900_ai_ci`, CHANGE street street VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_0900_ai_ci`, CHANGE housenumber housenumber VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_0900_ai_ci`, CHANGE siret siret VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_0900_ai_ci`, CHANGE osm_user osm_user VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_0900_ai_ci`, CHANGE email_content email_content LONGTEXT CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_0900_ai_ci`
|
||||||
|
SQL);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
// this down() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
ALTER TABLE place CHANGE email email VARCHAR(255) DEFAULT NULL, CHANGE note note VARCHAR(255) DEFAULT NULL, CHANGE name name VARCHAR(255) DEFAULT NULL, CHANGE note_content note_content VARCHAR(255) DEFAULT NULL, CHANGE street street VARCHAR(255) DEFAULT NULL, CHANGE housenumber housenumber VARCHAR(255) DEFAULT NULL, CHANGE siret siret VARCHAR(255) DEFAULT NULL, CHANGE osm_user osm_user VARCHAR(255) DEFAULT NULL, CHANGE email_content email_content LONGTEXT DEFAULT NULL
|
||||||
|
SQL);
|
||||||
|
}
|
||||||
|
}
|
|
@ -374,6 +374,49 @@ final class AdminController extends AbstractController
|
||||||
return ($b['completion_pondere_normalisee'] ?? 0) <=> ($a['completion_pondere_normalisee'] ?? 0);
|
return ($b['completion_pondere_normalisee'] ?? 0) <=> ($a['completion_pondere_normalisee'] ?? 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Récupérer les derniers followups pour chaque type
|
||||||
|
$latestFollowups = [];
|
||||||
|
$types = [
|
||||||
|
'fire_hydrant', 'charging_station', 'toilets', 'bus_stop', 'defibrillator', 'camera', 'recycling', 'substation', 'places'
|
||||||
|
];
|
||||||
|
foreach ($types as $type) {
|
||||||
|
$count = null;
|
||||||
|
$completion = null;
|
||||||
|
foreach ($stats->getCityFollowUps() as $fu) {
|
||||||
|
if ($fu->getName() === $type . '_count') {
|
||||||
|
if ($count === null || $fu->getDate() > $count->getDate()) {
|
||||||
|
$count = $fu;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($fu->getName() === $type . '_completion') {
|
||||||
|
if ($completion === null || $fu->getDate() > $completion->getDate()) {
|
||||||
|
$completion = $fu;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$latestFollowups[$type] = [];
|
||||||
|
if ($count) $latestFollowups[$type]['count'] = $count;
|
||||||
|
if ($completion) $latestFollowups[$type]['completion'] = $completion;
|
||||||
|
}
|
||||||
|
// Pour les lieux (places_count et places_completion)
|
||||||
|
$count = null;
|
||||||
|
$completion = null;
|
||||||
|
foreach ($stats->getCityFollowUps() as $fu) {
|
||||||
|
if ($fu->getName() === 'places_count') {
|
||||||
|
if ($count === null || $fu->getDate() > $count->getDate()) {
|
||||||
|
$count = $fu;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($fu->getName() === 'places_completion') {
|
||||||
|
if ($completion === null || $fu->getDate() > $completion->getDate()) {
|
||||||
|
$completion = $fu;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$latestFollowups['places'] = [];
|
||||||
|
if ($count) $latestFollowups['places']['count'] = $count;
|
||||||
|
if ($completion) $latestFollowups['places']['completion'] = $completion;
|
||||||
|
|
||||||
return $this->render('admin/stats.html.twig', [
|
return $this->render('admin/stats.html.twig', [
|
||||||
'stats' => $stats,
|
'stats' => $stats,
|
||||||
'commerces' => $commerces,
|
'commerces' => $commerces,
|
||||||
|
@ -384,7 +427,8 @@ final class AdminController extends AbstractController
|
||||||
'statsHistory' => $statsHistory,
|
'statsHistory' => $statsHistory,
|
||||||
'CTC_urls' => $urls,
|
'CTC_urls' => $urls,
|
||||||
'overpass' => '',
|
'overpass' => '',
|
||||||
'podium_local' => $podium_local
|
'podium_local' => $podium_local,
|
||||||
|
'latestFollowups' => $latestFollowups
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,22 @@ use Symfony\Component\Routing\Annotation\Route;
|
||||||
|
|
||||||
class FollowUpController extends AbstractController
|
class FollowUpController extends AbstractController
|
||||||
{
|
{
|
||||||
|
#[Route('/admin/followup/{insee_code}/delete', name: 'admin_followup_delete')]
|
||||||
|
public function deleteFollowups(string $insee_code, EntityManagerInterface $em): Response {
|
||||||
|
$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();
|
||||||
|
foreach ($followups as $fu) {
|
||||||
|
$em->remove($fu);
|
||||||
|
}
|
||||||
|
$em->flush();
|
||||||
|
$this->addFlash('success', 'Tous les suivis ont été supprimés pour cette ville.');
|
||||||
|
return $this->redirectToRoute('admin_followup_graph', ['insee_code' => $insee_code]);
|
||||||
|
}
|
||||||
|
|
||||||
#[Route('/admin/followup/{insee_code}', name: 'admin_followup')]
|
#[Route('/admin/followup/{insee_code}', name: 'admin_followup')]
|
||||||
public function followup(
|
public function followup(
|
||||||
string $insee_code,
|
string $insee_code,
|
||||||
|
@ -25,26 +41,52 @@ class FollowUpController extends AbstractController
|
||||||
$this->addFlash('error', 'Aucune stats trouvée pour ce code INSEE.');
|
$this->addFlash('error', 'Aucune stats trouvée pour ce code INSEE.');
|
||||||
return $this->redirectToRoute('app_admin');
|
return $this->redirectToRoute('app_admin');
|
||||||
}
|
}
|
||||||
|
// Ne plus supprimer les anciens suivis !
|
||||||
|
// $followups = $stats->getCityFollowUps();
|
||||||
|
// foreach ($followups as $fu) {
|
||||||
|
// $em->remove($fu);
|
||||||
|
// }
|
||||||
|
// $em->flush();
|
||||||
|
|
||||||
// Récupérer les objets OSM
|
// Récupérer les objets OSM
|
||||||
$elements = $motocultrice->followUpCity($insee_code);
|
$elements = $motocultrice->followUpCity($insee_code);
|
||||||
|
|
||||||
// Séparer les objets par type
|
// Séparer les objets par type
|
||||||
$fire_hydrants = array_filter($elements, fn($el) => ($el['tags']['emergency'] ?? null) === 'fire_hydrant');
|
|
||||||
$charging_stations = array_filter($elements, fn($el) => ($el['tags']['amenity'] ?? null) === 'charging_station');
|
|
||||||
|
|
||||||
// --- Suivi du nombre d'objets ---
|
|
||||||
$now = new \DateTime();
|
|
||||||
$types = [
|
$types = [
|
||||||
'fire_hydrant' => [
|
'fire_hydrant' => [
|
||||||
'label' => 'Bornes incendie',
|
'label' => 'Bornes incendie',
|
||||||
'objects' => $fire_hydrants
|
'objects' => array_filter($elements, fn($el) => ($el['tags']['emergency'] ?? null) === 'fire_hydrant')
|
||||||
],
|
],
|
||||||
'charging_station' => [
|
'charging_station' => [
|
||||||
'label' => 'Bornes de recharge',
|
'label' => 'Bornes de recharge',
|
||||||
'objects' => $charging_stations
|
'objects' => array_filter($elements, fn($el) => ($el['tags']['amenity'] ?? null) === 'charging_station')
|
||||||
]
|
],
|
||||||
|
'toilets' => [
|
||||||
|
'label' => 'Toilettes publiques',
|
||||||
|
'objects' => array_filter($elements, fn($el) => ($el['tags']['amenity'] ?? null) === 'toilets')
|
||||||
|
],
|
||||||
|
'bus_stop' => [
|
||||||
|
'label' => 'Arrêts de bus',
|
||||||
|
'objects' => array_filter($elements, fn($el) => ($el['tags']['highway'] ?? null) === 'bus_stop')
|
||||||
|
],
|
||||||
|
'defibrillator' => [
|
||||||
|
'label' => 'Défibrillateurs',
|
||||||
|
'objects' => array_filter($elements, fn($el) => ($el['tags']['emergency'] ?? null) === 'defibrillator')
|
||||||
|
],
|
||||||
|
'camera' => [
|
||||||
|
'label' => 'Caméras de surveillance',
|
||||||
|
'objects' => array_filter($elements, fn($el) => ($el['tags']['man_made'] ?? null) === 'surveillance')
|
||||||
|
],
|
||||||
|
'recycling' => [
|
||||||
|
'label' => 'Points de recyclage',
|
||||||
|
'objects' => array_filter($elements, fn($el) => ($el['tags']['amenity'] ?? null) === 'recycling')
|
||||||
|
],
|
||||||
|
'substation' => [
|
||||||
|
'label' => 'Sous-stations électriques',
|
||||||
|
'objects' => array_filter($elements, fn($el) => ($el['tags']['power'] ?? null) === 'substation')
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
$now = new \DateTime();
|
||||||
foreach ($types as $type => $data) {
|
foreach ($types as $type => $data) {
|
||||||
// Suivi du nombre
|
// Suivi du nombre
|
||||||
$followupCount = new CityFollowUp();
|
$followupCount = new CityFollowUp();
|
||||||
|
@ -54,7 +96,8 @@ class FollowUpController extends AbstractController
|
||||||
->setStats($stats);
|
->setStats($stats);
|
||||||
$em->persist($followupCount);
|
$em->persist($followupCount);
|
||||||
|
|
||||||
// Suivi de la complétion personnalisé
|
// Suivi de la complétion personnalisé (exemples)
|
||||||
|
$completed = [];
|
||||||
if ($type === 'fire_hydrant') {
|
if ($type === 'fire_hydrant') {
|
||||||
$completed = array_filter($data['objects'], function($el) {
|
$completed = array_filter($data['objects'], function($el) {
|
||||||
return !empty($el['tags']['ref'] ?? null);
|
return !empty($el['tags']['ref'] ?? null);
|
||||||
|
@ -63,8 +106,30 @@ class FollowUpController extends AbstractController
|
||||||
$completed = array_filter($data['objects'], function($el) {
|
$completed = array_filter($data['objects'], function($el) {
|
||||||
return !empty($el['tags']['charging_station:output'] ?? null) && !empty($el['tags']['capacity'] ?? null);
|
return !empty($el['tags']['charging_station:output'] ?? null) && !empty($el['tags']['capacity'] ?? null);
|
||||||
});
|
});
|
||||||
} else {
|
} elseif ($type === 'toilets') {
|
||||||
$completed = [];
|
$completed = array_filter($data['objects'], function($el) {
|
||||||
|
return ($el['tags']['wheelchair'] ?? null) === 'yes';
|
||||||
|
});
|
||||||
|
} elseif ($type === 'bus_stop') {
|
||||||
|
$completed = array_filter($data['objects'], function($el) {
|
||||||
|
return !empty($el['tags']['shelter'] ?? null);
|
||||||
|
});
|
||||||
|
} elseif ($type === 'defibrillator') {
|
||||||
|
$completed = array_filter($data['objects'], function($el) {
|
||||||
|
return !empty($el['tags']['indoor'] ?? null);
|
||||||
|
});
|
||||||
|
} elseif ($type === 'camera') {
|
||||||
|
$completed = array_filter($data['objects'], function($el) {
|
||||||
|
return !empty($el['tags']['surveillance:type'] ?? null);
|
||||||
|
});
|
||||||
|
} elseif ($type === 'recycling') {
|
||||||
|
$completed = array_filter($data['objects'], function($el) {
|
||||||
|
return !empty($el['tags']['recycling_type'] ?? null);
|
||||||
|
});
|
||||||
|
} elseif ($type === 'substation') {
|
||||||
|
$completed = array_filter($data['objects'], function($el) {
|
||||||
|
return !empty($el['tags']['substation'] ?? null);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
$completion = count($data['objects']) > 0 ? round(count($completed) / count($data['objects']) * 100) : 0;
|
$completion = count($data['objects']) > 0 ? round(count($completed) / count($data['objects']) * 100) : 0;
|
||||||
$followupCompletion = new CityFollowUp();
|
$followupCompletion = new CityFollowUp();
|
||||||
|
@ -83,14 +148,109 @@ class FollowUpController extends AbstractController
|
||||||
#[Route('/admin/followup/{insee_code}/graph', name: 'admin_followup_graph')]
|
#[Route('/admin/followup/{insee_code}/graph', name: 'admin_followup_graph')]
|
||||||
public function followupGraph(
|
public function followupGraph(
|
||||||
string $insee_code,
|
string $insee_code,
|
||||||
EntityManagerInterface $em
|
EntityManagerInterface $em,
|
||||||
): Response {
|
Motocultrice $motocultrice
|
||||||
|
) {
|
||||||
$stats = $em->getRepository(Stats::class)->findOneBy(['zone' => $insee_code]);
|
$stats = $em->getRepository(Stats::class)->findOneBy(['zone' => $insee_code]);
|
||||||
if (!$stats) {
|
if (!$stats) {
|
||||||
$this->addFlash('error', 'Aucune stats trouvée pour ce code INSEE.');
|
$this->addFlash('error', 'Aucune stats trouvée pour ce code INSEE.');
|
||||||
return $this->redirectToRoute('app_admin');
|
return $this->redirectToRoute('app_admin');
|
||||||
}
|
}
|
||||||
$followups = $stats->getCityFollowUps();
|
$followups = $stats->getCityFollowUps();
|
||||||
|
if ($followups->isEmpty()) {
|
||||||
|
// Générer les followup comme dans l'action followup
|
||||||
|
// (ne pas supprimer les anciens, car il n'y en a pas)
|
||||||
|
$elements = $motocultrice->followUpCity($insee_code);
|
||||||
|
// Séparer les objets par type
|
||||||
|
$types = [
|
||||||
|
'fire_hydrant' => [
|
||||||
|
'label' => 'Bornes incendie',
|
||||||
|
'objects' => array_filter($elements, fn($el) => ($el['tags']['emergency'] ?? null) === 'fire_hydrant')
|
||||||
|
],
|
||||||
|
'charging_station' => [
|
||||||
|
'label' => 'Bornes de recharge',
|
||||||
|
'objects' => array_filter($elements, fn($el) => ($el['tags']['amenity'] ?? null) === 'charging_station')
|
||||||
|
],
|
||||||
|
'toilets' => [
|
||||||
|
'label' => 'Toilettes publiques',
|
||||||
|
'objects' => array_filter($elements, fn($el) => ($el['tags']['amenity'] ?? null) === 'toilets')
|
||||||
|
],
|
||||||
|
'bus_stop' => [
|
||||||
|
'label' => 'Arrêts de bus',
|
||||||
|
'objects' => array_filter($elements, fn($el) => ($el['tags']['highway'] ?? null) === 'bus_stop')
|
||||||
|
],
|
||||||
|
'defibrillator' => [
|
||||||
|
'label' => 'Défibrillateurs',
|
||||||
|
'objects' => array_filter($elements, fn($el) => ($el['tags']['emergency'] ?? null) === 'defibrillator')
|
||||||
|
],
|
||||||
|
'camera' => [
|
||||||
|
'label' => 'Caméras de surveillance',
|
||||||
|
'objects' => array_filter($elements, fn($el) => ($el['tags']['man_made'] ?? null) === 'surveillance')
|
||||||
|
],
|
||||||
|
'recycling' => [
|
||||||
|
'label' => 'Points de recyclage',
|
||||||
|
'objects' => array_filter($elements, fn($el) => ($el['tags']['amenity'] ?? null) === 'recycling')
|
||||||
|
],
|
||||||
|
'substation' => [
|
||||||
|
'label' => 'Sous-stations électriques',
|
||||||
|
'objects' => array_filter($elements, fn($el) => ($el['tags']['power'] ?? null) === 'substation')
|
||||||
|
],
|
||||||
|
];
|
||||||
|
$now = new \DateTime();
|
||||||
|
foreach ($types as $type => $data) {
|
||||||
|
// Suivi du nombre
|
||||||
|
$followupCount = new CityFollowUp();
|
||||||
|
$followupCount->setName($type . '_count')
|
||||||
|
->setMeasure(count($data['objects']))
|
||||||
|
->setDate($now)
|
||||||
|
->setStats($stats);
|
||||||
|
$em->persist($followupCount);
|
||||||
|
// Suivi de la complétion personnalisé (exemples)
|
||||||
|
$completed = [];
|
||||||
|
if ($type === 'fire_hydrant') {
|
||||||
|
$completed = array_filter($data['objects'], function($el) {
|
||||||
|
return !empty($el['tags']['ref'] ?? null);
|
||||||
|
});
|
||||||
|
} elseif ($type === 'charging_station') {
|
||||||
|
$completed = array_filter($data['objects'], function($el) {
|
||||||
|
return !empty($el['tags']['charging_station:output'] ?? null) && !empty($el['tags']['capacity'] ?? null);
|
||||||
|
});
|
||||||
|
} elseif ($type === 'toilets') {
|
||||||
|
$completed = array_filter($data['objects'], function($el) {
|
||||||
|
return ($el['tags']['wheelchair'] ?? null) === 'yes';
|
||||||
|
});
|
||||||
|
} elseif ($type === 'bus_stop') {
|
||||||
|
$completed = array_filter($data['objects'], function($el) {
|
||||||
|
return !empty($el['tags']['shelter'] ?? null);
|
||||||
|
});
|
||||||
|
$completed = array_filter($data['objects'], function($el) {
|
||||||
|
return !empty($el['tags']['indoor'] ?? null);
|
||||||
|
});
|
||||||
|
} elseif ($type === 'camera') {
|
||||||
|
$completed = array_filter($data['objects'], function($el) {
|
||||||
|
return !empty($el['tags']['surveillance:type'] ?? null);
|
||||||
|
});
|
||||||
|
} elseif ($type === 'recycling') {
|
||||||
|
$completed = array_filter($data['objects'], function($el) {
|
||||||
|
return !empty($el['tags']['recycling_type'] ?? null);
|
||||||
|
});
|
||||||
|
} elseif ($type === 'substation') {
|
||||||
|
$completed = array_filter($data['objects'], function($el) {
|
||||||
|
return !empty($el['tags']['substation'] ?? null);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
$completion = count($data['objects']) > 0 ? round(count($completed) / count($data['objects']) * 100) : 0;
|
||||||
|
$followupCompletion = new CityFollowUp();
|
||||||
|
$followupCompletion->setName($type . '_completion')
|
||||||
|
->setMeasure($completion)
|
||||||
|
->setDate($now)
|
||||||
|
->setStats($stats);
|
||||||
|
$em->persist($followupCompletion);
|
||||||
|
}
|
||||||
|
$em->flush();
|
||||||
|
// Recharger les followups
|
||||||
|
$followups = $stats->getCityFollowUps();
|
||||||
|
}
|
||||||
$followups = $followups->toArray();
|
$followups = $followups->toArray();
|
||||||
usort($followups, fn($a, $b) => $a->getDate() <=> $b->getDate());
|
usort($followups, fn($a, $b) => $a->getDate() <=> $b->getDate());
|
||||||
// Grouper par type
|
// Grouper par type
|
||||||
|
@ -107,4 +267,123 @@ class FollowUpController extends AbstractController
|
||||||
'series' => $series
|
'series' => $series
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Route('/admin/followup/all', name: 'admin_followup_all')]
|
||||||
|
public function followupAll(
|
||||||
|
EntityManagerInterface $em,
|
||||||
|
Motocultrice $motocultrice
|
||||||
|
) {
|
||||||
|
$statsList = $em->getRepository(Stats::class)->findAll();
|
||||||
|
$now = new \DateTime();
|
||||||
|
foreach ($statsList as $stats) {
|
||||||
|
// Ne plus supprimer les anciens suivis !
|
||||||
|
// foreach ($stats->getCityFollowUps() as $fu) {
|
||||||
|
// $em->remove($fu);
|
||||||
|
// }
|
||||||
|
// Générer les followups OSM
|
||||||
|
$insee_code = $stats->getZone();
|
||||||
|
$elements = $motocultrice->followUpCity($insee_code);
|
||||||
|
$types = [
|
||||||
|
'fire_hydrant' => [
|
||||||
|
'label' => 'Bornes incendie',
|
||||||
|
'objects' => array_filter($elements, fn($el) => ($el['tags']['emergency'] ?? null) === 'fire_hydrant')
|
||||||
|
],
|
||||||
|
'charging_station' => [
|
||||||
|
'label' => 'Bornes de recharge',
|
||||||
|
'objects' => array_filter($elements, fn($el) => ($el['tags']['amenity'] ?? null) === 'charging_station')
|
||||||
|
],
|
||||||
|
'toilets' => [
|
||||||
|
'label' => 'Toilettes publiques',
|
||||||
|
'objects' => array_filter($elements, fn($el) => ($el['tags']['amenity'] ?? null) === 'toilets')
|
||||||
|
],
|
||||||
|
'bus_stop' => [
|
||||||
|
'label' => 'Arrêts de bus',
|
||||||
|
'objects' => array_filter($elements, fn($el) => ($el['tags']['highway'] ?? null) === 'bus_stop')
|
||||||
|
],
|
||||||
|
'defibrillator' => [
|
||||||
|
'label' => 'Défibrillateurs',
|
||||||
|
'objects' => array_filter($elements, fn($el) => ($el['tags']['emergency'] ?? null) === 'defibrillator')
|
||||||
|
],
|
||||||
|
'camera' => [
|
||||||
|
'label' => 'Caméras de surveillance',
|
||||||
|
'objects' => array_filter($elements, fn($el) => ($el['tags']['man_made'] ?? null) === 'surveillance')
|
||||||
|
],
|
||||||
|
'recycling' => [
|
||||||
|
'label' => 'Points de recyclage',
|
||||||
|
'objects' => array_filter($elements, fn($el) => ($el['tags']['amenity'] ?? null) === 'recycling')
|
||||||
|
],
|
||||||
|
'substation' => [
|
||||||
|
'label' => 'Sous-stations électriques',
|
||||||
|
'objects' => array_filter($elements, fn($el) => ($el['tags']['power'] ?? null) === 'substation')
|
||||||
|
],
|
||||||
|
];
|
||||||
|
foreach ($types as $type => $data) {
|
||||||
|
// Suivi du nombre
|
||||||
|
$followupCount = new CityFollowUp();
|
||||||
|
$followupCount->setName($type . '_count')
|
||||||
|
->setMeasure(count($data['objects']))
|
||||||
|
->setDate($now)
|
||||||
|
->setStats($stats);
|
||||||
|
$em->persist($followupCount);
|
||||||
|
// Suivi de la complétion personnalisé (exemples)
|
||||||
|
$completed = [];
|
||||||
|
if ($type === 'fire_hydrant') {
|
||||||
|
$completed = array_filter($data['objects'], function($el) {
|
||||||
|
return !empty($el['tags']['ref'] ?? null);
|
||||||
|
});
|
||||||
|
} elseif ($type === 'charging_station') {
|
||||||
|
$completed = array_filter($data['objects'], function($el) {
|
||||||
|
return !empty($el['tags']['charging_station:output'] ?? null) && !empty($el['tags']['capacity'] ?? null);
|
||||||
|
});
|
||||||
|
} elseif ($type === 'toilets') {
|
||||||
|
$completed = array_filter($data['objects'], function($el) {
|
||||||
|
return ($el['tags']['wheelchair'] ?? null) === 'yes';
|
||||||
|
});
|
||||||
|
} elseif ($type === 'bus_stop') {
|
||||||
|
$completed = array_filter($data['objects'], function($el) {
|
||||||
|
return !empty($el['tags']['shelter'] ?? null);
|
||||||
|
});
|
||||||
|
$completed = array_filter($data['objects'], function($el) {
|
||||||
|
return !empty($el['tags']['indoor'] ?? null);
|
||||||
|
});
|
||||||
|
} elseif ($type === 'camera') {
|
||||||
|
$completed = array_filter($data['objects'], function($el) {
|
||||||
|
return !empty($el['tags']['surveillance:type'] ?? null);
|
||||||
|
});
|
||||||
|
} elseif ($type === 'recycling') {
|
||||||
|
$completed = array_filter($data['objects'], function($el) {
|
||||||
|
return !empty($el['tags']['recycling_type'] ?? null);
|
||||||
|
});
|
||||||
|
} elseif ($type === 'substation') {
|
||||||
|
$completed = array_filter($data['objects'], function($el) {
|
||||||
|
return !empty($el['tags']['substation'] ?? null);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
$completion = count($data['objects']) > 0 ? round(count($completed) / count($data['objects']) * 100) : 0;
|
||||||
|
$followupCompletion = new CityFollowUp();
|
||||||
|
$followupCompletion->setName($type . '_completion')
|
||||||
|
->setMeasure($completion)
|
||||||
|
->setDate($now)
|
||||||
|
->setStats($stats);
|
||||||
|
$em->persist($followupCompletion);
|
||||||
|
}
|
||||||
|
// Ajout du suivi sur le nombre de Places
|
||||||
|
$followupPlaces = new CityFollowUp();
|
||||||
|
$followupPlaces->setName('places_count')
|
||||||
|
->setMeasure($stats->getPlacesCount() ?? 0)
|
||||||
|
->setDate($now)
|
||||||
|
->setStats($stats);
|
||||||
|
$em->persist($followupPlaces);
|
||||||
|
// Ajout du suivi sur la complétion moyenne
|
||||||
|
$followupCompletion = new CityFollowUp();
|
||||||
|
$followupCompletion->setName('places_completion')
|
||||||
|
->setMeasure($stats->getCompletionPercent() ?? 0)
|
||||||
|
->setDate($now)
|
||||||
|
->setStats($stats);
|
||||||
|
$em->persist($followupCompletion);
|
||||||
|
}
|
||||||
|
$em->flush();
|
||||||
|
$this->addFlash('success', 'Suivi généré pour toutes les villes.');
|
||||||
|
return $this->redirectToRoute('app_admin');
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -558,7 +558,7 @@ out meta;';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Génère la requête Overpass pour les bornes incendie et bornes de recharge
|
* Génère la requête Overpass pour tous les objets de suivi (thématiques étendues)
|
||||||
*/
|
*/
|
||||||
public function get_followup_query($zone) {
|
public function get_followup_query($zone) {
|
||||||
return <<<QUERY
|
return <<<QUERY
|
||||||
|
@ -567,6 +567,12 @@ area["ref:INSEE"="$zone"]->.searchArea;
|
||||||
(
|
(
|
||||||
nwr["emergency"="fire_hydrant"](area.searchArea);
|
nwr["emergency"="fire_hydrant"](area.searchArea);
|
||||||
nwr["amenity"="charging_station"](area.searchArea);
|
nwr["amenity"="charging_station"](area.searchArea);
|
||||||
|
nwr["amenity"="toilets"](area.searchArea);
|
||||||
|
nwr["highway"="bus_stop"](area.searchArea);
|
||||||
|
nwr["emergency"="defibrillator"](area.searchArea);
|
||||||
|
nwr["man_made"="surveillance"](area.searchArea);
|
||||||
|
nwr["amenity"="recycling"](area.searchArea);
|
||||||
|
nwr["power"="substation"](area.searchArea);
|
||||||
);
|
);
|
||||||
out body;
|
out body;
|
||||||
>;
|
>;
|
||||||
|
|
|
@ -5,14 +5,26 @@
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<div class="container mt-4">
|
<div class="container mt-4">
|
||||||
<h1>Suivi des objets OSM pour {{ stats.name }} ({{ stats.zone }})</h1>
|
<h1>Suivi des objets OSM pour {{ stats.name }} ({{ stats.zone }})</h1>
|
||||||
<p>Historique des bornes incendie et bornes de recharge (nombre et complétion).</p>
|
<div class="mb-3">
|
||||||
|
<a href="{{ path('admin_followup', {'insee_code': stats.zone}) }}" class="btn btn-warning">
|
||||||
<h2>Bornes de recharge</h2>
|
<i class="bi bi-arrow-repeat"></i> Mettre à jour les suivis (followup)
|
||||||
<canvas id="chargingStationChart" width="600" height="300"></canvas>
|
</a>
|
||||||
|
</div>
|
||||||
<h2>Bornes incendie</h2>
|
<p>Historique des objets suivis (nombre et complétion).</p>
|
||||||
<canvas id="fireHydrantChart" width="600" height="300"></canvas>
|
{% set type_labels = {
|
||||||
|
'fire_hydrant': 'Bornes incendie',
|
||||||
|
'charging_station': 'Bornes de recharge',
|
||||||
|
'toilets': 'Toilettes publiques',
|
||||||
|
'bus_stop': 'Arrêts de bus',
|
||||||
|
'defibrillator': 'Défibrillateurs',
|
||||||
|
'camera': 'Caméras de surveillance',
|
||||||
|
'recycling': 'Points de recyclage',
|
||||||
|
'substation': 'Sous-stations électriques'
|
||||||
|
} %}
|
||||||
|
{% for type in type_labels|keys %}
|
||||||
|
<h2 id="title-{{ type }}">{{ type_labels[type] }}</h2>
|
||||||
|
<canvas id="{{ type }}Chart" width="600" height="300"></canvas>
|
||||||
|
{% endfor %}
|
||||||
<h2 class="mt-4">Données brutes</h2>
|
<h2 class="mt-4">Données brutes</h2>
|
||||||
<table class="table table-bordered table-striped">
|
<table class="table table-bordered table-striped">
|
||||||
<thead>
|
<thead>
|
||||||
|
@ -36,7 +48,6 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<a href="{{ path('app_admin_stats', {'insee_code': stats.zone}) }}" class="btn btn-secondary mt-3"><i class="bi bi-arrow-left"></i> Retour à la fiche ville</a>
|
<a href="{{ path('app_admin_stats', {'insee_code': stats.zone}) }}" class="btn btn-secondary mt-3"><i class="bi bi-arrow-left"></i> Retour à la fiche ville</a>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -46,47 +57,67 @@
|
||||||
<script src="/js/chartjs/chart.umd.js"></script>
|
<script src="/js/chartjs/chart.umd.js"></script>
|
||||||
<script src="/js/chartjs/chartjs-adapter-date-fns.js"></script>
|
<script src="/js/chartjs/chartjs-adapter-date-fns.js"></script>
|
||||||
<script>
|
<script>
|
||||||
// Log du contenu de la variable series
|
const series = {{ series|json_encode|raw }};
|
||||||
console.log('series', {{ series|json_encode|raw }});
|
const typeLabels = {
|
||||||
|
fire_hydrant: 'Bornes incendie',
|
||||||
// Données bornes de recharge
|
charging_station: 'Bornes de recharge',
|
||||||
const chargingStationCount = [
|
toilets: 'Toilettes publiques',
|
||||||
{% for point in series['charging_station_count'] ?? [] %}
|
bus_stop: 'Arrêts de bus',
|
||||||
{ x: "{{ point.date }}", y: {{ point.value }} },
|
defibrillator: 'Défibrillateurs',
|
||||||
{% endfor %}
|
camera: 'Caméras de surveillance',
|
||||||
];
|
recycling: 'Points de recyclage',
|
||||||
const chargingStationCompletion = [
|
substation: 'Sous-stations électriques'
|
||||||
{% for point in series['charging_station_completion'] ?? [] %}
|
};
|
||||||
{ x: "{{ point.date }}", y: {{ point.value }} },
|
function formatDelta(val) {
|
||||||
{% endfor %}
|
if (val === null) return '-';
|
||||||
];
|
if (val === 0) return '0';
|
||||||
|
return (val > 0 ? '+' : '') + val;
|
||||||
// Données bornes incendie
|
}
|
||||||
const fireHydrantCount = [
|
function getDelta(data, days) {
|
||||||
{% for point in series['fire_hydrant_count'] ?? [] %}
|
if (!data.length) return null;
|
||||||
{ x: "{{ point.date }}", y: {{ point.value }} },
|
const now = new Date(data[data.length - 1].x || data[data.length - 1].date);
|
||||||
{% endfor %}
|
const refDate = new Date(now.getTime() - days * 24 * 60 * 60 * 1000);
|
||||||
];
|
let ref = null;
|
||||||
const fireHydrantCompletion = [
|
for (let i = data.length - 1; i >= 0; i--) {
|
||||||
{% for point in series['fire_hydrant_completion'] ?? [] %}
|
const d = new Date(data[i].x || data[i].date);
|
||||||
{ x: "{{ point.date }}", y: {{ point.value }} },
|
if (d <= refDate) {
|
||||||
{% endfor %}
|
ref = data[i].y !== undefined ? data[i].y : data[i].value;
|
||||||
];
|
break;
|
||||||
|
}
|
||||||
// Log des tableaux JS générés
|
}
|
||||||
console.log('chargingStationCount', chargingStationCount);
|
const last = data[data.length - 1].y !== undefined ? data[data.length - 1].y : data[data.length - 1].value;
|
||||||
console.log('chargingStationCompletion', chargingStationCompletion);
|
return ref !== null ? last - ref : null;
|
||||||
console.log('fireHydrantCount', fireHydrantCount);
|
}
|
||||||
console.log('fireHydrantCompletion', fireHydrantCompletion);
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
Object.keys(typeLabels).forEach(function(baseType) {
|
||||||
// Graphique bornes de recharge
|
const countData = (series[baseType + '_count'] || []).map(pt => ({ x: pt.date, y: pt.value }));
|
||||||
new Chart(document.getElementById('chargingStationChart'), {
|
const completionData = (series[baseType + '_completion'] || []).map(pt => ({ x: pt.date, y: pt.value }));
|
||||||
|
const canvasId = baseType + 'Chart';
|
||||||
|
const canvas = document.getElementById(canvasId);
|
||||||
|
if (!canvas) return;
|
||||||
|
// Derniers points
|
||||||
|
const lastCount = countData.length ? countData[countData.length - 1].y : '-';
|
||||||
|
const lastCompletion = completionData.length ? completionData[completionData.length - 1].y : '-';
|
||||||
|
// Deltas
|
||||||
|
const delta7dCount = formatDelta(getDelta(countData, 7));
|
||||||
|
const delta30dCount = formatDelta(getDelta(countData, 30));
|
||||||
|
const delta365dCount = formatDelta(getDelta(countData, 365));
|
||||||
|
const delta7dComp = formatDelta(getDelta(completionData, 7));
|
||||||
|
const delta30dComp = formatDelta(getDelta(completionData, 30));
|
||||||
|
const delta365dComp = formatDelta(getDelta(completionData, 365));
|
||||||
|
// Mettre à jour le titre
|
||||||
|
const titleElem = document.getElementById('title-' + baseType);
|
||||||
|
if (titleElem) {
|
||||||
|
titleElem.innerHTML = `${typeLabels[baseType]} (N = ${lastCount}, complétion = ${lastCompletion}%)`;
|
||||||
|
}
|
||||||
|
// Créer le graphique
|
||||||
|
new Chart(canvas, {
|
||||||
type: 'line',
|
type: 'line',
|
||||||
data: {
|
data: {
|
||||||
datasets: [
|
datasets: [
|
||||||
{
|
{
|
||||||
label: 'Nombre de bornes de recharge',
|
label: 'Nombre',
|
||||||
data: chargingStationCount,
|
data: countData,
|
||||||
borderColor: 'blue',
|
borderColor: 'blue',
|
||||||
backgroundColor: 'rgba(0,0,255,0.1)',
|
backgroundColor: 'rgba(0,0,255,0.1)',
|
||||||
fill: false,
|
fill: false,
|
||||||
|
@ -94,7 +125,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Complétion (%)',
|
label: 'Complétion (%)',
|
||||||
data: chargingStationCompletion,
|
data: completionData,
|
||||||
borderColor: 'green',
|
borderColor: 'green',
|
||||||
backgroundColor: 'rgba(0,255,0,0.1)',
|
backgroundColor: 'rgba(0,255,0,0.1)',
|
||||||
fill: false,
|
fill: false,
|
||||||
|
@ -103,8 +134,14 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
options: {
|
options: {
|
||||||
// parsing: false,
|
parsing: true,
|
||||||
responsive: true,
|
responsive: true,
|
||||||
|
plugins: {
|
||||||
|
title: {
|
||||||
|
display: true,
|
||||||
|
text: `${typeLabels[baseType]} (N = ${lastCount}, complétion = ${lastCompletion}%)`
|
||||||
|
}
|
||||||
|
},
|
||||||
scales: {
|
scales: {
|
||||||
x: { type: 'time', time: { unit: 'day' }, title: { display: true, text: 'Date' } },
|
x: { type: 'time', time: { unit: 'day' }, title: { display: true, text: 'Date' } },
|
||||||
y: { beginAtZero: true, title: { display: true, text: 'Nombre' } },
|
y: { beginAtZero: true, title: { display: true, text: 'Nombre' } },
|
||||||
|
@ -112,39 +149,16 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
// Afficher les changements sous le graphique
|
||||||
// Graphique bornes incendie
|
const infoDiv = document.createElement('div');
|
||||||
new Chart(document.getElementById('fireHydrantChart'), {
|
infoDiv.className = 'mb-4';
|
||||||
type: 'line',
|
infoDiv.innerHTML = `<strong>Évolution sur :</strong> <ul>
|
||||||
data: {
|
<li>7 jours : N ${delta7dCount}, complétion ${delta7dComp} %</li>
|
||||||
datasets: [
|
<li>30 jours : N ${delta30dCount}, complétion ${delta30dComp} %</li>
|
||||||
{
|
<li>1 an : N ${delta365dCount}, complétion ${delta365dComp} %</li>
|
||||||
label: 'Nombre de bornes incendie',
|
</ul>`;
|
||||||
data: fireHydrantCount,
|
canvas.parentNode.insertBefore(infoDiv, canvas.nextSibling);
|
||||||
borderColor: 'red',
|
});
|
||||||
backgroundColor: 'rgba(255,0,0,0.1)',
|
|
||||||
// fill: false,
|
|
||||||
yAxisID: 'y',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Complétion (%)',
|
|
||||||
data: fireHydrantCompletion,
|
|
||||||
borderColor: 'orange',
|
|
||||||
backgroundColor: 'rgba(255,165,0,0.1)',
|
|
||||||
// fill: false,
|
|
||||||
yAxisID: 'y1',
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
options: {
|
|
||||||
// parsing: false,
|
|
||||||
responsive: true,
|
|
||||||
scales: {
|
|
||||||
x: { type: 'time', time: { unit: 'day' }, title: { display: true, text: 'Date' } },
|
|
||||||
y: { beginAtZero: true, title: { display: true, text: 'Nombre' } },
|
|
||||||
y1: { beginAtZero: true, position: 'right', title: { display: true, text: 'Complétion (%)' }, grid: { drawOnChartArea: false } }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
|
@ -55,6 +55,9 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-6 col-12">
|
<div class="col-md-6 col-12">
|
||||||
<a href="{{ path('app_admin_labourer', {'insee_code': stats.zone, 'deleteMissing': 1}) }}" class="btn btn-primary" id="labourer">Labourer les mises à jour</a>
|
<a href="{{ path('app_admin_labourer', {'insee_code': stats.zone, 'deleteMissing': 1}) }}" class="btn btn-primary" id="labourer">Labourer les mises à jour</a>
|
||||||
|
<a href="{{ path('admin_followup_graph', {'insee_code': stats.zone}) }}" class="btn btn-info ms-2" id="followup-graph-link">
|
||||||
|
<i class="bi bi-graph-up"></i> Suivi OSM (graphes)
|
||||||
|
</a>
|
||||||
<button id="openInJOSM" class="btn btn-secondary ms-2">
|
<button id="openInJOSM" class="btn btn-secondary ms-2">
|
||||||
<i class="bi bi-map"></i> Ouvrir dans JOSM
|
<i class="bi bi-map"></i> Ouvrir dans JOSM
|
||||||
</button>
|
</button>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue