forked from QiXi9409/Simultaneous_ECG_Heartbeat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_annotator.py
50 lines (42 loc) · 1.31 KB
/
data_annotator.py
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
from raw_generator import generator
class annotator(generator):
def __init__(self):
super().__init__()
self.time = []
self.ann = []
self.r_peak = []
def annotation(self):
for i in range(len(self.label)):
sin_label = self.label[i]
sin_data = self.data[i]
time = sin_label.sample
ann = sin_label.symbol
remove = []
for j in range(len(ann)):
ann[j] = self.mapping(ann[j])
if ann[j] == -1:
remove.append(j)
ann = [ann[i] for i in range(len(ann)) if i not in remove]
time = [time[i] for i in range(len(time)) if i not in remove]
self.time.append(time)
self.ann.append(ann)
self.r_peak.append(time)
self.label = self.ann
def mapping(self, type):
N = ['L', 'R', 'e', 'j', 'N']
S = ['a', 'A', 'S', 'J']
V = ['E', 'V']
F = ['F']
Q = ['/', 'Q', 'f']
if type in N:
return 0
elif type in S:
return 1
elif type in V:
return 2
elif type in F:
return 3
elif type in Q:
return 4
else:
return -1