fix: calculer ETA depuis horizons API — évite dépendance aux données stale en base
This commit is contained in:
9
backend/public/assets/index-Ds68dQUk.js
Normal file
9
backend/public/assets/index-Ds68dQUk.js
Normal file
File diff suppressed because one or more lines are too long
756
backend/public/assets/maplibre-gl-PkidZdV8.js
Normal file
756
backend/public/assets/maplibre-gl-PkidZdV8.js
Normal file
File diff suppressed because one or more lines are too long
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user