@@ -8,58 +8,35 @@ const getTestThemeResultDao = {
88 theme
99 ) => {
1010 const query = `
11- WITH normalized_weights AS (
12- SELECT
13- $1::numeric AS w1_raw, -- stability
14- $2::numeric AS w2_raw, -- liquidity
15- $3::numeric AS w3_raw, -- growth
16- $4::numeric AS w4_raw -- diversification
17- ),
18- weight_sum AS (
19- SELECT
20- w1_raw + w2_raw + w3_raw + w4_raw AS total
21- FROM normalized_weights
22- ),
23- user_weights AS (
24- SELECT
25- w1_raw / total AS w1,
26- w2_raw / total AS w2,
27- w3_raw / total AS w3,
28- w4_raw / total AS w4
29- FROM normalized_weights, weight_sum
30- ),
31- scored_etfs AS (
11+ WITH raw_score AS (
3212 SELECT
3313 ers.etf_code,
3414 e.etf_name,
35- e.theme,
3615 ers.stability_score,
3716 ers.liquidity_score,
3817 ers.growth_score,
3918 ers.diversification_score,
40-
41- ROUND((
42- ers.stability_score * uw.w1 +
43- ers.liquidity_score * uw.w2 +
44- ers.growth_score * uw.w3 +
45- ers.diversification_score * uw.w4
46- )::numeric, 2) AS total_score
19+ ROUND((
20+ (
21+ ers.stability_score * $1 +
22+ ers.liquidity_score * $2 +
23+ ers.growth_score * $3 +
24+ ers.diversification_score * $4
25+ ) / ($1 + $2 + $3 + $4)
26+ )::numeric, 2) AS total_score
27+
4728 FROM etf_recommendation_score ers
4829 JOIN etfs e ON ers.etf_code = e.etf_code
49- CROSS JOIN user_weights uw
50- WHERE
51- ers.stability_score IS NOT NULL AND
52- ers.liquidity_score IS NOT NULL AND
53- ers.growth_score IS NOT NULL AND
54- ers.diversification_score IS NOT NULL AND
55- e.theme = $5 -- 테마 필터 추가
30+ WHERE ers.stability_score IS NOT NULL
31+ AND ers.liquidity_score IS NOT NULL
32+ AND ers.growth_score IS NOT NULL
33+ AND ers.diversification_score IS NOT NULL
34+ AND e.theme = $5
5635)
5736SELECT *
58- FROM scored_etfs
37+ FROM raw_score
5938ORDER BY total_score DESC
6039LIMIT 5;
61-
62-
6340` ;
6441 console . log (
6542 "ddd" ,
0 commit comments