add measure on checking advanced graph

This commit is contained in:
Tykayn 2025-08-12 11:58:11 +02:00 committed by tykayn
parent 46f8b3f6ab
commit 1659864efb
3 changed files with 133 additions and 32 deletions

View file

@ -527,6 +527,77 @@
if (average_completion && current_completion) {
current_completion.textContent = average_completion.toFixed(2) + ' %';
}
// Send measurement to /api/city-followup
const insee_code = '{{ stats.zone }}';
const theme = '{{ theme }}';
// Prepare data for the API request
const measureData = new FormData();
measureData.append('insee_code', insee_code);
measureData.append('measure_label', theme + '_count');
measureData.append('measure_value', count_objects);
// Send count measurement
fetch('/api/city-followup', {
method: 'POST',
body: measureData
})
.then(response => response.json())
.then(result => {
console.log('Count measurement saved:', result);
if (result.success) {
// Add the new measurement to the chart data
const newMeasurement = {
date: result.follow_up.date,
value: result.follow_up.measure
};
// Add to the global countData array
if (Array.isArray(window.countData)) {
window.countData.push(newMeasurement);
// Update the chart
updateChart();
}
}
})
.catch(error => {
console.error('Error saving count measurement:', error);
});
// Send completion measurement
if (average_completion) {
const completionData = new FormData();
completionData.append('insee_code', insee_code);
completionData.append('measure_label', theme + '_completion');
completionData.append('measure_value', average_completion);
fetch('/api/city-followup', {
method: 'POST',
body: completionData
})
.then(response => response.json())
.then(result => {
console.log('Completion measurement saved:', result);
if (result.success) {
// Add the new measurement to the chart data
const newMeasurement = {
date: result.follow_up.date,
value: result.follow_up.measure
};
// Add to the global completionData array
if (Array.isArray(window.completionData)) {
window.completionData.push(newMeasurement);
// Update the chart
updateChart();
}
}
})
.catch(error => {
console.error('Error saving completion measurement:', error);
});
}
const tbody = document.querySelector('#tags-stats-table tbody');
if (Object.keys(tagCounts).length === 0) {
tbody.innerHTML = '<tr><td colspan="2" class="text-muted">Aucun tag trouvé</td></tr>';
@ -551,8 +622,9 @@
const countData = {{ count_data|json_encode|raw }};
console.log('Count data:', countData);
window.countData = countData
window.countData = countData;
const completionData = {{ completion_data|json_encode|raw }};
window.completionData = completionData;
console.log('Completion data:', completionData);
// Current metrics from server
@ -694,6 +766,28 @@
}
});
// Function to update the chart with new data
function updateChart() {
// Get the chart instance
const chartInstance = Chart.getChart('themeChart');
if (!chartInstance) return;
// Update the datasets
chartInstance.data.datasets[0].data = Array.isArray(window.countData)
? window.countData.map(d => ({x: new Date(d.date), y: d.value}))
: [];
if (Array.isArray(window.completionData)) {
chartInstance.data.datasets[1].data = window.completionData.map(d => ({
x: new Date(d.date),
y: d.value
}));
}
// Update the chart
chartInstance.update();
}
// Initialiser les statistiques
updateStats();