mirror of
https://forge.chapril.org/tykayn/osm-commerces
synced 2025-10-04 17:04:53 +02:00
MAJ de completion
This commit is contained in:
parent
813125a871
commit
be97910177
1 changed files with 16 additions and 153 deletions
|
@ -542,9 +542,9 @@ final class AdminController extends AbstractController
|
|||
list($tagKey, $tagValue) = $extractTag($themeQueries[$theme] ?? '');
|
||||
foreach ($places as $place) {
|
||||
$match = false;
|
||||
// Cas particulier healthcare
|
||||
$main_tag = $place->getMainTag();
|
||||
// Cas particuliers multi-valeurs (ex: healthcare)
|
||||
if ($theme === 'healthcare') {
|
||||
$main_tag = $place->getMainTag();
|
||||
if ($main_tag && (
|
||||
str_starts_with($main_tag, 'healthcare=') ||
|
||||
in_array($main_tag, [
|
||||
|
@ -557,19 +557,13 @@ final class AdminController extends AbstractController
|
|||
)) {
|
||||
$match = true;
|
||||
}
|
||||
} elseif ($tagKey && $tagValue) {
|
||||
// On tente de retrouver la valeur du tag dans les propriétés Place
|
||||
$main_tag = $place->getMainTag();
|
||||
if ($main_tag === "$tagKey=$tagValue") {
|
||||
} else {
|
||||
// Détection générique : si le mainTag correspond à la clé/valeur du thème
|
||||
if ($tagKey && $tagValue && $main_tag === "$tagKey=$tagValue") {
|
||||
$match = true;
|
||||
}
|
||||
// Cas particuliers pour certains tags stockés ailleurs
|
||||
if (!$match) {
|
||||
if ($tagKey === 'highway' && method_exists($place, 'getOsmKind') && $place->getOsmKind() === $tagValue) {
|
||||
$match = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Ajouter l'objet si match
|
||||
if ($match && $place->getLat() && $place->getLon()) {
|
||||
$objects[] = [
|
||||
'id' => $place->getOsmId(),
|
||||
|
@ -1986,9 +1980,9 @@ final class AdminController extends AbstractController
|
|||
list($tagKey, $tagValue) = $extractTag($themeQueries[$theme] ?? '');
|
||||
foreach ($places as $place) {
|
||||
$match = false;
|
||||
// Cas particulier healthcare
|
||||
$main_tag = $place->getMainTag();
|
||||
// Cas particuliers multi-valeurs (ex: healthcare)
|
||||
if ($theme === 'healthcare') {
|
||||
$main_tag = $place->getMainTag();
|
||||
if ($main_tag && (
|
||||
str_starts_with($main_tag, 'healthcare=') ||
|
||||
in_array($main_tag, [
|
||||
|
@ -2001,19 +1995,13 @@ final class AdminController extends AbstractController
|
|||
)) {
|
||||
$match = true;
|
||||
}
|
||||
} elseif ($tagKey && $tagValue) {
|
||||
// On tente de retrouver la valeur du tag dans les propriétés Place
|
||||
$main_tag = $place->getMainTag();
|
||||
if ($main_tag === "$tagKey=$tagValue") {
|
||||
} else {
|
||||
// Détection générique : si le mainTag correspond à la clé/valeur du thème
|
||||
if ($tagKey && $tagValue && $main_tag === "$tagKey=$tagValue") {
|
||||
$match = true;
|
||||
}
|
||||
// Cas particuliers pour certains tags stockés ailleurs
|
||||
if (!$match) {
|
||||
if ($tagKey === 'highway' && method_exists($place, 'getOsmKind') && $place->getOsmKind() === $tagValue) {
|
||||
$match = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Ajouter l'objet si match
|
||||
if ($match && $place->getLat() && $place->getLon()) {
|
||||
$objects[] = [
|
||||
'id' => $place->getOsmId(),
|
||||
|
@ -2079,140 +2067,15 @@ final class AdminController extends AbstractController
|
|||
}
|
||||
|
||||
$themes = \App\Service\FollowUpService::getFollowUpThemes();
|
||||
if (!isset($themes[$theme])) {
|
||||
$this->addFlash('error', 'Thème non reconnu.');
|
||||
return $this->redirectToRoute('app_admin_stats', ['insee_code' => $insee_code]);
|
||||
}
|
||||
|
||||
// Récupérer toutes les données de followup pour ce thème
|
||||
$followups = $stats->getCityFollowUps();
|
||||
$countData = [];
|
||||
$completionData = [];
|
||||
|
||||
foreach ($followups as $fu) {
|
||||
if ($fu->getName() === $theme . '_count') {
|
||||
$countData[] = [
|
||||
'date' => $fu->getDate()->format('Y-m-d'),
|
||||
'value' => $fu->getMeasure()
|
||||
];
|
||||
}
|
||||
if ($fu->getName() === $theme . '_completion') {
|
||||
$completionData[] = [
|
||||
'date' => $fu->getDate()->format('Y-m-d'),
|
||||
'value' => $fu->getMeasure()
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Trier par date
|
||||
usort($countData, fn($a, $b) => $a['date'] <=> $b['date']);
|
||||
usort($completionData, fn($a, $b) => $a['date'] <=> $b['date']);
|
||||
|
||||
// Récupérer les objets du thème (Place) pour la ville
|
||||
$places = $this->entityManager->getRepository(Place::class)->findBy(['zip_code' => $insee_code]);
|
||||
$motocultrice = $this->motocultrice;
|
||||
$objects = [];
|
||||
// Récupérer la correspondance thème <-> requête Overpass
|
||||
$themeQueries = \App\Service\FollowUpService::getFollowUpOverpassQueries();
|
||||
$overpass_type_query = $themeQueries[$theme] ?? '';
|
||||
if ($overpass_type_query) {
|
||||
$overpass_query = "[out:json][timeout:60];\narea[\"ref:INSEE\"=\"$insee_code\"]->.searchArea;\n($overpass_type_query);\n(._;>;);\nout meta;\n>;";
|
||||
$josm_url = 'http://127.0.0.1:8111/import?url=https://overpass-api.de/api/interpreter?data=' . urlencode($overpass_query);
|
||||
} else {
|
||||
$josm_url = null;
|
||||
}
|
||||
// Fonction utilitaire pour extraire clé/valeur de la requête Overpass
|
||||
$extractTag = function ($query) {
|
||||
if (preg_match('/\\[([a-zA-Z0-9:_-]+)\\]="([^"]+)"/', $query, $matches)) {
|
||||
return [$matches[1], $matches[2]];
|
||||
}
|
||||
return [null, null];
|
||||
};
|
||||
list($tagKey, $tagValue) = $extractTag($themeQueries[$theme] ?? '');
|
||||
foreach ($places as $place) {
|
||||
$match = false;
|
||||
// Cas particulier healthcare
|
||||
if ($theme === 'healthcare') {
|
||||
$main_tag = $place->getMainTag();
|
||||
if ($main_tag && (
|
||||
str_starts_with($main_tag, 'healthcare=') ||
|
||||
in_array($main_tag, [
|
||||
'amenity=doctors',
|
||||
'amenity=pharmacy',
|
||||
'amenity=hospital',
|
||||
'amenity=clinic',
|
||||
'amenity=social_facility'
|
||||
])
|
||||
)) {
|
||||
$match = true;
|
||||
}
|
||||
} elseif ($tagKey && $tagValue) {
|
||||
// On tente de retrouver la valeur du tag dans les propriétés Place
|
||||
$main_tag = $place->getMainTag();
|
||||
if ($main_tag === "$tagKey=$tagValue") {
|
||||
$match = true;
|
||||
}
|
||||
// Cas particuliers pour certains tags stockés ailleurs
|
||||
if (!$match) {
|
||||
if ($tagKey === 'highway' && method_exists($place, 'getOsmKind') && $place->getOsmKind() === $tagValue) {
|
||||
$match = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($match && $place->getLat() && $place->getLon()) {
|
||||
$objects[] = [
|
||||
'id' => $place->getOsmId(),
|
||||
'osm_kind' => $place->getOsmKind(),
|
||||
'lat' => $place->getLat(),
|
||||
'lon' => $place->getLon(),
|
||||
'name' => $place->getName(),
|
||||
'tags' => ['main_tag' => $place->getMainTag()],
|
||||
'is_complete' => !empty($place->getName()),
|
||||
'osm_url' => 'https://www.openstreetmap.org/' . $place->getOsmKind() . '/' . $place->getOsmId(),
|
||||
'uuid' => $place->getUuidForUrl(),
|
||||
'zip_code' => $place->getZipCode(),
|
||||
];
|
||||
}
|
||||
}
|
||||
$geojson = [
|
||||
'type' => 'FeatureCollection',
|
||||
'features' => array_map(function ($obj) {
|
||||
return [
|
||||
'type' => 'Feature',
|
||||
'geometry' => [
|
||||
'type' => 'Point',
|
||||
'coordinates' => [$obj['lon'], $obj['lat']]
|
||||
],
|
||||
'properties' => $obj
|
||||
];
|
||||
}, $objects)
|
||||
];
|
||||
|
||||
// Centre de la carte : centre géographique des objets ou de la ville
|
||||
$center = null;
|
||||
if (count($objects) > 0) {
|
||||
$lat = array_sum(array_column($objects, 'lat')) / count($objects);
|
||||
$lon = array_sum(array_column($objects, 'lon')) / count($objects);
|
||||
$center = [$lon, $lat];
|
||||
} elseif ($stats->getPlaces()->count() > 0) {
|
||||
$first = $stats->getPlaces()->first();
|
||||
$center = [$first->getLon(), $first->getLat()];
|
||||
}
|
||||
// On ne vérifie pas ici un thème unique, on boucle sur tous les thèmes plus loin
|
||||
|
||||
// Ici, on ne prépare que les variables globales pour le template
|
||||
return $this->render('admin/followup_graph.html.twig', [
|
||||
'stats' => $stats,
|
||||
'theme' => $theme,
|
||||
'theme_label' => $themes[$theme],
|
||||
'count_data' => json_encode($countData),
|
||||
'completion_data' => json_encode($completionData),
|
||||
'icons' => \App\Service\FollowUpService::getFollowUpIcons(),
|
||||
'geojson' => json_encode($geojson),
|
||||
'overpass_query' => $overpass_query,
|
||||
'josm_url' => $josm_url,
|
||||
'center' => $center,
|
||||
'maptiler_token' => $_ENV['MAPTILER_TOKEN'] ?? null,
|
||||
'completion_tags' => \App\Service\FollowUpService::getFollowUpCompletionTags(),
|
||||
'followup_labels' => \App\Service\FollowUpService::getFollowUpThemes(),
|
||||
'followup_icons' => \App\Service\FollowUpService::getFollowUpIcons(),
|
||||
// ... autres variables nécessaires ...
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue