Scan if today candle files exist
This commit is contained in:
@@ -41,8 +41,26 @@ extension String {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extension String {
|
||||
func parseCandleDate() -> String? {
|
||||
let fileNameFrag = split(separator: ".")
|
||||
guard fileNameFrag.count == 2 else {
|
||||
return nil
|
||||
}
|
||||
|
||||
let candlePrefix = "candle-"
|
||||
guard fileNameFrag[0].prefix(candlePrefix.count) == candlePrefix, fileNameFrag[1] == "csv" else {
|
||||
return nil
|
||||
}
|
||||
|
||||
let fileDateFrag = fileNameFrag[0].suffix(fileNameFrag[0].count - candlePrefix.count)
|
||||
return String(fileDateFrag)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extension Date {
|
||||
|
||||
public var yyyyMMdd_split: (year: Int, month: Int, day: Int)? {
|
||||
let sets: Set<Calendar.Component> = [.year, .month, .day, .hour, .minute, .second]
|
||||
let components = Calendar.current.dateComponents(sets, from: self)
|
||||
@@ -145,6 +163,17 @@ extension Array where Element: PropertyIterable {
|
||||
}
|
||||
|
||||
|
||||
extension URL {
|
||||
var isDirectory: Bool? {
|
||||
var isDir: ObjCBool = false
|
||||
if FileManager.default.fileExists(atPath: path, isDirectory: &isDir) {
|
||||
return isDir.boolValue
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extension FileManager {
|
||||
static func subPathFiles(_ subpath: String) -> FileManager.DirectoryEnumerator? {
|
||||
let baseUrl = URL.currentDirectory().appending(path: subpath)
|
||||
|
||||
@@ -143,7 +143,7 @@ extension KissConsole {
|
||||
return .invalidFileName
|
||||
}
|
||||
|
||||
let fileDateFrag = fileNameFrag[0].suffix(fileNameFrag[0].count - candlePrefix.count)
|
||||
let fileDateFrag = String(fileNameFrag[0].suffix(fileNameFrag[0].count - candlePrefix.count))
|
||||
guard let stringCsv = try? String(contentsOfFile: fileUrl.path) else {
|
||||
return .cannotRead
|
||||
}
|
||||
|
||||
@@ -149,6 +149,52 @@ private func check_candle_csv() {
|
||||
}
|
||||
|
||||
|
||||
func check_today_candle_exist() {
|
||||
guard let enumerator = FileManager.subPathFiles("data") else {
|
||||
return
|
||||
}
|
||||
|
||||
var productUrls = [String: URL]()
|
||||
var candleUrls = [String: URL]()
|
||||
|
||||
for case let fileUrl as URL in enumerator {
|
||||
|
||||
guard true != fileUrl.isDirectory else {
|
||||
let productNo = fileUrl.lastPathComponent
|
||||
if let _ = Int(productNo) {
|
||||
productUrls[productNo] = fileUrl
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
guard fileUrl.pathExtension == "csv" else {
|
||||
continue
|
||||
}
|
||||
|
||||
let fileName = fileUrl.lastPathComponent
|
||||
let periodDir = fileUrl.deletingLastPathComponent()
|
||||
let period = periodDir.lastPathComponent
|
||||
let productNoDir = periodDir.deletingLastPathComponent()
|
||||
let productNo = productNoDir.lastPathComponent
|
||||
|
||||
guard let _ = Int(productNo), period == "min" else {
|
||||
continue
|
||||
}
|
||||
if Date().yyyyMMdd == fileName.parseCandleDate() {
|
||||
candleUrls[productNo] = fileUrl
|
||||
}
|
||||
}
|
||||
|
||||
for productNo in productUrls.keys {
|
||||
guard nil == candleUrls[productNo] else {
|
||||
continue
|
||||
}
|
||||
print("\(productNo) have no today candle!!")
|
||||
}
|
||||
print("all scan finished")
|
||||
}
|
||||
|
||||
|
||||
private func move_candles_to_min_subdir() {
|
||||
// Move all of csv into min sub-directory
|
||||
// ex) data/000020/candle-20230530.csv --> /data/000020/min/candle-20230530.csv
|
||||
|
||||
Reference in New Issue
Block a user