Skip to content

Commit 5a355d3

Browse files
committed
오류 수정
1 parent 98be54b commit 5a355d3

2 files changed

Lines changed: 38 additions & 56 deletions

File tree

dao/getTestResultDao.js

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,34 @@ const getTestResultDao = {
77
divScore
88
) => {
99
const query = `
10-
SELECT
11-
ers.etf_code,
12-
e.etf_name,
13-
ers.stability_score,
14-
ers.liquidity_score,
15-
ers.growth_score,
16-
ers.diversification_score,
17-
ROUND((
10+
WITH raw_score AS (
11+
SELECT
12+
ers.etf_code,
13+
e.etf_name,
14+
ers.stability_score,
15+
ers.liquidity_score,
16+
ers.growth_score,
17+
ers.diversification_score,
18+
ROUND((
19+
(
1820
ers.stability_score * $1 +
1921
ers.liquidity_score * $2 +
2022
ers.growth_score * $3 +
2123
ers.diversification_score * $4
22-
)::numeric, 2) AS total_score
23-
FROM etf_recommendation_score ers
24-
JOIN etfs e ON ers.etf_code = e.etf_code
25-
WHERE ers.stability_score IS NOT NULL
26-
AND ers.liquidity_score IS NOT NULL
27-
AND ers.growth_score IS NOT NULL
28-
AND ers.diversification_score IS NOT NULL
24+
) / ($1 + $2 + $3 + $4)
25+
)::numeric, 2) AS total_score
26+
27+
FROM etf_recommendation_score ers
28+
JOIN etfs e ON ers.etf_code = e.etf_code
29+
WHERE ers.stability_score IS NOT NULL
30+
AND ers.liquidity_score IS NOT NULL
31+
AND ers.growth_score IS NOT NULL
32+
AND ers.diversification_score IS NOT NULL
33+
)
34+
SELECT *
35+
FROM raw_score
2936
ORDER BY total_score DESC
3037
LIMIT 5;
31-
32-
3338
`;
3439
console.log(
3540
"stabilityScore,liquidityScore,growthScore,divScore",

dao/getTestThemeResultDao.js

Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -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
)
5736
SELECT *
58-
FROM scored_etfs
37+
FROM raw_score
5938
ORDER BY total_score DESC
6039
LIMIT 5;
61-
62-
6340
`;
6441
console.log(
6542
"ddd",

0 commit comments

Comments
 (0)