compute stats for completion by zone, have base tags, split categories
This commit is contained in:
parent
f15fec6d18
commit
f69b7824af
16 changed files with 1257 additions and 118 deletions
|
@ -10,12 +10,26 @@ class Motocultrice
|
|||
private $overpassApiUrl = 'https://overpass-api.de/api/interpreter';
|
||||
private $osmApiUrl = 'https://www.openstreetmap.org/api/0.6';
|
||||
|
||||
public $base_tags = [
|
||||
'name',
|
||||
'opening_hours',
|
||||
'contact:email',
|
||||
'contact:phone',
|
||||
'wheelchair',
|
||||
'addr:housenumber',
|
||||
'addr:street',
|
||||
'contact:website',
|
||||
'contact:mastodon',
|
||||
// 'EEEEEEEEEEEEEEEEEEE'
|
||||
];
|
||||
private $more_tags = ['image', 'ref:FR:SIRET'];
|
||||
public function __construct(
|
||||
private HttpClientInterface $client,
|
||||
private EntityManagerInterface $entityManager
|
||||
) {
|
||||
}
|
||||
|
||||
|
||||
public function labourer(string $zone): array
|
||||
{
|
||||
if (!$zone) {
|
||||
|
@ -58,6 +72,9 @@ QUERY;
|
|||
if (isset($data['elements'])) {
|
||||
foreach ($data['elements'] as $element) {
|
||||
if (isset($element['tags'])) {
|
||||
|
||||
|
||||
|
||||
$email = $element['tags']['contact:email'] ?? $element['tags']['email'] ?? null;
|
||||
// On passe si pas d'email
|
||||
if (!$email) {
|
||||
|
@ -86,6 +103,8 @@ QUERY;
|
|||
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;
|
||||
// dump($object_id);
|
||||
// die();
|
||||
|
||||
try {
|
||||
$response = $this->client->request('GET', $object_id);
|
||||
|
@ -96,8 +115,8 @@ QUERY;
|
|||
throw new \Exception("Impossible de récupérer les données OSM : " . $e->getMessage());
|
||||
}
|
||||
|
||||
// convertir les tags en clés et valeurs
|
||||
$osm_object_data['tags_converted'] = [];
|
||||
// convertir les tags en clés et valeurs, remplir avec les tags de base
|
||||
$osm_object_data['tags_converted'] = $this->base_tags;
|
||||
// Initialiser le tableau des tags convertis
|
||||
if (isset($osm_object_data['node'])) {
|
||||
$osm_object_data['node']['tags_converted'] = [];
|
||||
|
@ -236,4 +255,48 @@ QUERY;
|
|||
throw new \Exception("Erreur lors de la communication avec l'API OSM : " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function calculateStats(array $places): array
|
||||
{
|
||||
$counters = [
|
||||
'avec_horaires' => 0,
|
||||
'avec_adresse' => 0,
|
||||
'avec_site' => 0,
|
||||
'avec_accessibilite' => 0,
|
||||
'avec_note' => 0
|
||||
];
|
||||
|
||||
foreach ($places as $place) {
|
||||
if ($place->hasOpeningHours()) {
|
||||
$counters['avec_horaires']++;
|
||||
}
|
||||
if ($place->hasAddress()) {
|
||||
$counters['avec_adresse']++;
|
||||
}
|
||||
if ($place->hasWebsite()) {
|
||||
$counters['avec_site']++;
|
||||
}
|
||||
if ($place->hasWheelchair()) {
|
||||
$counters['avec_accessibilite']++;
|
||||
}
|
||||
if ($place->hasNote()) {
|
||||
$counters['avec_note']++;
|
||||
}
|
||||
}
|
||||
|
||||
$totalPlaces = count($places);
|
||||
$completionPercent = 0;
|
||||
|
||||
if ($totalPlaces > 0) {
|
||||
$totalCriteria = 5; // nombre total de critères
|
||||
$totalCompleted = array_sum($counters);
|
||||
$completionPercent = round(($totalCompleted / ($totalPlaces * $totalCriteria)) * 100);
|
||||
}
|
||||
|
||||
return [
|
||||
'places_count' => $totalPlaces,
|
||||
'completion_percent' => $completionPercent,
|
||||
'counters' => $counters
|
||||
];
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue