Changes between Version 2 and Version 3 of UserLeaderboard


Ignore:
Timestamp:
01/29/26 03:49:49 (10 days ago)
Author:
233051
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • UserLeaderboard

    v2 v3  
    1111
    1212{{{
     13CREATE OR REPLACE FUNCTION get_report_user_reputation_leaderboard()
     14    RETURNS TABLE (
     15                      username TEXT,
     16                      email TEXT,
     17                      approved_builds_count BIGINT,
     18                      total_favorites_received BIGINT,
     19                      avg_rating_received NUMERIC,
     20                      reputation_score NUMERIC
     21                  )
     22    LANGUAGE sql
     23AS $$
    1324WITH build_stats AS (
    14     SELECT 
     25    SELECT
    1526        b.id AS build_id,
    1627        b.user_id,
     
    1829        AVG(rb.value) AS avg_rating
    1930    FROM build b
    20     LEFT JOIN favorite_build fb ON b.id = fb.build_id
    21     LEFT JOIN rating_build rb ON b.id = rb.build_id
     31             LEFT JOIN favorite_build fb ON b.id = fb.build_id
     32             LEFT JOIN rating_build rb ON b.id = rb.build_id
    2233    WHERE b.is_approved = TRUE
    2334    GROUP BY b.id, b.user_id
    2435),
    25 user_stats AS (
    26     SELECT
    27         user_id,
    28         COUNT(build_id) AS approved_builds_count,
    29         SUM(favorites_count) AS total_favorites_received,
    30         AVG(avg_rating) AS avg_rating_received
    31     FROM build_stats
    32     GROUP BY user_id
    33 )
     36     user_stats AS (
     37         SELECT
     38             user_id,
     39             COUNT(build_id) AS approved_builds_count,
     40             COALESCE(SUM(favorites_count), 0) AS total_favorites_received,
     41             AVG(avg_rating) AS avg_rating_received
     42         FROM build_stats
     43         GROUP BY user_id
     44     )
    3445SELECT
    3546    u.username,
     
    3748    us.approved_builds_count,
    3849    us.total_favorites_received,
    39     ROUND(us.avg_rating_received, 2) AS avg_rating_received,
     50    ROUND(CAST(COALESCE(us.avg_rating_received, 0) AS numeric), 2) AS avg_rating_received,
    4051    (
    4152        (us.approved_builds_count * 10) +
    4253        (us.total_favorites_received * 5) +
    43         (us.avg_rating_received * 20)
    44     ) AS reputation_score
     54        (COALESCE(us.avg_rating_received, 0) * 20)
     55        ) AS reputation_score
    4556FROM user_stats us
    46 JOIN users u ON u.id = us.user_id
     57         JOIN users u ON u.id = us.user_id
    4758ORDER BY reputation_score DESC
    4859LIMIT 10;
     60$$;
    4961}}}
    5062