Skip to content

Commit 50be955

Browse files
Merge pull request #63 from InserToken/feat/52-financialChart-jihwan
디테일 수정
2 parents 4b0b0aa + 19ce2f1 commit 50be955

5 files changed

Lines changed: 45 additions & 12 deletions

File tree

models/PracticeScore.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const practiceScoreSchema = new mongoose.Schema({
1515
feedback: String,
1616
score: Number,
1717
logic: Number,
18-
momentum: Number,
18+
technical: Number,
1919
macroEconomy: Number,
2020
marketIssues: Number,
2121
quantEvidence: Number,

package-lock.json

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"mongodb": "^6.17.0",
3838
"mongoose": "^8.16.3",
3939
"morgan": "~1.9.1",
40+
"node-cache": "^5.1.2",
4041
"node-cron": "^4.2.1",
4142
"node-fetch": "^2.7.0",
4243
"validator": "^13.15.15",

routes/finance.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const FinancialSummary = require("../models/FinancialSummary");
77

88
const router = express.Router();
99

10-
const API_KEY = "695e30af841d9e180b0378b7b5e5c5048f9b8fd6";
10+
const API_KEY = "f829a70ff7a97b41e53e6f4c190b288d85052c15";
1111
const FIN_URL = "https://opendart.fss.or.kr/api/stockTotqySttus.json";
1212
const currentYear = 2025;
1313
const REPORT_CODES = [11013, 11012, 11014, 11011];

services/metricsService.js

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
const FinancialSummary = require("../models/FinancialSummary");
22
const { fetchStockPrice } = require("./fetchStockPrice");
3+
const NodeCache = require("node-cache");
4+
5+
const cache = new NodeCache({ stdTTL: 3600 }); // 1시간 캐시
36

47
/** reprt_code → 분기 말일 매핑 */
58
const PERIOD_END = {
@@ -21,6 +24,14 @@ function getPeriodDate(entry) {
2124
* @returns {Promise<object>} 계산된 지표들
2225
*/
2326
async function computeMetrics(stockCode, dateStr) {
27+
const cacheKey = `${stockCode}_${dateStr}`;
28+
console.log("cacheKey 생성:", cacheKey);
29+
30+
const cached = cache.get(cacheKey);
31+
if (cached) {
32+
console.log("📦 캐시된 데이터 반환:", cacheKey);
33+
return cached;
34+
}
2435
// DB에서 불러오기
2536
const doc = await FinancialSummary.findOne({ stock_code: stockCode }).lean();
2637
if (!doc) throw new Error("금융 요약 데이터가 없습니다: " + stockCode);
@@ -64,9 +75,9 @@ async function computeMetrics(stockCode, dateStr) {
6475
);
6576

6677
// 지표 계산
67-
const per = eps ? stockPrice / eps : null;
68-
const pbr = bps ? stockPrice / bps : null;
69-
const psr = ttmRevenue ? (stockPrice * shareCount) / ttmRevenue : null;
78+
// const per = eps ? stockPrice / eps : null;
79+
// const pbr = bps ? stockPrice / bps : null;
80+
// const psr = ttmRevenue ? (stockPrice * shareCount) / ttmRevenue : null;
7081

7182
// 시계열 데이터
7283
const series = {
@@ -80,16 +91,10 @@ async function computeMetrics(stockCode, dateStr) {
8091
operatingGrowthRate: valid.map((e) => e.operating_growth_rate),
8192
};
8293

83-
return {
94+
const result = {
8495
price: { price: stockPrice, date: priceDate },
85-
per,
86-
pbr,
87-
psr,
8896
stockPrice,
8997
shareCount,
90-
// per,
91-
// psr,
92-
// pbr,
9398
eps,
9499
bps,
95100
roe: last.roe,
@@ -100,6 +105,11 @@ async function computeMetrics(stockCode, dateStr) {
100105
profit_diff_rate: last.profit_diff_rate,
101106
series,
102107
};
108+
109+
cache.set(`${stockCode}_${dateStr}`, result);
110+
console.log("📝 캐시에 저장함:", `${stockCode}_${dateStr}`);
111+
112+
return result;
103113
}
104114

105115
module.exports = { computeMetrics };

0 commit comments

Comments
 (0)