Ignore invalid points
This commit is contained in:
parent
66a04781d3
commit
c6b51c98fb
@ -136,6 +136,7 @@ private func readElements<T>(from url: URL) throws -> [Timestamped<T>] where T:
|
||||
|
||||
var result: [Timestamped<T>] = []
|
||||
var currentIndex = data.startIndex
|
||||
var skippedValues = 0
|
||||
while currentIndex < data.endIndex {
|
||||
let startIndexOfTimestamp = currentIndex + byteCountLength
|
||||
guard startIndexOfTimestamp <= data.endIndex else {
|
||||
@ -159,14 +160,18 @@ private func readElements<T>(from url: URL) throws -> [Timestamped<T>] where T:
|
||||
let timestamp = try decoder.decode(Double.self, from: timestampData)
|
||||
let date = Date(timeIntervalSince1970: timestamp)
|
||||
let elementData = data[currentIndex..<nextIndex]
|
||||
do {
|
||||
let element: T = try decoder.decode(from: elementData)
|
||||
result.append(.init(value: element, timestamp: date))
|
||||
} catch {
|
||||
skippedValues += 1
|
||||
}
|
||||
currentIndex = nextIndex
|
||||
if result.count % 100 == 1 {
|
||||
print("File \(file): \(result.count) entries loaded (\(currentIndex)/\(data.endIndex) bytes)")
|
||||
}
|
||||
}
|
||||
print("Loaded \(result.count) data points")
|
||||
print("Loaded \(result.count) data points (\(skippedValues) skipped)")
|
||||
return result
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user