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.
This commit is contained in:
@@ -830,7 +830,8 @@ pub const QUERY_PROCESS_EXPIRED_AND_FILL: &str = r#"
|
|||||||
dt.office_type_id,
|
dt.office_type_id,
|
||||||
dt.region_id,
|
dt.region_id,
|
||||||
c.character_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
|
FROM distinct_types AS dt
|
||||||
JOIN falukant_data.election AS e
|
JOIN falukant_data.election AS e
|
||||||
ON e.office_type_id = dt.office_type_id
|
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
|
JOIN falukant_data.candidate AS c
|
||||||
ON c.election_id = e.id
|
ON c.election_id = e.id
|
||||||
AND c.id = v.candidate_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')
|
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 (
|
ranked_winners AS (
|
||||||
SELECT
|
SELECT
|
||||||
@@ -849,7 +852,7 @@ pub const QUERY_PROCESS_EXPIRED_AND_FILL: &str = r#"
|
|||||||
vpc.character_id,
|
vpc.character_id,
|
||||||
ROW_NUMBER() OVER (
|
ROW_NUMBER() OVER (
|
||||||
PARTITION BY vpc.office_type_id, vpc.region_id
|
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
|
) AS rn
|
||||||
FROM votes_per_candidate AS vpc
|
FROM votes_per_candidate AS vpc
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user