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',
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -48,6 +48,22 @@ class FollowUpService
|
|||
}) ?? [];
|
||||
} elseif ($type === 'bicycle_parking') {
|
||||
$objects = array_filter($elements, fn($el) => ($el['tags']['amenity'] ?? null) === 'bicycle_parking') ?? [];
|
||||
} elseif ($type === 'advertising_board') {
|
||||
$objects = array_filter($elements, fn($el) => ($el['tags']['advertising'] ?? null) === 'board' && ($el['tags']['message'] ?? null) === 'political') ?? [];
|
||||
} elseif ($type === 'building') {
|
||||
$objects = array_filter($elements, fn($el) => ($el['type'] ?? null) === 'way' && !empty($el['tags']['building'])) ?? [];
|
||||
} elseif ($type === 'email') {
|
||||
$objects = array_filter($elements, fn($el) => !empty($el['tags']['email'] ?? null) || !empty($el['tags']['contact:email'] ?? null)) ?? [];
|
||||
} elseif ($type === 'bench') {
|
||||
$objects = array_filter($elements, fn($el) => ($el['tags']['amenity'] ?? null) === 'bench') ?? [];
|
||||
} elseif ($type === 'waste_basket') {
|
||||
$objects = array_filter($elements, fn($el) => ($el['tags']['amenity'] ?? null) === 'waste_basket') ?? [];
|
||||
} elseif ($type === 'street_lamp') {
|
||||
$objects = array_filter($elements, fn($el) => ($el['tags']['highway'] ?? null) === 'street_lamp') ?? [];
|
||||
} elseif ($type === 'drinking_water') {
|
||||
$objects = array_filter($elements, fn($el) => ($el['tags']['amenity'] ?? null) === 'drinking_water') ?? [];
|
||||
} elseif ($type === 'tree') {
|
||||
$objects = array_filter($elements, fn($el) => ($el['tags']['natural'] ?? null) === 'tree') ?? [];
|
||||
} elseif ($type === 'places') {
|
||||
$objects = [];
|
||||
} else {
|
||||
|
@ -128,6 +144,43 @@ class FollowUpService
|
|||
$completed = array_filter($data['objects'], function($el) {
|
||||
return !empty($el['tags']['capacity'] ?? null) || !empty($el['tags']['covered'] ?? null);
|
||||
});
|
||||
} elseif ($type === 'advertising_board') {
|
||||
$completed = array_filter($data['objects'], function($el) {
|
||||
// On considère complet si le tag "operator" ou "ref" est présent
|
||||
return !empty($el['tags']['operator'] ?? null) || !empty($el['tags']['ref'] ?? null);
|
||||
});
|
||||
} elseif ($type === 'building') {
|
||||
$completed = array_filter($data['objects'], function($el) {
|
||||
// Complet si ref:FR:RNB est rempli
|
||||
return !empty($el['tags']['ref:FR:RNB'] ?? null);
|
||||
});
|
||||
} elseif ($type === 'email') {
|
||||
$completed = $data['objects']; // Possède déjà un email ou contact:email
|
||||
} elseif ($type === 'bench') {
|
||||
$completed = array_filter($data['objects'], function($el) {
|
||||
// Complet si le tag "material" ou "backrest" est présent
|
||||
return !empty($el['tags']['material'] ?? null) || !empty($el['tags']['backrest'] ?? null);
|
||||
});
|
||||
} elseif ($type === 'waste_basket') {
|
||||
$completed = array_filter($data['objects'], function($el) {
|
||||
// Complet si le tag "material" ou "ref" est présent
|
||||
return !empty($el['tags']['material'] ?? null) || !empty($el['tags']['ref'] ?? null);
|
||||
});
|
||||
} elseif ($type === 'street_lamp') {
|
||||
$completed = array_filter($data['objects'], function($el) {
|
||||
// Complet si le tag "lamp_type" ou "ref" est présent
|
||||
return !empty($el['tags']['lamp_type'] ?? null) || !empty($el['tags']['ref'] ?? null);
|
||||
});
|
||||
} elseif ($type === 'drinking_water') {
|
||||
$completed = array_filter($data['objects'], function($el) {
|
||||
// Complet si le tag "covered" ou "ref" est présent
|
||||
return !empty($el['tags']['covered'] ?? null) || !empty($el['tags']['ref'] ?? null);
|
||||
});
|
||||
} elseif ($type === 'tree') {
|
||||
$completed = array_filter($data['objects'], function($el) {
|
||||
// Complet si le tag "species" ou "ref" est présent
|
||||
return !empty($el['tags']['species'] ?? null) || !empty($el['tags']['ref'] ?? null);
|
||||
});
|
||||
}
|
||||
if ($type === 'lieux') {
|
||||
// Si le type est "lieux", on utilise la méthode completionPercent() de $stats
|
||||
|
@ -251,6 +304,14 @@ class FollowUpService
|
|||
'police' => 'Commissariats',
|
||||
'healthcare' => 'Lieux de santé',
|
||||
'bicycle_parking' => 'Parkings vélos',
|
||||
'advertising_board' => 'Panneaux électoraux',
|
||||
'building' => 'Bâtiments',
|
||||
'email' => 'Objets avec email',
|
||||
'bench' => 'Bancs',
|
||||
'waste_basket' => 'Poubelles',
|
||||
'street_lamp' => 'Lampadaires',
|
||||
'drinking_water' => 'Eau potable',
|
||||
'tree' => 'Arbres',
|
||||
'places' => 'Lieux'
|
||||
];
|
||||
}
|
||||
|
@ -271,6 +332,14 @@ class FollowUpService
|
|||
'police' => 'bi-shield-lock',
|
||||
'healthcare' => 'bi-hospital',
|
||||
'bicycle_parking' => 'bi-bicycle',
|
||||
'advertising_board' => 'bi-easel',
|
||||
'building' => 'bi-building',
|
||||
'email' => 'bi-envelope-at',
|
||||
'bench' => 'bi-badge-wc',
|
||||
'waste_basket' => 'bi-trash',
|
||||
'street_lamp' => 'bi-lightbulb',
|
||||
'drinking_water' => 'bi-droplet-half',
|
||||
'tree' => 'bi-tree',
|
||||
'places' => 'bi-geo-alt'
|
||||
];
|
||||
}
|
||||
|
@ -291,6 +360,14 @@ class FollowUpService
|
|||
'police' => 'nwr["amenity"="police"](area.searchArea);',
|
||||
'healthcare' => 'nwr["healthcare"](area.searchArea);nwr["amenity"="doctors"](area.searchArea);nwr["amenity"="pharmacy"](area.searchArea);nwr["amenity"="hospital"](area.searchArea);nwr["amenity"="clinic"](area.searchArea);nwr["amenity"="social_facility"](area.searchArea);',
|
||||
'bicycle_parking' => 'nwr["amenity"="bicycle_parking"](area.searchArea);',
|
||||
'advertising_board' => 'nwr["advertising"="board"]["message"="political"](area.searchArea);',
|
||||
'building' => 'way["building"](area.searchArea);',
|
||||
'email' => 'nwr["email"](area.searchArea);nwr["contact:email"](area.searchArea);',
|
||||
'bench' => 'nwr["amenity"="bench"](area.searchArea);',
|
||||
'waste_basket' => 'nwr["amenity"="waste_basket"](area.searchArea);',
|
||||
'street_lamp' => 'nwr["highway"="street_lamp"](area.searchArea);',
|
||||
'drinking_water' => 'nwr["amenity"="drinking_water"](area.searchArea);',
|
||||
'tree' => 'nwr["natural"="tree"](area.searchArea);',
|
||||
'places' => ''
|
||||
];
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ class Motocultrice
|
|||
|
||||
public $overpass_base_places = '
|
||||
(
|
||||
nw["amenity"~"^(cafe|bar|restaurant|library|cinema|fast_food|post_office|marketplace|community_centre|theatre|bank|townhall|animal_boarding|animal_breeding|animal_shelter|animal_training|archive|arts_centre|bicycle_rental|biergarten|boat_rental|boat_storage|bureau_de_change|canteen|car_rental|car_wash|casino|childcare|clinic|college|conference_centre|courthouse|coworking_space|crematorium|dancing_school|dentist|dive_centre|doctors)$"](area.searchArea);
|
||||
nw["amenity"~"^(cafe|bar|restaurant|library|cinema|fast_food|post_office|marketplace|community_centre|theatre|bank|townhall|animal_boarding|animal_breeding|animal_shelter|animal_training|archive|arts_centre|bicycle_rental|biergarten|boat_rental|boat_storage|bureau_de_change|canteen|car_rental|car_wash|casino|childcare|clinic|college|conference_centre|courthouse|coworking_space|crematorium|dancing_school|dentist|dive_centre|doctors|vehicle_inspection|driving_school)$"](area.searchArea);
|
||||
nw["shop"]["shop"!~"vacant"](area.searchArea);
|
||||
nw["tourism"~"^(hotel|hostel|motel|wilderness_hut|yes|chalet|gallery|guest_house|museum|zoo|theme_park|aquarium|alpine_hut|apartment)$"](area.searchArea);
|
||||
nw["healthcare"](area.searchArea);
|
||||
|
@ -583,6 +583,15 @@ area["ref:INSEE"="$zone"]->.searchArea;
|
|||
nwr["amenity"="school"](area.searchArea);
|
||||
nwr["amenity"="police"](area.searchArea);
|
||||
nwr["amenity"="bicycle_parking"](area.searchArea);
|
||||
nwr["advertising"="board"]["message"="political"](area.searchArea);
|
||||
way["building"](area.searchArea);
|
||||
nwr["email"](area.searchArea);
|
||||
nwr["contact:email"](area.searchArea);
|
||||
nwr["amenity"="bench"](area.searchArea);
|
||||
nwr["amenity"="waste_basket"](area.searchArea);
|
||||
nwr["highway"="street_lamp"](area.searchArea);
|
||||
nwr["amenity"="drinking_water"](area.searchArea);
|
||||
nwr["natural"="tree"](area.searchArea);
|
||||
);
|
||||
(._;>;);
|
||||
out meta;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue