Add resume for building candle db

This commit is contained in:
2024-11-16 00:44:27 +09:00
parent a1ad2c1296
commit 9cf4f00672
4 changed files with 31 additions and 6 deletions

View File

@@ -389,7 +389,7 @@ extension URL {
extension URL {
public var isDirectoryExists: Bool? {
public var isDirectoryExists: Bool {
var isDir: ObjCBool = false
if FileManager.default.fileExists(atPath: path, isDirectory: &isDir) {
return isDir.boolValue
@@ -397,7 +397,7 @@ extension URL {
return false
}
public var isFileExists: Bool? {
public var isFileExists: Bool {
var isDir: ObjCBool = false
if FileManager.default.fileExists(atPath: path, isDirectory: &isDir) {
return isDir.boolValue == false

View File

@@ -304,6 +304,12 @@ extension KissConsole {
return true
}
func isCandleMinuteDBExisted(productNo: String, year: String) -> Bool {
let dataDbPath = URL.currentDirectory().appending(path: "data-db")
let yearDbPath = dataDbPath.appending(path: "\(productNo)/min/candle-\(year).db1")
return yearDbPath.isDirectoryExists
}
private func buildCandleMinuteDB(to yearDbPath: URL, from csvFile: URL, trimAfterMarket: Bool) -> Bool {
autoreleasepool {
do {

View File

@@ -1283,7 +1283,17 @@ extension KissConsole {
private func onCandleDB_Build(_ args: [String]) {
let productNo = (args[0] == "all" ? nil: args[0])
var isBuildResumed = false
let productNo: String?
switch args[0] {
case "all":
productNo = nil
case "resume":
productNo = nil
isBuildResumed = true
default:
productNo = args[0]
}
let year = args[safe: 1]?.isYear == true ? args[safe: 1]: nil
let month = args[safe: 2]?.isMonth == true ? args[safe: 2]: nil
let day = args[safe: 3]?.isDay == true ? args[safe: 3]: nil
@@ -1304,13 +1314,22 @@ extension KissConsole {
let semaphore = DispatchSemaphore(value: 0)
Task {
defer {
semaphore.signal()
}
if isBuildResumed, let year = year {
if isCandleMinuteDBExisted(productNo: productNo, year: year) {
print("Skipping to build candle db for productNo: \(productNo) by resume")
return
}
}
let startTime = Date.appTime
if buildCandleMinuteDB(productNo: productNo, csvFiles: csvFiles) {
print("Success candle db with elapsed time: \(Date.appTime - startTime)")
}
try await Task.sleep(nanoseconds: 1_000_000_000)
semaphore.signal()
try await Task.sleep(nanoseconds: 1_000_000_000 / 5)
}
semaphore.wait()
}

View File

@@ -52,7 +52,7 @@ WIP `showcase` | 추천 상품을 제안함.
`localize names` | csv field name 에 대해서 한글명을 제공하는 **data/localized-names.csv** 를 저장.
`localize (on/off)`| 앞으로 저장하는 모든 csv file 의 field 에 (on) 이면 한글명으로, (off) 이면 영문으로 저장.
`real (PNO) (on/off)` | 실시간 웹소켓을 접속하여 수신된 데이터를 기록합니다. (on) 이면 파일로 기록, (off) 이면 기록하지 않음.
`db candle build all [yyyy] [MM] [dd]` | 모든 종목에 대해서 csv 파일로부터 지정된 yyyy, MM, dd 날짜에 대해서만 DB 로 빌드. **data/(PNO)/min/candle-(yyyy).db1** 파일에 저장.
`db candle build (all/resume) [yyyy] [MM] [dd]` | 모든 종목에 대해서 csv 파일로부터 지정된 yyyy, MM, dd 날짜에 대해서만 DB 로 빌드. **data/(PNO)/min/candle-(yyyy).db1** 파일에 저장.
`db candle build (PNO) [yyyy] [MM] [dd]` | PNO 의 csv 파일로부터 지정된 yyyy, MM, dd 날짜에 대해서만 DB 로 빌드. **data/(PNO)/min/candle-(yyyy).db1** 파일에 저장.
`db candle validate (PNO) (yyyy)` | PNO 의 yyyy DB에 기록된 분봉에 대해서 유효한지 검사.
`db candle count (PNO) (yyyy)` | PNO 의 yyyy DB에 기록된 분봉 갯수를 열람.