Changes between Initial Version and Version 1 of ComplexReports


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

--

Legend:

Unmodified
Added
Removed
Modified
  • ComplexReports

    v1 v1  
     1= Complex DB Reports (SQL, Stored Procedures, Relational Algebra) =
     2
     3===  Top Performing Components in Highly-Rated Builds ===
     4
     5Report on which specific components appear most frequently in builds that have received a high average user rating (4.5 stars or higher) within the last year.
     6
     7{{{
     8SELECT
     9    c.type,
     10    c.brand,
     11    c.name,
     12    COUNT(bc.component_id) AS usage_count,
     13    AVG(rb.value) AS avg_build_rating
     14FROM components c
     15JOIN build_component bc ON c.id = bc.component_id
     16JOIN build b ON bc.build_id = b.id
     17JOIN rating_build rb ON b.id = rb.build_id
     18WHERE b.created_at >= CURRENT_DATE - INTERVAL '1 year'
     19GROUP BY c.type, c.brand, c.name
     20HAVING avg_build_rating >= 4.5
     21ORDER BY usage_count DESC, avg_build_rating DESC
     22LIMIT 20;
     23}}}
     24
     25=== User Reputation Leaderboard ===
     26
     27Report on the most valuable forgers on PCForge. The score is calculated using the following metrics:
     28* Productivity: Number of approved builds created (Weight: 10).
     29* Popularity: Number of times their builds were favourited (Weight: 5).
     30* Quality: The average star rating across all their builds (Weight: 20).
     31
     32{{{
     33WITH build_stats AS (
     34    SELECT
     35        b.id AS build_id,
     36        b.user_id,
     37        COUNT(DISTINCT fb.user_id) AS favorites_count,
     38        AVG(rb.value) AS avg_rating
     39    FROM build b
     40    LEFT JOIN favorite_build fb ON b.id = fb.build_id
     41    LEFT JOIN rating_build rb ON b.id = rb.build_id
     42    WHERE b.is_approved = TRUE
     43    GROUP BY b.id, b.user_id
     44),
     45user_stats AS (
     46    SELECT
     47        user_id,
     48        COUNT(build_id) AS approved_builds_count,
     49        SUM(favorites_count) AS total_favorites_received,
     50        AVG(avg_rating) AS avg_rating_received
     51    FROM build_stats
     52    GROUP BY user_id
     53)
     54SELECT
     55    u.username,
     56    u.email,
     57    us.approved_builds_count,
     58    us.total_favorites_received,
     59    ROUND(us.avg_rating_received, 2) AS avg_rating_received,
     60    (
     61        (us.approved_builds_count * 10) +
     62        (us.total_favorites_received * 5) +
     63        (us.avg_rating_received * 20)
     64    ) AS reputation_score
     65FROM user_stats us
     66JOIN users u ON u.id = us.user_id
     67ORDER BY reputation_score DESC
     68LIMIT 10;
     69}}}
     70
     71=== Price-to-Performance Efficiency Analysis ===
     72
     73Report on which builds have the most computing power per dollar spent using a "price-to-performance index" calculated with the following formula:
     74* (CPU Cores * CPU Base Clock) + (GPU VRAM * 100)
     75
     76{{{
     77WITH cpu_per_build AS (
     78    SELECT
     79        b.id AS build_id,
     80        c.name AS cpu_model,
     81        cpu.cores,
     82        cpu.base_clock
     83    FROM build b
     84    JOIN build_component bc ON b.id = bc.build_id
     85    JOIN components c ON bc.component_id = c.id
     86    JOIN cpu ON c.id = cpu.component_id
     87    WHERE c.type = 'CPU'
     88),
     89gpu_per_build AS (
     90    SELECT
     91        b.id AS build_id,
     92        c.name AS gpu_model,
     93        gpu.vram
     94    FROM build b
     95    JOIN build_component bc ON b.id = bc.build_id
     96    JOIN components c ON bc.component_id = c.id
     97    JOIN gpu ON c.id = gpu.component_id
     98    WHERE c.type = 'GPU'
     99)
     100
     101SELECT
     102    b.name AS build_name,
     103    cpu.cpu_model,
     104    gpu.gpu_model,
     105    b.total_price,
     106    (cpu.cores * cpu.base_clock + gpu.vram * 100) AS performance_score,
     107    ROUND(
     108        (cpu.cores * cpu.base_clock + gpu.vram * 100),
     109        4
     110    ) AS price_to_performance_index
     111FROM build b
     112JOIN cpu_per_build cpu ON b.id = cpu.build_id
     113JOIN gpu_per_build gpu ON b.id = gpu.build_id
     114WHERE b.total_price > 0
     115ORDER BY price_to_performance_index DESC
     116LIMIT 20;
     117}}}