From d413d36a9dc62aaf0da57bb20ace8dc8622b2415 Mon Sep 17 00:00:00 2001 From: ened Date: Thu, 14 Nov 2024 07:28:40 +0900 Subject: [PATCH] Change default candle db1 directory --- KissMeConsole/Sources/KissConsole+DB.swift | 14 +++++++------- .../Sources/Tests/DB1_CandleData_Tests.swift | 6 ++---- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/KissMeConsole/Sources/KissConsole+DB.swift b/KissMeConsole/Sources/KissConsole+DB.swift index 872624b..0ca426b 100644 --- a/KissMeConsole/Sources/KissConsole+DB.swift +++ b/KissMeConsole/Sources/KissConsole+DB.swift @@ -286,7 +286,7 @@ extension KissConsole { for csvFile in csvFiles { let candleMinName = CandleMinuteFileName() if let (_, yyyyMMdd) = candleMinName.matchedUrl(csvFile.path), let year = Int(yyyyMMdd.prefix(4)) { - let yearDbPath = candleMinuteDBPath(productNo: productNo, year: String(year)) + let yearDbPath = Self.candleMinuteDBPath(productNo: productNo, year: String(year)) if removeOldDB { try? FileManager.default.removeItem(at: yearDbPath) } @@ -323,16 +323,16 @@ extension KissConsole { return true } - private func candleMinuteDBPath(productNo: String, year: String) -> URL { - let dataPath = URL.currentDirectory().appending(path: "data") - let yearDbPath = dataPath.appending(path: "\(productNo)/min/candle-\(year).db1") + static func candleMinuteDBPath(productNo: String, year: String) -> URL { + let dataDbPath = URL.currentDirectory().appending(path: "data-db") + let yearDbPath = dataDbPath.appending(path: "\(productNo)/min/candle-\(year).db1") return yearDbPath } /// - Parameters: /// trimAfterMarket: 거래시간 09:00 ~ 16:00 을 벗어난 경우, DB 의 검사에서 제외함. func validateCandleMinuteDB(productNo: String, year: String, trimAfterMarket: Bool = true) -> Bool { - let yearDbPath = candleMinuteDBPath(productNo: productNo, year: year) + let yearDbPath = Self.candleMinuteDBPath(productNo: productNo, year: year) guard let (_, yearCsvFiles) = collectCandleMinuteFiles(productNo: productNo, year: year, month: nil, day: nil).first else { print("No csv files of productNo: \(productNo), year: \(year)") return false @@ -376,7 +376,7 @@ extension KissConsole { } func countCandleMinunteDB(productNo: String, year: String) -> Int { - let yearDbPath = candleMinuteDBPath(productNo: productNo, year: year) + let yearDbPath = Self.candleMinuteDBPath(productNo: productNo, year: year) do { let db = try KissDB(directory: yearDbPath) try db.begin() @@ -399,7 +399,7 @@ extension KissConsole { } var candleItems = [Domestic.Candle]() - let yearDbPath = candleMinuteDBPath(productNo: productNo, year: String(year)) + let yearDbPath = Self.candleMinuteDBPath(productNo: productNo, year: String(year)) do { let db = try KissDB(directory: yearDbPath) diff --git a/KissMeConsole/Sources/Tests/DB1_CandleData_Tests.swift b/KissMeConsole/Sources/Tests/DB1_CandleData_Tests.swift index ae71e77..3d60b7f 100644 --- a/KissMeConsole/Sources/Tests/DB1_CandleData_Tests.swift +++ b/KissMeConsole/Sources/Tests/DB1_CandleData_Tests.swift @@ -63,11 +63,10 @@ struct DB1_CandleData_Tests: KissTestCase { let year = Self.year let month = Self.month let csvFiles = Self.collectCsv(productNo: productNo, yyyy: year, MM: month) - let dataPath = URL.currentDirectory().appending(path: "data") var itemCount = 0 for csvFile in csvFiles { - let yearDbPath = dataPath.appending(path: "\(productNo)/min/candle-\(year).db1") + let yearDbPath = KissConsole.candleMinuteDBPath(productNo: productNo, year: year) try? FileManager.default.createDirectory(at: yearDbPath, withIntermediateDirectories: true) do { @@ -97,9 +96,8 @@ struct DB1_CandleData_Tests: KissTestCase { let productNo = Self.samsungProductNo let year = Self.year let yyyyMM = String(year) + Self.month - let dataPath = URL.currentDirectory().appending(path: "data") - let yearDbPath = dataPath.appending(path: "\(productNo)/min/candle-\(year).db1") + let yearDbPath = KissConsole.candleMinuteDBPath(productNo: productNo, year: year) do { let db = try KissDB(directory: yearDbPath) try db.begin()