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

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -8,7 +8,7 @@
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Fredoka+One&family=Fredoka:wght@400;500;600&display=swap" rel="stylesheet">
<script type="module" crossorigin src="/assets/index-DJWsPHf5.js"></script>
<script type="module" crossorigin src="/assets/index-Ds68dQUk.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-D676BouX.css">
</head>
<body>

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>