Changes between Initial Version and Version 1 of UserLeaderboard


Ignore:
Timestamp:
01/27/26 23:47:47 (12 days ago)
Author:
233051
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • UserLeaderboard

    v1 v1  
     1= Complex DB Reports (SQL, Stored Procedures, Relational Algebra) =
     2
     3=== User Reputation Leaderboard ===
     4
     5Report on the most valuable forgers on PCForge. The score is calculated using the following metrics:
     6* Productivity: Number of approved builds created (Weight: 10).
     7* Popularity: Number of times their builds were favourited (Weight: 5).
     8* Quality: The average star rating across all their builds (Weight: 20).
     9
     10{{{
     11WITH build_stats AS (
     12    SELECT
     13        b.id AS build_id,
     14        b.user_id,
     15        COUNT(DISTINCT fb.user_id) AS favorites_count,
     16        AVG(rb.value) AS avg_rating
     17    FROM build b
     18    LEFT JOIN favorite_build fb ON b.id = fb.build_id
     19    LEFT JOIN rating_build rb ON b.id = rb.build_id
     20    WHERE b.is_approved = TRUE
     21    GROUP BY b.id, b.user_id
     22),
     23user_stats AS (
     24    SELECT
     25        user_id,
     26        COUNT(build_id) AS approved_builds_count,
     27        SUM(favorites_count) AS total_favorites_received,
     28        AVG(avg_rating) AS avg_rating_received
     29    FROM build_stats
     30    GROUP BY user_id
     31)
     32SELECT
     33    u.username,
     34    u.email,
     35    us.approved_builds_count,
     36    us.total_favorites_received,
     37    ROUND(us.avg_rating_received, 2) AS avg_rating_received,
     38    (
     39        (us.approved_builds_count * 10) +
     40        (us.total_favorites_received * 5) +
     41        (us.avg_rating_received * 20)
     42    ) AS reputation_score
     43FROM user_stats us
     44JOIN users u ON u.id = us.user_id
     45ORDER BY reputation_score DESC
     46LIMIT 10;
     47}}}
     48
     49{{{
     50build_stats =
     51γ_{b.id → build_id, b.user_id;
     52   COUNT_DISTINCT(fb.user_id) → favorites_count,
     53   AVG(rb.value) → avg_rating
     54} (
     55  σ_{b.is_approved = TRUE} (
     56    (build b
     57      ⟕_{b.id = fb.build_id} favorite_build fb)
     58      ⟕_{b.id = rb.build_id} rating_build rb
     59  )
     60)
     61
     62user_stats =
     63γ_{user_id;
     64COUNT(build_id) → approved_builds_count,
     65SUM(favorites_count) → total_favorites_received,
     66AVG(avg_rating) → avg_rating_received
     67} (
     68build_stats
     69)
     70
     71λ_10 (
     72  τ_{reputation_score DESC} (
     73    π_{u.username,
     74      u.email,
     75      us.approved_builds_count,
     76      us.total_favorites_received,
     77      ROUND(us.avg_rating_received, 2) → avg_rating_received,
     78      ((us.approved_builds_count * 10)
     79       + (us.total_favorites_received * 5)
     80       + (us.avg_rating_received * 20)) → reputation_score
     81    } (
     82      user_stats us ⋈_{u.id = us.user_id} users u
     83    )
     84  )
     85)
     86}}}