up stats page

This commit is contained in:
Tykayn 2025-06-03 12:51:20 +02:00 committed by tykayn
parent a412cb977a
commit e4bf3753b0
9 changed files with 357 additions and 124 deletions

View file

@ -60,7 +60,25 @@ class Motocultrice
"alt_name" => "was:alt_name"
];
public function get_query_places($zone) {
return <<<QUERY
[out:json][timeout:25];
area["ISO3166-1"="FR"]->.france;
area["postal_code"="{$zone}"](area.france)->.searchArea;
(
nw["amenity"~"^(cafe|bar|restaurant|library|cinema|fast_food|post_office|marketplace|community_centre|theatre|bank|townhall)$"](area.searchArea);
nw["shop"](area.searchArea);
nw["healthcare"](area.searchArea);
nw["office"](area.searchArea);
);
out body;
>;
out skel qt;
QUERY;
}
private $more_tags = ['image', 'ref:FR:SIRET'];
public function __construct(
private HttpClientInterface $client,
@ -72,12 +90,7 @@ class Motocultrice
$has_ask_angela = false;
$remove_ask_angela = false;
$has_opening_hours = false;
// $has_phone = false;
// $has_contact_phone = false;
// $has_email = false;
// $has_contact_email = false;
$has_opening_hours = false;
$modified_request_post = [];
@ -123,47 +136,12 @@ class Motocultrice
// Nettoyer et échapper la zone pour la requête
$zone = addslashes(trim($zone));
// //area["postal_code"="{$zone}"]->.searchArea;
$query = <<<QUERY
[out:json][timeout:25];
{{geocodeArea:{$zone}}}->.searchArea;
(
// Recherche des commerces et services avec email
nw["amenity"]["contact:email"][name](area.searchArea);
nw["amenity"]["email"][name](area.searchArea);
nw["shop"]["contact:email"][name](area.searchArea);
nw["shop"]["email"][name](area.searchArea);
nw["office"]["contact:email"][name](area.searchArea);
nw["office"]["email"][name](area.searchArea);
// Recherche des commerces et services sans email pour référence
nw["amenity"][name](area.searchArea);
nw["shop"][name](area.searchArea);
nw["office"][name](area.searchArea);
);
out body;
>;
out skel qt;
QUERY;
$query = $this->get_query_places($zone);
if($use_places_without_email_to_reference) {
$query = <<<QUERY
[out:json][timeout:25];
area(id:3610571698)->.searchArea;
(
nw["amenity"~"^(cafe|bar|restaurant|library|cinema|fast_food|post_office|marketplace|community_centre|theatre|bank|townhall)$"](area.searchArea);
nw["healthcare"](area.searchArea);
nw["shop"](area.searchArea);
nw["tourism"~"^(museum|hotel|chalet|apartment)$"](area.searchArea);
nw["office"](area.searchArea);
);
out body;
>;
out skel qt;
QUERY;
$query = $this->get_query_places($zone);
}
$essai_query = "%5Bout%3Ajson%5D%5Btimeout%3A25%5D%3B%0A%0A(%0Aarea(id%3A3610571698)-%3E.searchArea%3B%0A++++nw%5B%22amenity%22~%22%5E(cafe%7Cbar%7Crestaurant%7Clibrary%7Ccinema%7Cfast_food%7Cpost_office%7Cmarketplace%7Ccommunity_centre%7Ctheatre%7Cbank%7Ctownhall)%24%22%5D(area.searchArea)%3B%0A++++nw%5B%22healthcare%22%5D(area.searchArea)%3B%0A++++nw%5B%22shop%22%5D(area.searchArea)%3B%0A++++nw%5B%22tourism%22~%22%5E(museum%7Chotel%7Cchalet%7Capartment)%24%22%5D(area.searchArea)%3B%0A++++nw%5B%22office%22%5D(area.searchArea)%3B%0A)%3B%0Aout+body%3B%0A%3E%3B%0Aout+center%3B";
try {
$response = $this->client->request('POST', $this->overpassApiUrl, [
'body' => ['data' => $query]
@ -208,6 +186,29 @@ QUERY;
}
}
public function get_city_osm_from_zip_code($zip_code) {
// Requête Overpass pour obtenir la zone administrative de niveau 8 avec un nom
$query = "[out:json][timeout:25];
area[\"postal_code\"=\"{$zip_code}\"]->.searchArea;
(
relation[\"admin_level\"=\"8\"][\"name\"][\"type\"=\"boundary\"][\"boundary\"=\"administrative\"](area.searchArea);
);
out body;
>;
out skel qt;";
// $query = "area[\"postal_code\"=\"{$zip_code}\"]->.searchArea;";
$response = $this->client->request('POST', $this->overpassApiUrl, [
'body' => ['data' => $query]
]);
$data = json_decode($response->getContent(), true);
if (isset($data['elements']) && !empty($data['elements'])) {
$city = $data['elements'][0]['tags']['name'];
return $city;
}
return null;
}
public function get_osm_object_data($osm_kind = 'node', $osm_object_id = 12855459190)
{
$object_id = "https://www.openstreetmap.org/api/0.6/".$osm_kind."/".$osm_object_id;