up infos vélo
This commit is contained in:
parent
c0a1780fce
commit
0b760c20bc
7 changed files with 246 additions and 50 deletions
|
@ -254,6 +254,32 @@ final class AdminController extends AbstractController
|
|||
$this->followUpService->generateCityFollowUps($stats, $this->motocultrice, $this->entityManager, true, $theme);
|
||||
}
|
||||
$this->entityManager->flush();
|
||||
|
||||
// Après le flush, vérifier s'il n'y a aucun commerce compté
|
||||
if ($stats->getPlacesCount() < 2) {
|
||||
// Récupérer les lieux via Motocultrice
|
||||
try {
|
||||
$placesData = $this->motocultrice->labourer($insee_code);
|
||||
$places = $stats->getPlaces();
|
||||
foreach ($places as $place) {
|
||||
// Chercher les données correspondantes par OSM ID
|
||||
foreach ($placesData as $placeData) {
|
||||
if ($place->getOsmId() == $placeData['id']) {
|
||||
// Mettre à jour les tags et coordonnées
|
||||
$place->update_place_from_overpass_data($placeData);
|
||||
$place->setStat($stats);
|
||||
$stats->addPlace($place);
|
||||
$this->entityManager->persist($place);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->entityManager->flush();
|
||||
} catch (\Exception $e) {
|
||||
// Ignorer les erreurs silencieusement
|
||||
}
|
||||
}
|
||||
|
||||
return $this->redirectToRoute('app_admin_stats', ['insee_code' => $insee_code]);
|
||||
}
|
||||
|
||||
|
@ -748,6 +774,48 @@ final class AdminController extends AbstractController
|
|||
// $this->addFlash('error', '3 Aucune stats trouvée pour ce code INSEE.');
|
||||
// return $this->redirectToRoute('app_public_index');
|
||||
}
|
||||
// Compléter le nom si manquant
|
||||
if (!$stats->getName()) {
|
||||
$cityName = $this->motocultrice->get_city_osm_from_zip_code($insee_code);
|
||||
if ($cityName) {
|
||||
$stats->setName($cityName);
|
||||
}
|
||||
}
|
||||
// Compléter la population si manquante
|
||||
if (!$stats->getPopulation()) {
|
||||
try {
|
||||
$apiUrl = 'https://geo.api.gouv.fr/communes/' . $insee_code;
|
||||
$response = @file_get_contents($apiUrl);
|
||||
if ($response !== false) {
|
||||
$data = json_decode($response, true);
|
||||
if (isset($data['population'])) {
|
||||
$stats->setPopulation((int)$data['population']);
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {}
|
||||
}
|
||||
// Compléter le budget si manquant
|
||||
if (!$stats->getBudgetAnnuel()) {
|
||||
$budget = $this->budgetService->getBudgetAnnuel($insee_code);
|
||||
if ($budget !== null) {
|
||||
$stats->setBudgetAnnuel((string)$budget);
|
||||
}
|
||||
}
|
||||
// Compléter les lieux d'intérêt si manquants (lat/lon)
|
||||
if (!$stats->getLat() || !$stats->getLon()) {
|
||||
// On tente de récupérer le centre de la ville via l'API geo.gouv.fr
|
||||
try {
|
||||
$apiUrl = 'https://geo.api.gouv.fr/communes/' . $insee_code . '?fields=centre';
|
||||
$response = @file_get_contents($apiUrl);
|
||||
if ($response !== false) {
|
||||
$data = json_decode($response, true);
|
||||
if (isset($data['centre']['coordinates']) && count($data['centre']['coordinates']) === 2) {
|
||||
$stats->setLon((string)$data['centre']['coordinates'][0]);
|
||||
$stats->setLat((string)$data['centre']['coordinates'][1]);
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {}
|
||||
}
|
||||
// Mettre à jour la date de requête de labourage
|
||||
$stats->setDateLabourageRequested(new \DateTime());
|
||||
$this->entityManager->persist($stats);
|
||||
|
@ -775,7 +843,7 @@ final class AdminController extends AbstractController
|
|||
// Toujours générer les CityFollowUp (mais ne jamais les supprimer)
|
||||
// $themes = \App\Service\FollowUpService::getFollowUpThemes();
|
||||
// foreach (array_keys($themes) as $theme) {
|
||||
// $this->followUpService->generateCityFollowUps($stats, $this->motocultrice, $this->entityManager, true, $theme);
|
||||
$this->followUpService->generateCityFollowUps($stats, $this->motocultrice, $this->entityManager, true);
|
||||
// }
|
||||
$this->entityManager->flush();
|
||||
return $this->redirectToRoute('app_admin_stats', ['insee_code' => $insee_code]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue