presentation thèmes par ville

This commit is contained in:
Tykayn 2025-07-05 14:31:50 +02:00 committed by tykayn
parent 5188f12ad4
commit 6f3d19245e
6 changed files with 417 additions and 63 deletions

View file

@ -590,6 +590,7 @@ final class AdminController extends AbstractController
{ {
$deleteMissing = $request->query->getBoolean('deleteMissing', true); $deleteMissing = $request->query->getBoolean('deleteMissing', true);
$disableFollowUpCleanup = $request->query->getBoolean('disableFollowUpCleanup', false); $disableFollowUpCleanup = $request->query->getBoolean('disableFollowUpCleanup', false);
$debug = $request->query->getBoolean('debug', false);
$this->actionLogger->log('labourer', ['insee_code' => $insee_code]); $this->actionLogger->log('labourer', ['insee_code' => $insee_code]);
@ -599,11 +600,51 @@ final class AdminController extends AbstractController
$this->actionLogger->log('ERROR_labourer_bad_insee', ['insee_code' => $insee_code]); $this->actionLogger->log('ERROR_labourer_bad_insee', ['insee_code' => $insee_code]);
return $this->redirectToRoute('app_public_index'); return $this->redirectToRoute('app_public_index');
} }
$city = null;
$city_insee_found = null;
$city_debug = null;
try { try {
// Récupérer ou créer les stats pour cette zone // Récupérer ou créer les stats pour cette zone
$stats = $this->entityManager->getRepository(Stats::class)->findOneBy(['zone' => $insee_code]); $stats = $this->entityManager->getRepository(Stats::class)->findOneBy(['zone' => $insee_code]);
$city = $this->motocultrice->get_city_osm_from_zip_code($insee_code); $city = $this->motocultrice->get_city_osm_from_zip_code($insee_code);
// Si la fonction retourne un tableau ou un objet, on tente d'en extraire le code INSEE
if (is_array($city) && isset($city['insee'])) {
$city_insee_found = $city['insee'];
$city_debug = $city;
$city = $city['name'] ?? $city_insee_found;
} elseif (is_object($city) && isset($city->insee)) {
$city_insee_found = $city->insee;
$city_debug = (array)$city;
$city = $city->name ?? $city_insee_found;
} else {
$city_insee_found = $insee_code;
}
// Si le code INSEE trouvé ne correspond pas à celui demandé, afficher un message et stopper
if ($city_insee_found !== $insee_code) {
$msg = "Attention : le code INSEE trouvé (" . $city_insee_found . ") ne correspond pas à celui demandé (" . $insee_code . "). Aucune modification effectuée.";
if ($debug) {
return $this->render('admin/labourage_debug.html.twig', [
'insee_code' => $insee_code,
'city_insee_found' => $city_insee_found,
'city_debug' => $city_debug,
'city_name' => $city,
'message' => $msg,
'stats' => $stats,
]);
}
$this->addFlash('error', $msg);
return $this->render('admin/labourage_debug.html.twig', [
'insee_code' => $insee_code,
'city_insee_found' => $city_insee_found,
'city_debug' => $city_debug,
'city_name' => $city,
'message' => $msg,
'stats' => $stats,
]);
}
if (!$stats) { if (!$stats) {
$stats = new Stats(); $stats = new Stats();
$stats->setDateCreated(new \DateTime()); $stats->setDateCreated(new \DateTime());
@ -970,10 +1011,29 @@ final class AdminController extends AbstractController
return $this->redirectToRoute('app_admin_stats', ['insee_code' => $insee_code]); return $this->redirectToRoute('app_admin_stats', ['insee_code' => $insee_code]);
} catch (\Exception $e) { } catch (\Exception $e) {
$this->addFlash('error', 'Erreur lors du labourage : ' . $e->getMessage()); $this->addFlash('error', 'Erreur lors du labourage : ' . $e->getMessage());
die(var_dump($e)); if ($debug) {
return $this->render('admin/labourage_debug.html.twig', [
'insee_code' => $insee_code,
'city_insee_found' => $city_insee_found,
'city_debug' => $city_debug,
'city_name' => $city,
'message' => $e->getMessage(),
'stats' => $stats ?? null,
]);
}
return $this->redirectToRoute('app_admin_stats', ['insee_code' => $insee_code]);
}
// ... (fin normale du traitement, on peut ajouter un affichage debug si besoin)
if ($debug) {
return $this->render('admin/labourage_debug.html.twig', [
'insee_code' => $insee_code,
'city_insee_found' => $city_insee_found,
'city_debug' => $city_debug,
'city_name' => $city,
'message' => null,
'stats' => $stats,
]);
} }
// return $this->redirectToRoute('app_public_dashboard');
return $this->redirectToRoute('app_admin_stats', ['insee_code' => $insee_code]); return $this->redirectToRoute('app_admin_stats', ['insee_code' => $insee_code]);
} }
@ -1673,4 +1733,33 @@ final class AdminController extends AbstractController
$response->setContent($csv); $response->setContent($csv);
return $response; return $response;
} }
#[Route('/admin/test-ctc/{insee_code}', name: 'admin_test_ctc', requirements: ['insee_code' => '\d+'], defaults: ['insee_code' => null])]
public function testCTC(Request $request, ?string $insee_code = null): Response
{
$json = null;
$url = null;
$error = null;
$stats = null;
if ($insee_code) {
$stats = $this->entityManager->getRepository(\App\Entity\Stats::class)->findOneBy(['zone' => $insee_code]);
if ($stats) {
$url = $stats->getCTCurlBase();
try {
$json = file_get_contents($url . '_last_stats.json');
} catch (\Exception $e) {
$error = $e->getMessage();
}
} else {
$error = "Aucune stats trouvée pour ce code INSEE.";
}
}
return $this->render('admin/test_ctc.html.twig', [
'insee_code' => $insee_code,
'url' => $url ? $url . '_last_stats.json' : null,
'json' => $json,
'error' => $error,
'stats' => $stats
]);
}
} }

View file

@ -10,6 +10,9 @@
<a href="{{ path('app_admin_stats', {'insee_code': stats.zone}) }}" class="btn btn-info me-2"> <a href="{{ path('app_admin_stats', {'insee_code': stats.zone}) }}" class="btn btn-info me-2">
<i class="bi bi-bar-chart"></i> Voir la page de la ville <i class="bi bi-bar-chart"></i> Voir la page de la ville
</a> </a>
<a href="{{ path('admin_followup_theme_graph', {'insee_code': stats.zone, 'theme': theme}) }}" class="btn btn-primary me-2">
<i class="bi bi-graph-up"></i> Graphe détaillé
</a>
<a href="https://osm-mon-commerce.fr/?insee={{ stats.zone }}" target="_blank" class="btn btn-success me-2"> <a href="https://osm-mon-commerce.fr/?insee={{ stats.zone }}" target="_blank" class="btn btn-success me-2">
<i class="bi bi-globe"></i> OSM Mon Commerce <i class="bi bi-globe"></i> OSM Mon Commerce
</a> </a>

View file

@ -0,0 +1,25 @@
{% extends 'base.html.twig' %}
{% block title %}Debug Labourage{% endblock %}
{% block body %}
<div class="container mt-4">
<h1>Debug Labourage</h1>
<div class="alert alert-info">
<strong>Code INSEE demandé :</strong> {{ insee_code }}<br>
<strong>Code INSEE trouvé :</strong> {{ city_insee_found }}<br>
<strong>Nom de la ville trouvé :</strong> {{ city_name }}
</div>
{% if message %}
<div class="alert alert-warning">{{ message }}</div>
{% endif %}
<h3>Détails bruts de la ville trouvée :</h3>
<pre style="background:#222;color:#b5f;font-size:0.95em;padding:1em;border-radius:8px;overflow:auto;max-height:400px;">{{ city_debug|json_encode(constant('JSON_PRETTY_PRINT')) }}</pre>
{% if stats %}
<h3>Stats associées :</h3>
<pre style="background:#222;color:#b5f;font-size:0.95em;padding:1em;border-radius:8px;overflow:auto;max-height:400px;">{{ dump(stats) }}</pre>
{% endif %}
<a href="{{ path('app_admin_labourer', {'insee_code': insee_code, 'debug': 1}) }}" class="btn btn-primary mt-3">Rafraîchir debug</a>
<a href="{{ path('app_admin_stats', {'insee_code': insee_code}) }}" class="btn btn-secondary mt-3">Retour aux stats</a>
</div>
{% endblock %}

View file

@ -62,6 +62,54 @@
background: #388e3c; background: #388e3c;
border-color: #1b5e20; border-color: #1b5e20;
} }
.compact-theme-card {
transition: transform 0.2s ease-in-out;
}
.compact-theme-card:hover {
transform: translateY(-2px);
box-shadow: 0 4px 8px rgba(0,0,0,0.1) !important;
}
.theme-title a {
font-size: 0.85rem;
line-height: 1.2;
}
.theme-stats {
font-size: 0.75rem;
color: #6c757d;
}
.theme-actions .btn {
padding: 0.25rem 0.5rem;
font-size: 0.75rem;
}
.theme-row-scroll {
overflow-x: auto;
white-space: nowrap;
padding-bottom: 0.5rem;
}
.theme-row-scroll .col-auto {
display: inline-block;
float: none;
}
.theme-row-scroll .compact-theme-card {
display: inline-block;
vertical-align: top;
margin-right: 8px;
}
.tab-content {
margin-top: 1.5rem;
}
.table-theme th, .table-theme td {
vertical-align: middle;
font-size: 0.95em;
}
.table-theme th {
background: #f8f9fa;
}
</style> </style>
{% endblock %} {% endblock %}
@ -149,70 +197,179 @@
'healthcare': 'nwr["healthcare"](area.searchArea);nwr["amenity"="doctors"](area.searchArea);nwr["amenity"="pharmacy"](area.searchArea);nwr["amenity"="hospital"](area.searchArea);nwr["amenity"="clinic"](area.searchArea);nwr["amenity"="social_facility"](area.searchArea);' 'healthcare': 'nwr["healthcare"](area.searchArea);nwr["amenity"="doctors"](area.searchArea);nwr["amenity"="pharmacy"](area.searchArea);nwr["amenity"="hospital"](area.searchArea);nwr["amenity"="clinic"](area.searchArea);nwr["amenity"="social_facility"](area.searchArea);'
} %} } %}
<div class="row mb-4 latestFollowups "> {% set theme_groups = {
{% for type, data in latestFollowups %} 'emergency': ['fire_hydrant', 'defibrillator'],
{% set overpass_query = '[out:json][timeout:60];\narea["ref:INSEE"="' ~ stats.zone ~ '"]->.searchArea;\n(' ~ overpass_type_queries[type]|default('') ~ ');\n(._;>;);\nout meta;\n>;' %} 'transport': ['bus_stop', 'charging_station'],
{% set completion = data.completion is defined ? data.completion.getMeasure() : null %} 'healthcare': ['healthcare', 'laboratory'],
{% set completion_class = '' %} 'education': ['school'],
{% if completion is not null %} 'security': ['police', 'camera'],
{% if completion < 40 %} 'infrastructure': ['toilets', 'recycling', 'substation']
{% set completion_class = 'completion-low' %} } %}
{% elseif completion < 80 %}
{% set completion_class = 'completion-medium' %} <div class="row mb-4">
{% else %} <div class="col-12">
{% set completion_class = 'completion-high' %} <ul class="nav nav-tabs" id="themeTabs" role="tablist">
{% endif %} <li class="nav-item" role="presentation">
{% endif %} <button class="nav-link active" id="tab-table" data-bs-toggle="tab" data-bs-target="#tabTableContent" type="button" role="tab" aria-controls="tabTableContent" aria-selected="true">Tableau</button>
{% if data is defined and (data.count is defined or data.completion is defined) %} </li>
<div class="col-auto mb-2"> <li class="nav-item" role="presentation">
<div class="card shadow-sm text-center" style="min-width: 140px;"> <button class="nav-link" id="tab-cards" data-bs-toggle="tab" data-bs-target="#tabCardsContent" type="button" role="tab" aria-controls="tabCardsContent" aria-selected="false">Cartes</button>
<div class="card-body p-2"> </li>
<span class="completion-badge {{ completion_class }}"></span><br> </ul>
<i class="bi {{ followup_icons[type]|default('bi-question-circle') }} fs-2 mb-1"></i><br> <div class="tab-content" id="themeTabsContent">
<a href="http://127.0.0.1:8111/import?url=https://overpass-api.de/api/interpreter?data={{ overpass_query|url_encode }}" target="_blank" class="fw-bold text-decoration-underline text-dark" title="Charger dans JOSM">{{ followup_labels[type]|default(type|capitalize) }}</a><br> <div class="tab-pane fade show active" id="tabTableContent" role="tabpanel" aria-labelledby="tab-table">
<a href="{{ path('admin_followup_theme_graph', {'insee_code': stats.zone, 'theme': type}) }}" target="_blank" class="btn btn-sm btn-outline-primary mt-1" title="Voir le graphique"> <table class="table table-sm table-theme align-middle">
<i class="bi bi-graph-up"></i> <thead>
</a><br> <tr>
<span title="Nombre"> {{ data.count is defined ? data.count.getMeasure() : '?' }}</span><br> <th>Catégorie</th>
<span title="Complétion"> {{ completion is not null ? completion : '?' }}%</span> <th>Thème</th>
{% if progression7Days[type] is defined %} <th>Nombre</th>
{% set countDelta = progression7Days[type].count %} <th>Complétion</th>
{% set completionDelta = progression7Days[type].completion %} <th>Progression 7j</th>
{% if countDelta is not null or completionDelta is not null %} <th>Actions</th>
<small class="text-muted"> </tr>
{% if countDelta is not null %} </thead>
<span title="Progression sur 7 jours - Nombre d'objets"> <tbody>
{{ countDelta > 0 ? '+' ~ countDelta : countDelta == 0 ? '0' : countDelta }} {% for group_name, group_types in theme_groups %}
</span> {% for type in group_types %}
{% set data = latestFollowups[type]|default(null) %}
{% set completion = data and data.completion is defined ? data.completion.getMeasure() : null %}
{% set count = data and data.count is defined ? data.count.getMeasure() : null %}
{% set completion_class = '' %}
{% if completion is not null %}
{% if completion < 40 %}
{% set completion_class = 'completion-low' %}
{% elseif completion < 80 %}
{% set completion_class = 'completion-medium' %}
{% else %}
{% set completion_class = 'completion-high' %}
{% endif %} {% endif %}
{% if completionDelta is not null %} {% endif %}
<span title="Progression sur 7 jours - Complétion"> <tr>
{{ completionDelta > 0 ? '+' ~ completionDelta|round(1) : completionDelta == 0 ? '0' : completionDelta|round(1) }}% <td class="text-muted">
</span> {% if loop.first %}
{% if group_name == 'emergency' %}🚨 Urgence
{% elseif group_name == 'transport' %}🚌 Transport
{% elseif group_name == 'healthcare' %}🏥 Santé
{% elseif group_name == 'education' %}🎓 Éducation
{% elseif group_name == 'security' %}🛡️ Sécurité
{% elseif group_name == 'infrastructure' %}🏗️ Infrastructure
{% else %}{{ group_name|capitalize }}
{% endif %}
{% endif %}
</td>
<td>
<i class="bi {{ followup_icons[type]|default('bi-question-circle') }}"></i>
{{ followup_labels[type]|default(type|capitalize) }}
</td>
<td>{{ count is not null ? count : '?' }}</td>
<td><span class="completion-badge {{ completion_class }}"></span> {{ completion is not null ? completion ~ '%' : '?' }}</td>
<td>
{% if progression7Days[type] is defined %}
{% set countDelta = progression7Days[type].count %}
{% set completionDelta = progression7Days[type].completion %}
<span class="text-muted small">
{% if countDelta is not null %}
<span title="Progression sur 7 jours - Nombre d'objets">
{{ countDelta > 0 ? '+' ~ countDelta : countDelta == 0 ? '0' : countDelta }}
</span>
{% endif %}
{% if completionDelta is not null %}
<span title="Progression sur 7 jours - Complétion">
{{ completionDelta > 0 ? '+' ~ completionDelta|round(1) : completionDelta == 0 ? '0' : completionDelta|round(1) }}%
</span>
{% endif %}
</span>
{% endif %}
</td>
<td>
<a href="{{ path('admin_followup_theme_graph', {'insee_code': stats.zone, 'theme': type}) }}" target="_blank" class="btn btn-sm btn-outline-primary" title="Voir le graphique">
<i class="bi bi-graph-up"></i>
</a>
</td>
</tr>
{% endfor %}
{% endfor %}
</tbody>
</table>
</div>
<div class="tab-pane fade" id="tabCardsContent" role="tabpanel" aria-labelledby="tab-cards">
{% for group_name, group_types in theme_groups %}
<div class="mb-2">
<div class="mb-1 text-muted">
{% if group_name == 'emergency' %}🚨 Urgence
{% elseif group_name == 'transport' %}🚌 Transport
{% elseif group_name == 'healthcare' %}🏥 Santé
{% elseif group_name == 'education' %}🎓 Éducation
{% elseif group_name == 'security' %}🛡️ Sécurité
{% elseif group_name == 'infrastructure' %}🏗️ Infrastructure
{% else %}{{ group_name|capitalize }}
{% endif %}
</div>
<div class="theme-row-scroll">
{% for type in group_types %}
{% set data = latestFollowups[type]|default(null) %}
{% set overpass_query = '[out:json][timeout:60];\narea["ref:INSEE"="' ~ stats.zone ~ '"]->.searchArea;\n(' ~ overpass_type_queries[type]|default('') ~ ');\n(._;>;);\nout meta;\n>;' %}
{% set completion = data and data.completion is defined ? data.completion.getMeasure() : null %}
{% set completion_class = '' %}
{% if completion is not null %}
{% if completion < 40 %}
{% set completion_class = 'completion-low' %}
{% elseif completion < 80 %}
{% set completion_class = 'completion-medium' %}
{% else %}
{% set completion_class = 'completion-high' %}
{% endif %}
{% endif %} {% endif %}
</small> <div class="col-auto">
{% endif %} <div class="card shadow-sm text-center compact-theme-card" style="min-width: 120px; max-width: 140px;">
{% endif %} <div class="card-body p-2">
</div> <div class="d-flex align-items-center justify-content-between mb-1">
<span class="completion-badge {{ completion_class }}"></span>
<i class="bi {{ followup_icons[type]|default('bi-question-circle') }} fs-4"></i>
</div>
<div class="theme-title mb-1">
<a href="http://127.0.0.1:8111/import?url=https://overpass-api.de/api/interpreter?data={{ overpass_query|url_encode }}" target="_blank" class="fw-bold text-decoration-none text-dark small" title="Charger dans JOSM">
{{ followup_labels[type]|default(type|capitalize) }}
</a>
</div>
<div class="theme-stats small">
<span title="Nombre">{{ data and data.count is defined ? data.count.getMeasure() : '?' }}</span> |
<span title="Complétion">{{ completion is not null ? completion : '?' }}%</span>
</div>
<div class="theme-actions mt-1">
<a href="{{ path('admin_followup_theme_graph', {'insee_code': stats.zone, 'theme': type}) }}" target="_blank" class="btn btn-sm btn-outline-primary btn-sm" title="Voir le graphique">
<i class="bi bi-graph-up"></i>
</a>
</div>
{% if progression7Days[type] is defined %}
{% set countDelta = progression7Days[type].count %}
{% set completionDelta = progression7Days[type].completion %}
{% if countDelta is not null or completionDelta is not null %}
<small class="text-muted d-block mt-1">
{% if countDelta is not null %}
<span title="Progression sur 7 jours - Nombre d'objets">
{{ countDelta > 0 ? '+' ~ countDelta : countDelta == 0 ? '0' : countDelta }}
</span>
{% endif %}
{% if completionDelta is not null %}
<span title="Progression sur 7 jours - Complétion">
{{ completionDelta > 0 ? '+' ~ completionDelta|round(1) : completionDelta == 0 ? '0' : completionDelta|round(1) }}%
</span>
{% endif %}
</small>
{% endif %}
{% endif %}
</div>
</div>
</div>
{% endfor %}
</div>
</div>
{% endfor %}
</div> </div>
</div> </div>
{% else %} </div>
<div class="col-auto mb-2">
<div class="card shadow-sm text-center bg-light text-muted" style="min-width: 140px;">
<div class="card-body p-2">
<span class="completion-badge" style="background:#eee;"></span><br>
<i class="bi bi-question-circle fs-2 mb-1"></i><br>
<span class="fw-bold">{{ followup_labels[type]|default(type|capitalize) }}</span><br>
<a href="{{ path('admin_followup_theme_graph', {'insee_code': stats.zone, 'theme': type}) }}" target="_blank" class="btn btn-sm btn-outline-secondary mt-1" title="Voir le graphique">
<i class="bi bi-graph-up"></i> Graphique
</a><br>
<span title="Nombre">N = ?</span><br>
<span title="Complétion">?%</span>
</div>
</div>
</div>
{% endif %}
{% endfor %}
</div> </div>
</div> </div>

View file

@ -0,0 +1,31 @@
{% extends 'base.html.twig' %}
{% block title %}Test Complète tes commerces{% endblock %}
{% block body %}
<div class="container mt-4">
<h1>Test Complète tes commerces</h1>
<form method="get" action="{{ path('admin_test_ctc', {'insee_code': ''}) }}" class="row g-3 mb-4">
<div class="col-auto">
<input type="text" name="insee_code" class="form-control" placeholder="Code INSEE" value="{{ insee_code|default('') }}" required pattern="\\d+">
</div>
<div class="col-auto">
<button type="submit" class="btn btn-primary">Tester</button>
</div>
</form>
{% if url %}
<div class="mb-3">
<strong>URL CTC :</strong> <a href="{{ url }}" target="_blank">{{ url }}</a>
</div>
{% endif %}
{% if error %}
<div class="alert alert-danger">{{ error }}</div>
{% endif %}
{% if json %}
<h3>JSON reçu :</h3>
<pre style="background:#222;color:#b5f;font-size:0.95em;padding:1em;border-radius:8px;overflow:auto;max-height:600px;">{{ json|json_decode(constant('JSON_OBJECT_AS_ARRAY'))|json_encode(constant('JSON_PRETTY_PRINT')) }}</pre>
{% elseif url and not error %}
<div class="alert alert-warning">Aucune donnée reçue.</div>
{% endif %}
</div>
{% endblock %}

View file

@ -1,3 +1,52 @@
<style>
.suggestion-list {
position: absolute;
background: #fff;
border: 1px solid #ced4da;
border-radius: 0.5rem;
box-shadow: 0 4px 16px rgba(0,0,0,0.08);
max-height: 260px;
overflow-y: auto;
width: 100%;
z-index: 1050;
margin-top: 2px;
display: none;
padding: 0;
}
.suggestion-item {
padding: 0.75rem 1rem;
cursor: pointer;
border-bottom: 1px solid #f1f3f4;
background: #fff;
transition: background 0.15s;
font-size: 1rem;
display: flex;
align-items: center;
}
.suggestion-item:last-child {
border-bottom: none;
}
.suggestion-item:hover, .suggestion-item.active {
background: #e9ecef;
color: #212529;
}
.suggestion-name {
font-weight: 500;
color: #0d6efd;
margin-right: 0.5em;
}
.suggestion-details {
font-size: 0.95em;
color: #6c757d;
}
.suggestion-type {
margin-right: 8px;
color: #adb5bd;
font-size: 1.1em;
}
.search-container { position: relative; }
</style>
<div class="row mt-4 labourer-form-container" id="labourerFormContainer"> <div class="row mt-4 labourer-form-container" id="labourerFormContainer">
<div class="col-12"> <div class="col-12">
<div class="card"> <div class="card">