tests liens ctc

This commit is contained in:
Tykayn 2025-07-05 15:25:33 +02:00 committed by tykayn
parent 6f3d19245e
commit 2fd0d8d933
3 changed files with 315 additions and 78 deletions

View file

@ -4,6 +4,7 @@
{% block stylesheets %}
{{ parent() }}
<link href='{{ asset('js/maplibre/maplibre-gl.css') }}' rel='stylesheet'/>
<style>
.chart-container {
width: 100%;
@ -87,11 +88,48 @@
.chart-content.active {
display: block;
}
#themeMap {
height: 400px;
width: 100%;
border-radius: 8px;
margin-bottom: 1.5rem;
}
.maplibregl-popup-content {
font-size: 0.95em;
}
.btn-josm {
margin-bottom: 1rem;
}
</style>
{% endblock %}
{% block body %}
<div class="container-fluid">
{# DEBUG : Affichage des objets Place trouvés pour cette ville #}
{% if places is defined %}
<div class="alert alert-warning" style="font-size:0.95em;">
<b>DEBUG : Objets Place trouvés pour cette ville (avant filtrage)</b><br>
<table class="table table-sm table-bordered mt-2 mb-0">
<thead><tr>
<th>#</th><th>id</th><th>main_tag</th><th>osm_kind</th><th>nom</th><th>lat</th><th>lon</th>
</tr></thead>
<tbody>
{% for p in places %}
<tr>
<td>{{ loop.index }}</td>
<td>{{ p.getOsmId() }}</td>
<td>{{ p.getMainTag() }}</td>
<td>{{ p.getOsmKind() }}</td>
<td>{{ p.getName() }}</td>
<td>{{ p.getLat() }}</td>
<td>{{ p.getLon() }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endif %}
<div class="stats-header">
<div class="d-flex justify-content-between align-items-start">
<div>
@ -125,6 +163,15 @@
</a>
</div>
{% if josm_url %}
<a href="{{ josm_url }}" class="btn btn-outline-dark btn-josm" target="_blank">
<i class="bi bi-box-arrow-up-right"></i> Ouvrir tous les objets dans JOSM
</a>
{% else %}
<div class="alert alert-info mb-3">Aucun objet sélectionné pour ce thème, rien à charger dans JOSM.</div>
{% endif %}
<div id="themeMap"></div>
<div class="stats-grid">
<div class="stat-card">
<div class="stat-value" id="currentCount">-</div>
@ -165,6 +212,65 @@
{% block javascripts %}
{{ parent() }}
<script src='{{ asset('js/maplibre/maplibre-gl.js') }}'></script>
<script>
const geojson = {{ geojson|raw }};
const mapToken = '{{ maptiler_token }}';
const mapCenter = {{ center|json_encode|raw }};
document.addEventListener('DOMContentLoaded', function() {
console.log('[DEBUG] mapToken:', mapToken);
console.log('[DEBUG] geojson:', geojson);
console.log('[DEBUG] geojson.features:', geojson ? geojson.features : undefined);
console.log('[DEBUG] mapCenter:', mapCenter);
if (mapToken && geojson && geojson.features && geojson.features.length > 0) {
console.log('[DEBUG] Initialisation de la carte Maplibre...');
const map = new maplibregl.Map({
container: 'themeMap',
style: `https://api.maptiler.com/maps/streets/style.json?key=${mapToken}`,
center: mapCenter || geojson.features[0].geometry.coordinates,
zoom: 13
});
map.addControl(new maplibregl.NavigationControl());
geojson.features.forEach(f => {
let color = f.properties.is_complete ? '#198754' : '#adb5bd';
if (!f.properties.is_complete && (f.properties.tags && (f.properties.tags.name || f.properties.tags.operator))) {
color = '#ffc107'; // partiel
}
const marker = new maplibregl.Marker({ color: color })
.setLngLat(f.geometry.coordinates)
.setPopup(new maplibregl.Popup({ offset: 18 })
.setHTML(`
<div style='min-width:180px'>
<strong>${f.properties.name || '(sans nom)'}</strong><br>
<span class='text-muted'>${f.properties.osm_kind} ${f.properties.id}</span><br>
<span style='font-size:0.95em;'>
${Object.entries(f.properties.tags).map(([k,v]) => `<span><b>${k}</b>: ${v}</span>`).join('<br>')}
</span>
<a href='${f.properties.osm_url}' target='_blank'>Voir sur OSM</a>
</div>
`)
)
.addTo(map);
});
} else {
console.warn('[DEBUG] Carte non initialisée : conditions non remplies.');
if (!mapToken) {
console.warn('[DEBUG] mapToken manquant ou vide');
}
if (!geojson) {
console.warn('[DEBUG] geojson manquant ou vide');
}
if (!geojson || !geojson.features || geojson.features.length === 0) {
console.warn('[DEBUG] geojson.features vide ou non défini');
}
// Affichage d'un message dans la page
const mapDiv = document.getElementById('themeMap');
if (mapDiv) {
mapDiv.innerHTML = '<div style="color:red;font-weight:bold;padding:2em;text-align:center;">Carte non initialisée : données manquantes ou incomplètes (voir console pour debug)</div>';
}
}
});
</script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-date-fns/dist/chartjs-adapter-date-fns.bundle.min.js"></script>

View file

@ -218,14 +218,12 @@
</ul>
<div class="tab-content" id="themeTabsContent">
<div class="tab-pane fade show active" id="tabTableContent" role="tabpanel" aria-labelledby="tab-table">
<table class="table table-sm table-theme align-middle">
<table class="table table-theme">
<thead>
<tr>
<th>Catégorie</th>
<th>Thème</th>
<th>Nombre</th>
<th>Complétion</th>
<th>Progression 7j</th>
<th>Actions</th>
</tr>
</thead>
@ -294,79 +292,51 @@
</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 }}
{% set all_types = followup_labels|keys %}
<div class="row">
{% for type in all_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 %}
</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 %}
<div class="col-auto">
<div class="card shadow-sm text-center compact-theme-card" style="min-width: 120px; max-width: 140px;">
<div class="card-body p-2">
<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>
{% endif %}
<div class="col-auto">
<div class="card shadow-sm text-center compact-theme-card" style="min-width: 120px; max-width: 140px;">
<div class="card-body p-2">
<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="https://overpass-api.de/api/interpreter?data={{ overpass_query|url_encode }}" target="_blank" class="fw-bold text-decoration-none text-dark small" title="Voir le JSON Overpass">
{{ 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>
<a href="http://127.0.0.1:8111/import?url=https://overpass-api.de/api/interpreter?data={{ overpass_query|url_encode }}" target="_blank" class="btn btn-sm btn-outline-dark btn-sm ms-1" title="Ouvrir dans JOSM">
<i class="bi bi-box-arrow-up-right"></i> JOSM
</a>
</div>
</div>
{% endfor %}
</div>
</div>
</div>
{% endfor %}
{% endfor %}
</div>
</div>
</div>
</div>
@ -603,6 +573,48 @@
</div>
</div>
<!-- Espace de dump JSON -->
<div id="ctc-json-dump-container" class="mt-4" style="display:none;">
<div class="card">
<div class="card-header p-2">
<i class="bi bi-file-earmark-code"></i> Dump du JSON récupéré
</div>
<div class="card-body p-2">
<pre id="ctc-json-dump" style="max-height:400px;overflow:auto;"></pre>
</div>
</div>
</div>
<div class="mt-3 ctc-tests">
<div class="card ctc-tests">
<div class="card-header p-2">
<i class="bi bi-link-45deg"></i> Tester les JSON Complète tes commerces
</div>
<div class="card-body p-2">
<ul class="mb-0" style="font-size:0.95em;">
{% set ctc_jsons = stats.getAllCTCUrlsMap() %}
{% for key, url in ctc_jsons %}
<li><a href="{{ url }}" target="_blank" rel="noopener">{{ key }}</a></li>
{% endfor %}
</ul>
<div class="mt-3">
<div class="input-group">
<select id="ctc-json-select" class="form-select">
<option value="">Choisir un JSON à tester…</option>
{% for key, url in ctc_jsons %}
<option value="{{ url }}">{{ key }}</option>
{% endfor %}
</select>
<button id="ctc-json-test-btn" class="btn btn-outline-primary" type="button">
<i class="bi bi-bug"></i> Tester l'accès JSON CTC
</button>
</div>
</div>
</div>
</div>
</div>
<div id="ctc-json-error" class="alert alert-danger mt-4" style="display:none;"></div>
{% endblock %}
@ -1048,4 +1060,35 @@ if(dc ){
});
});
</script>
<script>
document.addEventListener('DOMContentLoaded', function() {
const btn = document.getElementById('ctc-json-test-btn');
const select = document.getElementById('ctc-json-select');
const dumpContainer = document.getElementById('ctc-json-dump-container');
const dump = document.getElementById('ctc-json-dump');
const error = document.getElementById('ctc-json-error');
if(btn && select) {
btn.addEventListener('click', function() {
const url = select.value;
dumpContainer.style.display = 'none';
error.style.display = 'none';
dump.textContent = '';
if(!url) return;
fetch(url)
.then(r => {
if(!r.ok) throw new Error('Erreur HTTP ' + r.status);
return r.json();
})
.then(data => {
dump.textContent = JSON.stringify(data, null, 2);
dumpContainer.style.display = '';
})
.catch(e => {
error.textContent = 'Erreur lors de la récupération du JSON : ' + e.message;
error.style.display = '';
});
});
}
});
</script>
{% endblock %}