From 0516886b4897dc6fd26d7b9f658f2b2be57bf973 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B3=BD=EC=98=88=EA=B2=BD?= Date: Sun, 27 Jul 2025 16:54:45 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20=EC=A0=84=EB=82=A0=EC=A3=BC=EA=B0=80?= =?UTF-8?q?=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8=EC=8B=9C=EA=B0=84=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20->=200=EC=8B=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/test.js | 78 +++++++++++++++++++------------------- tasks/dailyStockUpdater.js | 4 +- 2 files changed, 41 insertions(+), 41 deletions(-) diff --git a/services/test.js b/services/test.js index a8ee173..57a79c8 100644 --- a/services/test.js +++ b/services/test.js @@ -1,44 +1,44 @@ // //practicechartdata db에서 중복된 날짜 제거 -const mongoose = require("mongoose"); -const PracticeChartData = require("../models/PracticeChartData"); // 경로 수정 -require("dotenv").config(); - -async function removeDuplicatePrices() { - await mongoose.connect(process.env.DB_URI); - - const docs = await PracticeChartData.find({}); - - for (const doc of docs) { - const seen = new Map(); // 날짜 -> 첫 price - const uniquePrices = []; - - for (const price of doc.prices) { - if (!seen.has(price.date)) { - seen.set(price.date, true); - uniquePrices.push(price); - } - } - - if (uniquePrices.length !== doc.prices.length) { - console.log( - `[중복 제거] ${doc.stock_code}: ${doc.prices.length} → ${uniquePrices.length}` - ); - doc.prices = uniquePrices; - await doc.save(); - } - } - - await mongoose.disconnect(); - console.log("✅ 중복 제거 완료"); -} - -removeDuplicatePrices().catch((err) => { - console.error("❌ 오류 발생:", err); -}); - -// // 테스트용, 전 종목 직전일 주가정보 업데이트 // const mongoose = require("mongoose"); -// // const { fetchDailyPrice } = require("./fetchStockPrice"); +// const PracticeChartData = require("../models/PracticeChartData"); // 경로 수정 +// require("dotenv").config(); + +// async function removeDuplicatePrices() { +// await mongoose.connect(process.env.DB_URI); + +// const docs = await PracticeChartData.find({}); + +// for (const doc of docs) { +// const seen = new Map(); // 날짜 -> 첫 price +// const uniquePrices = []; + +// for (const price of doc.prices) { +// if (!seen.has(price.date)) { +// seen.set(price.date, true); +// uniquePrices.push(price); +// } +// } + +// if (uniquePrices.length !== doc.prices.length) { +// console.log( +// `[중복 제거] ${doc.stock_code}: ${doc.prices.length} → ${uniquePrices.length}` +// ); +// doc.prices = uniquePrices; +// await doc.save(); +// } +// } + +// await mongoose.disconnect(); +// console.log("✅ 중복 제거 완료"); +// } + +// removeDuplicatePrices().catch((err) => { +// console.error("❌ 오류 발생:", err); +// }); + +// 테스트용, 전 종목 직전일 주가정보 업데이트 +// const mongoose = require("mongoose"); +// require("dotenv").config(); // const { fetchAllStockPrice } = require("../tasks/dailyStockUpdater"); // async function testInsert() { diff --git a/tasks/dailyStockUpdater.js b/tasks/dailyStockUpdater.js index 310ac63..6c1d796 100644 --- a/tasks/dailyStockUpdater.js +++ b/tasks/dailyStockUpdater.js @@ -1,4 +1,4 @@ -// 매일 6시 전날 주가 데이터 업데이트 +// 매일 자정 전날 주가 데이터 업데이트 const cron = require("node-cron"); const { fetchDailyPrice } = require("../services/fetchStockPrice"); const Stock = require("../models/Stocks"); @@ -23,7 +23,7 @@ async function fetchAllStockPrice() { } cron.schedule( - "0 6 * * *", + "0 0 * * *", async () => { console.log("[스케줄 시작] 매일 6시 직전 영업일 주가 데이터 수집"); await fetchAllStockPrice();