Skip to content

Instantly share code, notes, and snippets.

@clarle
Created August 8, 2015 04:54
Show Gist options
  • Save clarle/4563da33a9a1bdc4e156 to your computer and use it in GitHub Desktop.
Save clarle/4563da33a9a1bdc4e156 to your computer and use it in GitHub Desktop.
Blood sugar random data generation
import random
import csv
DAYS = 7
HOURS = 24
data = []
for day in range(DAYS):
for hour in range(HOURS):
sugar_data = {
"day": day,
"hour": hour
}
if ((9 <= hour <= 11) or (13 <= hour <= 15) or (18 <= hour <= 20)):
sugar_data['blood_sugar_level'] = random.randint(130, 230)
else:
sugar_data['blood_sugar_level'] = random.randint(30, 130)
data.append(sugar_data)
with open('sugar.csv', 'wb') as csv_file:
blood_sugar_writer = csv.DictWriter(csv_file, fieldnames=['day', 'hour', 'blood_sugar_level'])
blood_sugar_writer.writeheader()
for point in data:
blood_sugar_writer.writerow(point)
day hour blood_sugar_level
0 0 106
0 1 102
0 2 78
0 3 125
0 4 33
0 5 51
0 6 69
0 7 120
0 8 100
0 9 173
0 10 146
0 11 142
0 12 49
0 13 201
0 14 175
0 15 157
0 16 120
0 17 76
0 18 182
0 19 135
0 20 159
0 21 130
0 22 75
0 23 97
1 0 91
1 1 62
1 2 79
1 3 122
1 4 67
1 5 121
1 6 119
1 7 112
1 8 85
1 9 171
1 10 230
1 11 189
1 12 109
1 13 193
1 14 164
1 15 212
1 16 72
1 17 119
1 18 216
1 19 194
1 20 214
1 21 35
1 22 94
1 23 82
2 0 106
2 1 94
2 2 31
2 3 33
2 4 61
2 5 102
2 6 72
2 7 59
2 8 82
2 9 180
2 10 217
2 11 141
2 12 73
2 13 164
2 14 223
2 15 214
2 16 44
2 17 103
2 18 138
2 19 158
2 20 212
2 21 97
2 22 74
2 23 39
3 0 46
3 1 125
3 2 40
3 3 114
3 4 93
3 5 123
3 6 53
3 7 37
3 8 32
3 9 137
3 10 182
3 11 167
3 12 101
3 13 134
3 14 155
3 15 149
3 16 107
3 17 91
3 18 207
3 19 152
3 20 195
3 21 47
3 22 90
3 23 49
4 0 129
4 1 41
4 2 117
4 3 116
4 4 82
4 5 98
4 6 31
4 7 62
4 8 44
4 9 173
4 10 176
4 11 146
4 12 106
4 13 130
4 14 131
4 15 198
4 16 72
4 17 54
4 18 221
4 19 163
4 20 142
4 21 43
4 22 36
4 23 66
5 0 90
5 1 128
5 2 123
5 3 68
5 4 38
5 5 62
5 6 40
5 7 37
5 8 61
5 9 201
5 10 144
5 11 209
5 12 73
5 13 151
5 14 210
5 15 189
5 16 97
5 17 100
5 18 211
5 19 146
5 20 131
5 21 98
5 22 49
5 23 34
6 0 101
6 1 130
6 2 77
6 3 104
6 4 58
6 5 76
6 6 55
6 7 93
6 8 97
6 9 229
6 10 135
6 11 184
6 12 82
6 13 181
6 14 218
6 15 198
6 16 84
6 17 40
6 18 207
6 19 180
6 20 198
6 21 38
6 22 91
6 23 76
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment