mirror of
https://forge.chapril.org/tykayn/osm-commerces
synced 2025-10-09 17:02:46 +02:00
centralisation des tags de complétion par thème
This commit is contained in:
parent
6cfb2f0958
commit
c7e4f4e6a2
7 changed files with 433 additions and 184 deletions
|
@ -92,196 +92,46 @@ class FollowUpService
|
|||
$em->clear();
|
||||
}
|
||||
|
||||
// Suivi de la complétion personnalisé (exemples)
|
||||
// Suivi de la complétion basé sur les tags attendus
|
||||
$completionTags = self::getFollowUpCompletionTags();
|
||||
$expectedTags = $completionTags[$type] ?? [];
|
||||
$completed = [];
|
||||
if ($type === 'fire_hydrant') {
|
||||
$completed = array_filter($data['objects'], function($el) {
|
||||
$partialCompletions = [];
|
||||
if (!empty($expectedTags)) {
|
||||
foreach ($data['objects'] as $el) {
|
||||
$tags = $el['tags'] ?? [];
|
||||
// Considérer comme complet si au moins un critère supplémentaire est rempli
|
||||
return !empty($tags['ref'] ?? null)
|
||||
|| !empty($tags['name'] ?? null)
|
||||
|| !empty($tags['operator'] ?? null)
|
||||
|| !empty($tags['colour'] ?? null);
|
||||
});
|
||||
} elseif ($type === 'charging_station') {
|
||||
$completed = array_filter($data['objects'], function($el) {
|
||||
$tags = $el['tags'] ?? [];
|
||||
return !empty($tags['charging_station:output'] ?? null)
|
||||
|| !empty($tags['capacity'] ?? null)
|
||||
|| !empty($tags['name'] ?? null)
|
||||
|| !empty($tags['operator'] ?? null);
|
||||
});
|
||||
} elseif ($type === 'toilets') {
|
||||
$completed = array_filter($data['objects'], function($el) {
|
||||
$tags = $el['tags'] ?? [];
|
||||
return ($tags['wheelchair'] ?? null) === 'yes'
|
||||
|| !empty($tags['name'] ?? null)
|
||||
|| !empty($tags['operator'] ?? null)
|
||||
|| !empty($tags['access'] ?? null);
|
||||
});
|
||||
} elseif ($type === 'bus_stop') {
|
||||
$completed = array_filter($data['objects'], function($el) {
|
||||
$tags = $el['tags'] ?? [];
|
||||
// Considérer comme complet si au moins un de ces critères est rempli
|
||||
return !empty($tags['shelter'] ?? null)
|
||||
|| !empty($tags['name'] ?? null)
|
||||
|| !empty($tags['operator'] ?? null)
|
||||
|| !empty($tags['network'] ?? null);
|
||||
});
|
||||
} elseif ($type === 'defibrillator') {
|
||||
$completed = array_filter($data['objects'], function($el) {
|
||||
$tags = $el['tags'] ?? [];
|
||||
// Considérer comme complet si au moins un de ces critères est rempli
|
||||
return !empty($tags['indoor'] ?? null)
|
||||
|| !empty($tags['name'] ?? null)
|
||||
|| !empty($tags['operator'] ?? null)
|
||||
|| !empty($tags['access'] ?? null);
|
||||
});
|
||||
} elseif ($type === 'camera') {
|
||||
$completed = array_filter($data['objects'], function($el) {
|
||||
$tags = $el['tags'] ?? [];
|
||||
return !empty($tags['surveillance:type'] ?? null)
|
||||
|| !empty($tags['name'] ?? null)
|
||||
|| !empty($tags['operator'] ?? null);
|
||||
});
|
||||
} elseif ($type === 'recycling') {
|
||||
$completed = array_filter($data['objects'], function($el) {
|
||||
$tags = $el['tags'] ?? [];
|
||||
return !empty($tags['recycling_type'] ?? null)
|
||||
|| !empty($tags['name'] ?? null)
|
||||
|| !empty($tags['operator'] ?? null);
|
||||
});
|
||||
} elseif ($type === 'substation') {
|
||||
$completed = array_filter($data['objects'], function($el) {
|
||||
$tags = $el['tags'] ?? [];
|
||||
return !empty($tags['substation'] ?? null)
|
||||
|| !empty($tags['name'] ?? null)
|
||||
|| !empty($tags['operator'] ?? null);
|
||||
});
|
||||
} elseif ($type === 'laboratory') {
|
||||
$completed = array_filter($data['objects'], function($el) {
|
||||
$tags = $el['tags'] ?? [];
|
||||
return !empty($tags['website'] ?? null)
|
||||
|| !empty($tags['contact:website'] ?? null)
|
||||
|| !empty($tags['name'] ?? null)
|
||||
|| !empty($tags['phone'] ?? null);
|
||||
});
|
||||
} elseif ($type === 'school') {
|
||||
$completed = array_filter($data['objects'], function($el) {
|
||||
$tags = $el['tags'] ?? [];
|
||||
// Considérer comme complet si au moins un de ces critères est rempli
|
||||
return !empty($tags['ref:UAI'] ?? null)
|
||||
|| !empty($tags['isced:level'] ?? null)
|
||||
|| !empty($tags['school:FR'] ?? null)
|
||||
|| !empty($tags['name'] ?? null)
|
||||
|| !empty($tags['operator'] ?? null);
|
||||
});
|
||||
} elseif ($type === 'police') {
|
||||
$completed = array_filter($data['objects'], function($el) {
|
||||
$tags = $el['tags'] ?? [];
|
||||
return !empty($tags['phone'] ?? null)
|
||||
|| !empty($tags['website'] ?? null)
|
||||
|| !empty($tags['name'] ?? null)
|
||||
|| !empty($tags['operator'] ?? null);
|
||||
});
|
||||
} elseif ($type === 'healthcare') {
|
||||
$completed = array_filter($data['objects'], function($el) {
|
||||
$tags = $el['tags'] ?? [];
|
||||
return !empty($tags['name'] ?? null)
|
||||
|| !empty($tags['contact:phone'] ?? null)
|
||||
|| !empty($tags['phone'] ?? null)
|
||||
|| !empty($tags['email'] ?? null)
|
||||
|| !empty($tags['contact:email'] ?? null)
|
||||
|| !empty($tags['operator'] ?? null);
|
||||
});
|
||||
} elseif ($type === 'bicycle_parking') {
|
||||
$completed = array_filter($data['objects'], function($el) {
|
||||
$tags = $el['tags'] ?? [];
|
||||
return !empty($tags['capacity'] ?? null)
|
||||
|| !empty($tags['covered'] ?? null)
|
||||
|| !empty($tags['name'] ?? null)
|
||||
|| !empty($tags['operator'] ?? null);
|
||||
});
|
||||
} elseif ($type === 'advertising_board') {
|
||||
$completed = array_filter($data['objects'], function($el) {
|
||||
$tags = $el['tags'] ?? [];
|
||||
return !empty($tags['operator'] ?? null)
|
||||
|| !empty($tags['contact:phone'] ?? null)
|
||||
|| !empty($tags['name'] ?? null);
|
||||
});
|
||||
} elseif ($type === 'building') {
|
||||
$completed = array_filter($data['objects'], function($el) {
|
||||
$tags = $el['tags'] ?? [];
|
||||
return !empty($tags['name'] ?? null)
|
||||
|| !empty($tags['ref'] ?? null)
|
||||
|| !empty($tags['operator'] ?? null);
|
||||
});
|
||||
} elseif ($type === 'email') {
|
||||
$completed = array_filter($data['objects'], function($el) {
|
||||
$tags = $el['tags'] ?? [];
|
||||
return !empty($tags['name'] ?? null)
|
||||
|| !empty($tags['phone'] ?? null)
|
||||
|| !empty($tags['operator'] ?? null);
|
||||
});
|
||||
} elseif ($type === 'bench') {
|
||||
$completed = array_filter($data['objects'], function($el) {
|
||||
$tags = $el['tags'] ?? [];
|
||||
return !empty($tags['material'] ?? null)
|
||||
|| !empty($tags['backrest'] ?? null)
|
||||
|| !empty($tags['name'] ?? null)
|
||||
|| !empty($tags['operator'] ?? null);
|
||||
});
|
||||
} elseif ($type === 'waste_basket') {
|
||||
$completed = array_filter($data['objects'], function($el) {
|
||||
$tags = $el['tags'] ?? [];
|
||||
return !empty($tags['waste'] ?? null)
|
||||
|| !empty($tags['recycling_type'] ?? null)
|
||||
|| !empty($tags['name'] ?? null)
|
||||
|| !empty($tags['operator'] ?? null);
|
||||
});
|
||||
} elseif ($type === 'street_lamp') {
|
||||
$completed = array_filter($data['objects'], function($el) {
|
||||
$tags = $el['tags'] ?? [];
|
||||
return !empty($tags['lamp_type'] ?? null)
|
||||
|| !empty($tags['height'] ?? null)
|
||||
|| !empty($tags['name'] ?? null)
|
||||
|| !empty($tags['operator'] ?? null);
|
||||
});
|
||||
} elseif ($type === 'drinking_water') {
|
||||
$completed = array_filter($data['objects'], function($el) {
|
||||
$tags = $el['tags'] ?? [];
|
||||
return !empty($tags['covered'] ?? null)
|
||||
|| !empty($tags['ref'] ?? null)
|
||||
|| !empty($tags['name'] ?? null)
|
||||
|| !empty($tags['operator'] ?? null);
|
||||
});
|
||||
} elseif ($type === 'tree') {
|
||||
$completed = array_filter($data['objects'], function($el) {
|
||||
$tags = $el['tags'] ?? [];
|
||||
$hasTaxonomy = !empty($tags['species'] ?? null)
|
||||
|| !empty($tags['genus'] ?? null)
|
||||
|| !empty($tags['taxon'] ?? null)
|
||||
|| !empty($tags['taxon:binomial'] ?? null);
|
||||
$hasLeaf = !empty($tags['leaf_type'] ?? null)
|
||||
|| !empty($tags['leaf_cycle'] ?? null)
|
||||
|| !empty($tags['leaf_shape'] ?? null)
|
||||
|| !empty($tags['leaf_color'] ?? null)
|
||||
|| !empty($tags['leaf_fall'] ?? null);
|
||||
return $hasTaxonomy && $hasLeaf;
|
||||
});
|
||||
} elseif ($type === 'power_pole') {
|
||||
$completed = array_filter($data['objects'], function($el) {
|
||||
$tags = $el['tags'] ?? [];
|
||||
return !empty($tags['ref'] ?? null)
|
||||
|| !empty($tags['material'] ?? null)
|
||||
|| !empty($tags['height'] ?? null)
|
||||
|| !empty($tags['operator'] ?? null);
|
||||
});
|
||||
$filled = 0;
|
||||
foreach ($expectedTags as $tag) {
|
||||
if ($tag === 'phone') {
|
||||
if (!empty($tags['phone'] ?? null) || !empty($tags['contact:phone'] ?? null)) {
|
||||
$filled++;
|
||||
}
|
||||
} elseif ($tag === 'email') {
|
||||
if (!empty($tags['email'] ?? null) || !empty($tags['contact:email'] ?? null)) {
|
||||
$filled++;
|
||||
}
|
||||
} else {
|
||||
if (!empty($tags[$tag] ?? null)) {
|
||||
$filled++;
|
||||
}
|
||||
}
|
||||
}
|
||||
$percent = count($expectedTags) > 0 ? ($filled / count($expectedTags)) : 0;
|
||||
$partialCompletions[] = $percent;
|
||||
if ($percent === 1.0) {
|
||||
$completed[] = $el;
|
||||
}
|
||||
}
|
||||
}
|
||||
// ... fallback pour les types sans tags attendus
|
||||
else {
|
||||
$completed = [];
|
||||
$partialCompletions = array_fill(0, count($data['objects']), 0);
|
||||
}
|
||||
if ($type === 'places') {
|
||||
$completion = $stats->getCompletionPercent();
|
||||
} else {
|
||||
$completion = count($data['objects']) > 0 ? round(count($completed) / count($data['objects']) * 100) : 0;
|
||||
$completion = count($partialCompletions) > 0 ? round(array_sum($partialCompletions) / count($partialCompletions) * 100) : 0;
|
||||
}
|
||||
$followupCompletion = new CityFollowUp();
|
||||
$followupCompletion->setName($type . '_completion')
|
||||
|
@ -619,4 +469,36 @@ class FollowUpService
|
|||
// Si aucune mesure n'est disponible, retourner null
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne pour chaque thématique la liste des tags attendus pour la complétion
|
||||
*/
|
||||
public static function getFollowUpCompletionTags(): array
|
||||
{
|
||||
return [
|
||||
'fire_hydrant' => ['ref', 'colour'],
|
||||
'charging_station' => ['charging_station:output', 'capacity'],
|
||||
'toilets' => ['wheelchair', 'access'],
|
||||
'bus_stop' => ['shelter', 'network'],
|
||||
'defibrillator' => ['indoor', 'access'],
|
||||
'camera' => ['surveillance:type'],
|
||||
'recycling' => ['recycling_type'],
|
||||
'substation' => ['substation'],
|
||||
'laboratory' => ['website', 'contact:website', 'name', 'phone'],
|
||||
'school' => ['ref:UAI', 'isced:level', 'school:FR'],
|
||||
'police' => ['phone', 'website'],
|
||||
'healthcare' => ['name', 'contact:phone', 'phone', 'email', 'contact:email'],
|
||||
'bicycle_parking' => ['capacity', 'covered'],
|
||||
'advertising_board' => ['operator', 'contact:phone'],
|
||||
'building' => ['name', 'ref'],
|
||||
'email' => ['name', 'phone'],
|
||||
'bench' => ['material', 'backrest'],
|
||||
'waste_basket' => ['waste', 'recycling_type'],
|
||||
'street_lamp' => ['lamp_type', 'height'],
|
||||
'drinking_water' => ['covered', 'ref'],
|
||||
'tree' => ['species', 'leaf_type', 'leaf_cycle'],
|
||||
'power_pole' => ['ref', 'material'],
|
||||
'places' => ['name', 'address', 'opening_hours', 'website', 'phone', 'wheelchair', 'siret'],
|
||||
];
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue