fix: calculer ETA depuis horizons API — évite dépendance aux données stale en base

This commit is contained in:
Gwadaking
2026-04-03 19:35:21 -04:00
parent 22a3ce23a4
commit 878174404e
4 changed files with 778 additions and 2 deletions

View File

@@ -12,6 +12,17 @@ const TREND_CONFIG = {
decreasing: { icon: '📉', label: 'Amélioration en cours', cls: 'trend--good' },
};
const ETA_BUFFER_KM = 5;
function computeEta(score, horizons) {
if (score?.distance != null && score.distance < ETA_BUFFER_KM) return 0;
for (const h of [6, 12, 24, 48]) {
const horizon = horizons?.[`h${h}`];
if (horizon?.distanceKm != null && horizon.distanceKm < ETA_BUFFER_KM) return h;
}
return null;
}
function etaLabel(etaHours) {
if (etaHours === 0) return { icon: '🚨', label: 'Impact en cours', cls: 'eta--now' };
if (etaHours === 6) return { icon: '⚠️', label: 'Impact prévu dans ~6h', cls: 'eta--soon' };
@@ -82,7 +93,7 @@ export default function SpotPanel({ spot, activeStep, onClose }) {
: (
<>
{activeStep === 'now' && (() => {
const eta = etaLabel(displayScore.etaHours ?? undefined);
const eta = etaLabel(computeEta(data?.score, data?.horizons));
return (
<div className={`spot-panel__eta ${eta.cls}`}>
<span className="spot-panel__eta-icon">{eta.icon}</span>