From a4d57d796156995cec28edbd9e69eb2889bda6ac Mon Sep 17 00:00:00 2001 From: Gwadaking Date: Fri, 10 Apr 2026 00:30:55 -0400 Subject: [PATCH] =?UTF-8?q?fix:=20s=C3=A9lectionner=20l'observation=20la?= =?UTF-8?q?=20plus=20proche=20(pas=20la=20plus=20r=C3=A9cente)=20pour=20pa?= =?UTF-8?q?tches=20et=20horizons?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Les subqueries de loadHorizonScores() et loadPatches() triaient par detected_at DESC, ce qui provoquait une contamination inter-zones : une ingestion récente de Guadeloupe avec des patches à ~189km de la Barbade écrasait les données locales pourtant plus proches. Aligner sur la logique de loadLatestScore() (ImpactScoreService) qui trie déjà par ST_Distance ASC — les 3 sources (score now, patches, horizons) utilisent maintenant la même observation de référence. Co-Authored-By: Claude Sonnet 4.6 --- backend/src/Controller/SpotScoreController.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/backend/src/Controller/SpotScoreController.php b/backend/src/Controller/SpotScoreController.php index fc89a6d..672b8a4 100644 --- a/backend/src/Controller/SpotScoreController.php +++ b/backend/src/Controller/SpotScoreController.php @@ -121,7 +121,9 @@ class SpotScoreController extends AbstractController coastal_point cp3 WHERE cp3.id = :spotId AND ST_Distance(o2.geometry::geography, cp3.geometry::geography) < 300000 - ORDER BY o2.detected_at DESC LIMIT 1 + ORDER BY ST_Distance(o2.geometry::geography, cp3.geometry::geography) ASC, + o2.detected_at DESC + LIMIT 1 ) ORDER BY f.time_horizon ASC', ['spotId' => $spotId] @@ -243,7 +245,9 @@ class SpotScoreController extends AbstractController coastal_point cp3 WHERE cp3.id = :spotId AND ST_Distance(o2.geometry::geography, cp3.geometry::geography) < 300000 - ORDER BY o2.detected_at DESC LIMIT 1 + ORDER BY ST_Distance(o2.geometry::geography, cp3.geometry::geography) ASC, + o2.detected_at DESC + LIMIT 1 ) ) dump WHERE cp.id = :spotId