follow up graphs

This commit is contained in:
Tykayn 2025-06-29 15:56:55 +02:00 committed by tykayn
parent 4b4a46c3f7
commit ab1b9a9d3d
11 changed files with 580 additions and 41 deletions

View file

@ -556,4 +556,41 @@ out meta;';
'counters' => $counters
];
}
/**
* Génère la requête Overpass pour les bornes incendie et bornes de recharge
*/
public function get_followup_query($zone) {
return <<<QUERY
[out:json][timeout:60];
area["ref:INSEE"="$zone"]->.searchArea;
(
nwr["emergency"="fire_hydrant"](area.searchArea);
nwr["amenity"="charging_station"](area.searchArea);
);
out body;
>;
out skel qt;
QUERY;
}
/**
* Récupère les objets de suivi pour une ville (bornes incendie et bornes de recharge)
*/
public function followUpCity($zone) {
$query = $this->get_followup_query($zone);
try {
$response = $this->client->request('POST', 'https://overpass-api.de/api/interpreter', [
'body' => ['data' => $query],
'timeout' => 60
]);
if ($response->getStatusCode() !== 200) {
throw new \Exception('L\'API Overpass a retourné un code de statut non-200 : ' . $response->getStatusCode());
}
$data = json_decode($response->getContent(), true);
return $data['elements'] ?? [];
} catch (\Exception $e) {
return [];
}
}
}