| | 1 | = Complex DB Reports (SQL, Stored Procedures, Relational Algebra) = |
| | 2 | |
| | 3 | === Component Compatibility Success Rate === |
| | 4 | |
| | 5 | Report on which component pairings (CPU + motherboard, GPU + case) have the highest build success rates based on user satisfaction and build longevity. |
| | 6 | |
| | 7 | **SQL:** |
| | 8 | |
| | 9 | {{{ |
| | 10 | WITH cpu_mobo_pairs AS ( |
| | 11 | SELECT |
| | 12 | cpu.brand AS cpu_brand, |
| | 13 | cpu.name AS cpu_model, |
| | 14 | mobo.chipset AS motherboard_chipset, |
| | 15 | b.id AS build_id, |
| | 16 | b.user_id |
| | 17 | FROM build b |
| | 18 | JOIN build_component bc_cpu ON b.id = bc_cpu.build_id |
| | 19 | JOIN components cpu ON bc_cpu.component_id = cpu.id |
| | 20 | JOIN build_component bc_mobo ON b.id = bc_mobo.build_id |
| | 21 | JOIN components mobo ON bc_mobo.component_id = mobo.id |
| | 22 | WHERE cpu.type = 'CPU' |
| | 23 | AND mobo.type = 'Motherboard' |
| | 24 | AND b.is_approved = TRUE |
| | 25 | ), |
| | 26 | pair_metrics AS ( |
| | 27 | SELECT |
| | 28 | cmp.cpu_brand, |
| | 29 | cmp.cpu_model, |
| | 30 | cmp.motherboard_chipset, |
| | 31 | COUNT(cmp.build_id) AS total_builds, |
| | 32 | AVG(rb.value) AS avg_satisfaction, |
| | 33 | COUNT(DISTINCT CASE WHEN ub.last_active >= CURRENT_DATE - INTERVAL '3 months' |
| | 34 | THEN cmp.build_id END) AS active_builds |
| | 35 | FROM cpu_mobo_pairs cmp |
| | 36 | LEFT JOIN rating_build rb ON cmp.build_id = rb.build_id |
| | 37 | LEFT JOIN user_builds ub ON cmp.build_id = ub.build_id |
| | 38 | GROUP BY cmp.cpu_brand, cmp.cpu_model, cmp.motherboard_chipset |
| | 39 | HAVING COUNT(cmp.build_id) >= 10 |
| | 40 | ) |
| | 41 | SELECT |
| | 42 | CONCAT(cpu_brand, ' ', cpu_model) AS cpu_combo, |
| | 43 | motherboard_chipset, |
| | 44 | total_builds, |
| | 45 | ROUND(avg_satisfaction, 2) AS avg_satisfaction, |
| | 46 | ROUND( |
| | 47 | (avg_satisfaction / 5.0) * 0.6 + |
| | 48 | (CAST(active_builds AS DECIMAL) / total_builds) * 0.4, |
| | 49 | 3 |
| | 50 | ) AS success_rate |
| | 51 | FROM pair_metrics |
| | 52 | ORDER BY success_rate DESC, total_builds DESC |
| | 53 | LIMIT 12; |
| | 54 | }}} |
| | 55 | |
| | 56 | **Relational algebra:** |
| | 57 | |
| | 58 | {{{ |
| | 59 | cpu_mobo_pairs = |
| | 60 | π_{cpu.brand ⇒ cpu_brand, cpu.name ⇒ cpu_model, |
| | 61 | mobo.chipset ⇒ motherboard_chipset, |
| | 62 | b.id ⇒ build_id |
| | 63 | } ( |
| | 64 | σ_{c1.type = 'CPU' AND c2.type = 'Motherboard'} ( |
| | 65 | build b |
| | 66 | ⋈_{b.id = bc1.build_id} build_component bc1 |
| | 67 | ⋈_{bc1.component_id = c1.id} components c1 |
| | 68 | ⋈_{b.id = bc2.build_id} build_component bc2 |
| | 69 | ⋈_{bc2.component_id = c2.id} components c2 |
| | 70 | ) |
| | 71 | ) |
| | 72 | |
| | 73 | pair_metrics = |
| | 74 | γ_{cpu_brand, cpu_model, motherboard_chipset; |
| | 75 | COUNT(build_id) ⇒ total_builds, |
| | 76 | AVG(rb.value) ⇒ avg_satisfaction, |
| | 77 | COUNT(DISTINCT ub.user_id WHERE ub.still_active = TRUE) ⇒ active_builds |
| | 78 | } ( |
| | 79 | cpu_mobo_pairs cmp |
| | 80 | ⋈_{cmp.build_id = rb.build_id} rating_build rb |
| | 81 | ⋈_{cmp.build_id = ub.build_id} user_builds ub |
| | 82 | ) |
| | 83 | |
| | 84 | λ_12 ( |
| | 85 | τ_{success_rate DESC, total_builds DESC} ( |
| | 86 | σ_{total_builds ≥ 10} ( |
| | 87 | π_{pm.cpu_brand + ' ' + pm.cpu_model ⇒ cpu_combo, |
| | 88 | pm.motherboard_chipset, |
| | 89 | pm.total_builds, |
| | 90 | ROUND(pm.avg_satisfaction, 2) ⇒ avg_satisfaction, |
| | 91 | ROUND((pm.avg_satisfaction / 5.0) * 0.6 + (pm.active_builds / pm.total_builds) * 0.4, 3) ⇒ success_rate |
| | 92 | } (pair_metrics pm) |
| | 93 | ) |
| | 94 | ) |
| | 95 | ) |
| | 96 | }}} |