From a82d554494bcd5c1ec79eddc5ef51418109b6615 Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Sat, 20 Dec 2025 23:06:51 +0100 Subject: [PATCH] Enhance SQL query in Worker to include character reputation: Add COALESCE for reputation in the vote count query and adjust the GROUP BY and ORDER BY clauses to incorporate reputation, improving data accuracy in election results. --- src/worker/sql.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/worker/sql.rs b/src/worker/sql.rs index 272a4ec..2052068 100644 --- a/src/worker/sql.rs +++ b/src/worker/sql.rs @@ -830,7 +830,8 @@ pub const QUERY_PROCESS_EXPIRED_AND_FILL: &str = r#" dt.office_type_id, dt.region_id, c.character_id, - COUNT(v.id) AS vote_count + COUNT(v.id) AS vote_count, + COALESCE(ch.reputation, 0) AS reputation FROM distinct_types AS dt JOIN falukant_data.election AS e ON e.office_type_id = dt.office_type_id @@ -839,8 +840,10 @@ pub const QUERY_PROCESS_EXPIRED_AND_FILL: &str = r#" JOIN falukant_data.candidate AS c ON c.election_id = e.id AND c.id = v.candidate_id + JOIN falukant_data."character" AS ch + ON ch.id = c.character_id WHERE e.date >= (NOW() - INTERVAL '30 days') - GROUP BY dt.office_type_id, dt.region_id, c.character_id + GROUP BY dt.office_type_id, dt.region_id, c.character_id, ch.reputation ), ranked_winners AS ( SELECT @@ -849,7 +852,7 @@ pub const QUERY_PROCESS_EXPIRED_AND_FILL: &str = r#" vpc.character_id, ROW_NUMBER() OVER ( PARTITION BY vpc.office_type_id, vpc.region_id - ORDER BY vpc.vote_count DESC + ORDER BY vpc.vote_count DESC, vpc.reputation DESC, vpc.character_id ASC ) AS rn FROM votes_per_candidate AS vpc ),