up stats page
This commit is contained in:
parent
a412cb977a
commit
e4bf3753b0
9 changed files with 357 additions and 124 deletions
|
@ -72,6 +72,7 @@ final class AdminController extends AbstractController
|
|||
return $this->render('admin/stats.html.twig', [
|
||||
'stats' => $stats,
|
||||
'zip_code' => $zip_code,
|
||||
'query_places' => $this->motocultrice->get_query_places($zip_code),
|
||||
'counters' => $calculatedStats['counters'],
|
||||
'maptiler_token' => $_ENV['MAPTILER_TOKEN'],
|
||||
'mapbox_token' => $_ENV['MAPBOX_TOKEN'],
|
||||
|
@ -117,8 +118,7 @@ final class AdminController extends AbstractController
|
|||
#[Route('/admin/labourer/{zip_code}', name: 'app_admin_labourer')]
|
||||
public function labourer_zone(string $zip_code): Response
|
||||
{
|
||||
$results = [];
|
||||
// $zone = 'Briis sous forges';
|
||||
$results = [];
|
||||
$results = $this->motocultrice->labourer($zip_code);
|
||||
|
||||
|
||||
|
@ -145,6 +145,16 @@ final class AdminController extends AbstractController
|
|||
$this->entityManager->flush();
|
||||
}
|
||||
|
||||
// Si le nom de la zone n'est pas défini, le récupérer via OSM
|
||||
if (!$stats->getName()) {
|
||||
$city_name = $this->motocultrice->get_city_osm_from_zip_code($zip_code);
|
||||
if ($city_name) {
|
||||
$stats->setName($city_name);
|
||||
$this->entityManager->persist($stats);
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
}
|
||||
|
||||
$commerces = $this->entityManager->getRepository(Place::class)->findBy(['zip_code' => $zip_code]);
|
||||
|
||||
|
||||
|
|
|
@ -52,6 +52,9 @@ class Stats
|
|||
#[ORM\Column(type: Types::SMALLINT, nullable: true)]
|
||||
private ?int $avec_note = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $name = null;
|
||||
|
||||
// calcule le pourcentage de complétion de la zone
|
||||
public function computeCompletionPercent(): ?int
|
||||
{
|
||||
|
@ -211,6 +214,18 @@ class Stats
|
|||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getName(): ?string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setName(?string $name): static
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue