From 9175f63e3969bcc8bdba593187b88969d77391ca Mon Sep 17 00:00:00 2001 From: Gwadaking Date: Thu, 9 Apr 2026 00:57:30 -0400 Subject: [PATCH] =?UTF-8?q?fix:=20distance=20sargasses=20=3D=20min(patches?= =?UTF-8?q?)=20live=20ST=5FDump,=20plus=20fiable=20que=20la=20valeur=20sto?= =?UTF-8?q?ck=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/Controller/SpotScoreController.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/backend/src/Controller/SpotScoreController.php b/backend/src/Controller/SpotScoreController.php index 2d240f8..fc89a6d 100644 --- a/backend/src/Controller/SpotScoreController.php +++ b/backend/src/Controller/SpotScoreController.php @@ -49,6 +49,16 @@ class SpotScoreController extends AbstractController $current = $this->scoreService->getCachedScore($id); } + $patches = $this->loadPatches($id); + + // La distance issue des patches (ST_Dump live) est plus fiable que + // distance_to_nearest_sargassum stockée (peut venir d'une obs lointaine). + // On l'utilise comme référence si des patches sont détectés à proximité. + if ($current !== null && !empty($patches)) { + $minPatchDist = min(array_column($patches, 'distanceKm')); + $current['distance'] = $minPatchDist; + } + $currentDistanceKm = $current !== null ? $current['distance'] : null; return $this->json([ @@ -57,7 +67,7 @@ class SpotScoreController extends AbstractController 'type' => $spot->getType(), 'region' => $spot->getRegion(), 'score' => $current, - 'patches' => $this->loadPatches($id), + 'patches' => $patches, 'horizons' => $this->loadHorizonScores($id, $currentDistanceKm), ]); }