-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_demo_data.py
54 lines (49 loc) · 1.53 KB
/
generate_demo_data.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
import math
from datetime import datetime, timedelta
from dateutil import rrule
from random import randint
import json
def generate_heartrate_data ():
date_end = datetime.today()
date_start = date_end - timedelta(days=20)
dates = []
for day in rrule.rrule(rrule.DAILY, dtstart=date_start,
until=date_end):
dates.append(day)
result = []
for day in dates:
value_dict1 = {
'type': 'Heartrate',
'unit': 'bpm',
'timestamp': day.strftime('%Y-%m-%dT%H:%M:%S.%f'),
'deviceID': '123456789abc',
'values': {
'val': 60 + randint(0, 90)
}
}
value_dict2 = {
'type': 'Heartrate',
'unit': 'bpm',
'timestamp': (day + timedelta(hours=6)).strftime('%Y-%m-%dT%H:%M:%S.%f'),
'deviceID': '123456789abc',
'values': {
'val': 60 + randint(0, 90)
}
}
value_dict3 = {
'type': 'Heartrate',
'unit': 'bpm',
'timestamp': (day + timedelta(hours=9)).strftime('%Y-%m-%dT%H:%M:%S.%f'),
'deviceID': '123456789abc',
'values': {
'val': 60 + randint(0, 90)
}
}
result.append(value_dict1)
result.append(value_dict2)
result.append(value_dict3)
return result
if __name__ == "__main__":
js = generate_heartrate_data()
with open('test_data.json', 'w') as outfile:
json.dump(js, outfile)