-
Notifications
You must be signed in to change notification settings - Fork 1
/
write_kine_random.py
104 lines (80 loc) · 3.18 KB
/
write_kine_random.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
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
95
96
97
98
99
100
101
102
# import testdata
import json
from boto import kinesis
import sys
# seed the pseudorandom number generator
from random import seed
from random import randint
import time
import random
kinesis = kinesis.connect_to_region("us-east-2")
print(kinesis.list_streams())
# stream = kinesis.create_stream("BotoDemo", 1)
# print(kinesis.describe_stream("BotoDemo"))
def get_range_heart_rate(rhythm_index):
if rhythm_index==0:
start=100
stop=140
elif rhythm_index==1:
start=100
stop=200
elif rhythm_index==2:
start=80
stop=110
elif rhythm_index==3:
start=30
stop=60
elif rhythm_index==4:
start=0
stop=30
elif rhythm_index==5:
start=60
stop=100
return start,stop
# list_measure_groups=["IMU","GSR","NIRS","Temperature","ECG","PPG","Microphone_Audio"]
list_measure_groups=["IMU","GSR","ECG"]
device_name=["headband","fitbit","chest_mount"]
# seed random number generator
seed(1)
if len(sys.argv)>1:
index=int(sys.argv[1])
# for i in range(500):
i=0
while 1==1:
new_dict={}
new_dict["timestamp"]=int(time.time())
if len(sys.argv)==1:
index=randint(0,10)%3
# index=0
new_dict["userName"]="user"+str(index+1)
new_dict["device_name"]=device_name[index]
if index==0:
# "IMU"
new_dict["detail_result"]={}
new_dict["detail_result"][list_measure_groups[index]]={}
new_dict["detail_result"][list_measure_groups[index]]["StepCount"]=randint(0,10)
new_dict["detail_result"][list_measure_groups[index]]["BodyOrientationPitch"]=randint(0,180)
new_dict["detail_result"][list_measure_groups[index]]["BodyOrientationRoll"]=randint(0,180)
items=["upright","flat","inverted"]
new_dict["detail_result"][list_measure_groups[index]]["BodyOrientationString"]=items[random.randrange(len(items))]
new_dict["detail_result"][list_measure_groups[index]]["BreathRate"]=randint(0,100)
elif index==1:
# "GSR"
new_dict["detail_result"]={}
new_dict["detail_result"][list_measure_groups[index]]={}
new_dict["detail_result"][list_measure_groups[index]]["SkinConductance"]=randint(0,10)
new_dict["detail_result"][list_measure_groups[index]]["SweatRate"]=random.uniform(0, 5)
items=["high","low","moderate"]
new_dict["detail_result"][list_measure_groups[index]]["SweatRateString"]=items[random.randrange(len(items))]
elif index==2:
# "ECG"
new_dict["detail_result"]={}
new_dict["detail_result"][list_measure_groups[index]]={}
items=["tachycardia","atrial_fibrillation","atrial_flutter","bradycardia","ventricular_fibrillation","normal"]
rhythm_index=random.randrange(len(items))
new_dict["detail_result"][list_measure_groups[index]]["HeartRhythmString"]=items[rhythm_index]
start,stop = get_range_heart_rate(rhythm_index)
new_dict["detail_result"][list_measure_groups[index]]["HeartRate"]=random.randint(start, stop)
print("loading ",json.dumps(new_dict))
kinesis.put_record("end-stream", json.dumps(new_dict), "partitionkey")
time.sleep(0.2)