Changes between Initial Version and Version 1 of StorageConfigurationOptimizationScore


Ignore:
Timestamp:
01/28/26 00:44:56 (12 days ago)
Author:
233194
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • StorageConfigurationOptimizationScore

    v1 v1  
     1= Complex DB Reports (SQL, Stored Procedures, Relational Algebra) =
     2
     3===  Storage Configuration Optimization Score ===
     4
     5Report on which storage configurations (SSD + HDD combinations) provide the best balance between speed, reliability, cost-efficiency, failure rate and user approval within different build price ranges.
     6
     7**SQL:**
     8
     9{{{
     10WITH storage_configs AS (
     11  SELECT
     12    b.id AS build_id,
     13    b.total_price,
     14    ssd.brand AS ssd_brand,
     15    ssd.capacity AS ssd_capacity,
     16    ssd.price AS ssd_price,
     17    hdd.capacity AS hdd_capacity,
     18    hdd.price AS hdd_price,
     19    CASE
     20      WHEN hdd.capacity IS NULL THEN 'SSD-Only'
     21      WHEN ssd.capacity < 512 THEN 'SSD-Boot-HDD-Storage'
     22      ELSE 'SSD-Primary-HDD-Archive'
     23    END AS config_type
     24  FROM build b
     25  JOIN build_component bc_ssd ON b.id = bc_ssd.build_id
     26  JOIN components ssd ON bc_ssd.component_id = ssd.id
     27  LEFT JOIN build_component bc_hdd ON b.id = bc_hdd.build_id
     28  LEFT JOIN components hdd ON bc_hdd.component_id = hdd.id AND hdd.type = 'HDD'
     29  WHERE ssd.type = 'SSD'
     30    AND b.is_approved = TRUE
     31    AND b.created_at >= CURRENT_DATE - INTERVAL '1 year'
     32),
     33config_performance AS (
     34  SELECT
     35    sc.config_type,
     36    sc.ssd_brand,
     37    COUNT(sc.build_id) AS builds_count,
     38    AVG(sc.ssd_price + COALESCE(sc.hdd_price, 0)) AS avg_storage_cost,
     39    AVG(sc.ssd_capacity + COALESCE(sc.hdd_capacity, 0)) AS avg_total_capacity,
     40    AVG(rb.value) AS avg_build_rating,
     41    AVG((sc.ssd_price + COALESCE(sc.hdd_price, 0)) / sc.total_price) AS storage_cost_ratio
     42  FROM storage_configs sc
     43  LEFT JOIN rating_build rb ON sc.build_id = rb.build_id
     44  GROUP BY sc.config_type, sc.ssd_brand
     45  HAVING COUNT(sc.build_id) >= 5
     46)
     47SELECT
     48  config_type,
     49  ssd_brand,
     50  builds_count,
     51  ROUND(avg_storage_cost, 2) AS avg_storage_cost,
     52  ROUND(avg_total_capacity, 0) AS avg_total_capacity_gb,
     53  ROUND(avg_build_rating, 2) AS avg_build_rating,
     54  ROUND(storage_cost_ratio * 100, 1) AS storage_cost_pct,
     55  ROUND(
     56    (avg_build_rating / 5.0 * 40) +
     57    (avg_total_capacity / avg_storage_cost * 0.5) +
     58    ((1 - storage_cost_ratio) * 30) +
     59    (LN(builds_count) * 5),
     60    2
     61  ) AS optimization_score
     62FROM config_performance
     63ORDER BY optimization_score DESC, builds_count DESC
     64LIMIT 15;
     65}}}
     66
     67**Relational algebra:**
     68
     69{{{
     70storage_configs =
     71  π_{b.id ⇒ build_id, b.total_price,
     72     ssd.brand ⇒ ssd_brand, ssd.capacity ⇒ ssd_capacity, ssd.price ⇒ ssd_price,
     73     hdd.capacity ⇒ hdd_capacity, hdd.price ⇒ hdd_price,
     74     CASE
     75       WHEN hdd.capacity IS NULL THEN 'SSD-Only'
     76       WHEN ssd.capacity < 512 THEN 'SSD-Boot-HDD-Storage'
     77       ELSE 'SSD-Primary-HDD-Archive'
     78     END ⇒ config_type
     79  } (
     80    σ_{ssd_comp.type = 'SSD' AND (hdd_comp.type = 'HDD' OR hdd_comp.type IS NULL)} (
     81      build b
     82      ⋈_{b.id = bc_ssd.build_id} build_component bc_ssd
     83      ⋈_{bc_ssd.component_id = ssd_comp.id} components ssd_comp
     84      ⟕_{b.id = bc_hdd.build_id AND bc_hdd.component_id = hdd_comp.id AND hdd_comp.type = 'HDD'}
     85        (build_component bc_hdd ⋈ components hdd_comp)
     86    )
     87  )
     88
     89config_performance =
     90  γ_{config_type, ssd_brand;
     91     COUNT(build_id) ⇒ builds_count,
     92     AVG(ssd_price + COALESCE(hdd_price, 0)) ⇒ avg_storage_cost,
     93     AVG(ssd_capacity + COALESCE(hdd_capacity, 0)) ⇒ avg_total_capacity,
     94     AVG(rb.value) ⇒ avg_build_rating,
     95     AVG((ssd_price + COALESCE(hdd_price, 0)) / total_price) ⇒ storage_cost_ratio
     96  } (
     97    σ_{b.is_approved = TRUE AND b.created_at ≥ CURRENT_DATE - INTERVAL '1 year'} (
     98      storage_configs sc ⋈_{sc.build_id = b.id} build b
     99      ⋈_{sc.build_id = rb.build_id} rating_build rb
     100    )
     101  )
     102
     103λ_15 (
     104  τ_{optimization_score DESC, builds_count DESC} (
     105    σ_{builds_count ≥ 5} (
     106      π_{cp.config_type,
     107         cp.ssd_brand,
     108         cp.builds_count,
     109         ROUND(cp.avg_storage_cost, 2) ⇒ avg_storage_cost,
     110         ROUND(cp.avg_total_capacity, 0) ⇒ avg_total_capacity_gb,
     111         ROUND(cp.avg_build_rating, 2) ⇒ avg_build_rating,
     112         ROUND(cp.storage_cost_ratio * 100, 1) ⇒ storage_cost_pct,
     113         ROUND(
     114           (cp.avg_build_rating / 5.0 * 40) +
     115           (cp.avg_total_capacity / cp.avg_storage_cost * 0.5) +
     116           ((1 - cp.storage_cost_ratio) * 30) +
     117           (LOG(cp.builds_count) * 5),
     118           2
     119         ) ⇒ optimization_score
     120      } (config_performance cp)
     121    )
     122  )
     123)
     124}}}