fix(evolver): correct GROUP BY in island stats query

b.bot_id was selected without being in the GROUP BY clause or wrapped
in an aggregate, causing a Postgres error on live export. Replaced with
a correlated subquery that finds the highest-rated bot per island.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
jedarden 2026-04-24 07:04:37 -04:00
parent 9771c5dd00
commit 9c5eb57fdd

View file

@ -187,7 +187,14 @@ func fillIslandStats(ctx context.Context, db *sql.DB, data *LiveData) error {
SELECT p.island,
COUNT(*) AS population,
COALESCE(MAX(b.rating_mu - 2*b.rating_phi), 0) AS best_rating,
COALESCE(b.bot_id, '') AS best_bot_id
COALESCE(
(SELECT p2.bot_id FROM programs p2
LEFT JOIN bots b2 ON p2.bot_id = b2.bot_id
WHERE p2.island = p.island
ORDER BY COALESCE(b2.rating_mu - 2*b2.rating_phi, 0) DESC
LIMIT 1),
''
) AS best_bot_id
FROM programs p
LEFT JOIN bots b ON p.bot_id = b.bot_id
GROUP BY p.island`)