-
Notifications
You must be signed in to change notification settings - Fork 20
/
DefaultVitalSignsDataProvider.swift
94 lines (79 loc) · 3.41 KB
/
DefaultVitalSignsDataProvider.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//******************************************************************************
// SCICHART® Copyright SciChart Ltd. 2011-2020. All rights reserved.
//
// Web: http://www.scichart.com
// Support: support@scichart.com
// Sales: sales@scichart.com
//
// DefaultVitalSignsDataProvider.swift is part of the SCICHART® Examples. Permission is hereby granted
// to modify, create derivative works, distribute and publish any part of this source
// code whether for commercial, private or personal use.
//
// The SCICHART® examples are distributed in the hope that they will be useful, but
// without any warranty. It is provided "AS IS" without warranty of any kind, either
// expressed or implied.
//******************************************************************************
import Foundation
class DefaultVitalSignsDataProvider: DataProviderBase<VitalSignsData> {
// 1. Heart rate or pulse rate (ECG HR)
// 2. Blood Pressure (NI BP)
// 3. Blood Volume (SV ml)
// 4. Blood Oxygenation (SPo2)
let SAMPLE_RATE: Double = 800
let ECG_TRACES = "EcgTraces.csv"
private var currentIndex = 0
private var totalIndex = 0
private var isATrace = false
let xValues = SCIDoubleValues()
let ecgHeartRate = SCIDoubleValues()
let bloodPressure = SCIDoubleValues()
let bloodVolume = SCIDoubleValues()
let bloodOxygenation = SCIDoubleValues()
init() {
super.init(dispatchTimeInterval: .microseconds(1000))
do {
let rawData = try String.init(contentsOfFile: SCDDataManager.getBundleFilePath(from: ECG_TRACES), encoding: .utf8)
let lines = rawData.components(separatedBy: "\n")
for i in 0 ..< lines.count - 1 {
let split = lines[i].components(separatedBy: ",") as [NSString]
xValues.add(split[0].doubleValue)
ecgHeartRate.add(split[1].doubleValue)
bloodPressure.add(split[2].doubleValue)
bloodVolume.add(split[3].doubleValue)
bloodOxygenation.add(split[4].doubleValue)
}
} catch {
print("Load ECG Error: Failed to load ECG. \(error.localizedDescription)")
}
}
override func onNext() -> VitalSignsData {
if currentIndex >= xValues.count {
currentIndex = 0;
}
let time = (Double(totalIndex) / SAMPLE_RATE).truncatingRemainder(dividingBy: 10)
let ecgHeartRate = self.ecgHeartRate.getValueAt(currentIndex)
let bloodPressure = self.bloodPressure.getValueAt(currentIndex)
let bloodVolume = self.bloodVolume.getValueAt(currentIndex)
let bloodOxygenation = self.bloodOxygenation.getValueAt(currentIndex)
let data = VitalSignsData(xValue: time,
ecgHeartRate: ecgHeartRate,
bloodPressure: bloodPressure,
bloodVolume: bloodVolume,
bloodOxygenation: bloodOxygenation,
isATrace: isATrace)
currentIndex += 1
totalIndex += 1
if totalIndex % 8000 == 0 {
isATrace = !isATrace
}
return data;
}
}
struct VitalSignsData {
let xValue: Double
let ecgHeartRate: Double
let bloodPressure: Double
let bloodVolume: Double
let bloodOxygenation: Double
let isATrace: Bool
}