Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 39 additions & 39 deletions services/test.js
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions tasks/dailyStockUpdater.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 매일 6시 전날 주가 데이터 업데이트
// 매일 자정 전날 주가 데이터 업데이트
const cron = require("node-cron");
const { fetchDailyPrice } = require("../services/fetchStockPrice");
const Stock = require("../models/Stocks");
Expand All @@ -23,7 +23,7 @@ async function fetchAllStockPrice() {
}

cron.schedule(
"0 6 * * *",
"0 0 * * *",
async () => {
console.log("[스케줄 시작] 매일 6시 직전 영업일 주가 데이터 수집");
await fetchAllStockPrice();
Expand Down