feat: suivre la température pendant les tournées

This commit is contained in:
Alexandre NOEL 2026-09-15 15:43:00 +02:00
commit d35434c522
15 changed files with 129 additions and 23 deletions

View file

@ -944,25 +944,47 @@ $currentTime = date('H:i');
</script>
<script>
(function() {
const el = document.getElementById('weightChart');
const el = document.getElementById('healthMeasurementsChart');
if (!el) return;
const rows = <?= json_encode($weights ?? [], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) ?> ;
const weights = <?= json_encode($weights ?? [], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) ?>;
const temperatures = <?= json_encode($temperatures ?? [], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) ?>;
const normalizeDate = value => String(value || '').replace(' ', 'T');
const labels = [...new Set([
...weights.map(row => normalizeDate(row.measured_at)),
...temperatures.map(row => normalizeDate(row.measured_at))
])].filter(Boolean).sort();
const valuesByDate = rows => new Map(rows.map(row => [normalizeDate(row.measured_at), Number(row.value)]));
const weightValues = valuesByDate(weights);
const temperatureValues = valuesByDate(temperatures);
// labels = dates, data = poids
const labels = rows.map(r => (r.measured_at || '').slice(0, 10)); // YYYY-MM-DD
const data = rows.map(r => Number(r.value));
// Chart.js default color (on ne fixe rien volontairement)
new Chart(el, {
type: 'line',
data: {
labels,
datasets: [{
labels: labels.map(value => new Date(value).toLocaleString(undefined, {
dateStyle: 'short',
timeStyle: 'short'
})),
datasets: [
{
label: <?= json_encode(t('chart.weight'), JSON_UNESCAPED_UNICODE) ?> ,
data,
data: labels.map(label => weightValues.get(label) ?? null),
borderColor: '#206bc4',
backgroundColor: '#206bc4',
tension: 0.25,
pointRadius: 2
pointRadius: 3,
spanGaps: true,
yAxisID: 'weight'
},
{
label: <?= json_encode(t('chart.temperature'), JSON_UNESCAPED_UNICODE) ?>,
data: labels.map(label => temperatureValues.get(label) ?? null),
borderColor: '#d63939',
backgroundColor: '#d63939',
tension: 0.25,
pointRadius: 3,
spanGaps: true,
yAxisID: 'temperature'
}]
},
options: {
@ -974,12 +996,25 @@ $currentTime = date('H:i');
}
},
scales: {
y: {
weight: {
type: 'linear',
position: 'left',
title: {
display: true,
text: 'kg'
}
},
temperature: {
type: 'linear',
position: 'right',
grid: {
drawOnChartArea: false
},
title: {
display: true,
text: '°C'
}
},
x: {
title: {
display: true,