-
Notifications
You must be signed in to change notification settings - Fork 2
/
BeatModel.py
45 lines (35 loc) · 1.13 KB
/
BeatModel.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
import json
class BeatModel(object):
raw_data: list
symbol: str
r_peak_index: int
aux_note: str
def __init__(self, json_string: str = None):
super().__init__()
if json_string is None:
return
data = json.loads(json_string)
self.raw_data = json.loads(data['raw_data'])
self.symbol = data['symbol']
self.r_peak_index = data['r_peak_index']
self.aux_note = data['aux_note']
def toDict(self) -> dict:
return {'raw_data': json.dumps(self.raw_data),
'symbol': self.symbol,
'r_peak_index': self.r_peak_index,
'aux_note': self.aux_note}
def toJSONText(self) -> str:
data = self.toDict()
return json.dumps(data)
if __name__ == '__main__':
model = BeatModel()
model.raw_data = [1, 2, 3, 4, 5, 6]
model.symbol = 'N'
model.r_peak_index = 3
text = model.toJSONText()
print(text)
model2 = BeatModel(text)
print(model2.toJSONText())
print(model2.raw_data)
print(model2.symbol, type(model2.symbol))
print(model2.r_peak_index, type(model2.r_peak_index))