Changes between Version 2 and Version 3 of UserLeaderboard
- Timestamp:
- 01/29/26 03:49:49 (10 days ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
UserLeaderboard
v2 v3 11 11 12 12 {{{ 13 CREATE 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 23 AS $$ 13 24 WITH build_stats AS ( 14 SELECT 25 SELECT 15 26 b.id AS build_id, 16 27 b.user_id, … … 18 29 AVG(rb.value) AS avg_rating 19 30 FROM build b 20 LEFT JOIN favorite_build fb ON b.id = fb.build_id21 LEFT JOIN rating_build rb ON b.id = rb.build_id31 LEFT JOIN favorite_build fb ON b.id = fb.build_id 32 LEFT JOIN rating_build rb ON b.id = rb.build_id 22 33 WHERE b.is_approved = TRUE 23 34 GROUP BY b.id, b.user_id 24 35 ), 25 user_stats AS (26 SELECT27 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_received31 FROM build_stats32 GROUP BY user_id33 )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 ) 34 45 SELECT 35 46 u.username, … … 37 48 us.approved_builds_count, 38 49 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, 40 51 ( 41 52 (us.approved_builds_count * 10) + 42 53 (us.total_favorites_received * 5) + 43 ( us.avg_rating_received* 20)44 ) AS reputation_score54 (COALESCE(us.avg_rating_received, 0) * 20) 55 ) AS reputation_score 45 56 FROM user_stats us 46 JOIN users u ON u.id = us.user_id57 JOIN users u ON u.id = us.user_id 47 58 ORDER BY reputation_score DESC 48 59 LIMIT 10; 60 $$; 49 61 }}} 50 62
