-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdata.php
More file actions
315 lines (229 loc) · 7.42 KB
/
data.php
File metadata and controls
315 lines (229 loc) · 7.42 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
<?php
include_once("config.php");
// Get Date or set current date
$date = date("Y-m-d");
if (isset($_GET['date'])) {
$date = $_GET['date'];
}
// VALIDATION
// Step 1 - Date Validation
if (!validateDate("$date 00:00:00")) {
exit("Date is not valid. Please use YYYY-MM-DD format.");
}
// Step 2 - Do not proceed if Client ID is not set
if (!isset($_SESSION['fb_client_id']) || $_SESSION['fb_client_id'] == '') {
exit("Client ID not available. Please <a href='index.php'>try again</a>");
} else {
$fb_client_id = $_SESSION['fb_client_id'];
}
// GET DATA & SHOW THE CHART
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Fitbit Heart Rate Data for <?php echo $fb_client_id; ?></title>
<!-- Bootstrap -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src='https://code.highcharts.com/10/highcharts.js'></script>
<script src='https://code.highcharts.com/10/modules/exporting.js'></script>
<!-- date picker -->
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.3.0/css/datepicker3.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.3.0/js/bootstrap-datepicker.js"></script>
</head>
<body>
<!-- Header -->
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="./"><strong>Fitbit Heart Rate Intraday Data</strong></a>
</div>
</div>
</nav>
<div style='height:100px;'>
</div>
<!-- Primary data -->
<div class="container">
<div class="well" id="setdate">
<form action='data.php' method=get id='form'>
<div class="row">
<!-- Column for Showing Date Picker -->
<div class="col-md-2">
<div class="input-group date" id="datepicker">
<input type=text class="form-control" readonly name=date placeholder='yyyy-mm-dd' value='<?php echo $date; ?>'>
<div class="input-group-addon">
<span class="glyphicon glyphicon-th"></span>
</div>
</div>
</div><!-- /col-md-2 -->
<div class="col-md-3 pull-right text-right">
<a class="btn btn-success" href='getdata.php?date=<?php echo $date; ?>'>Refresh (Sync with Fitbit)</a>
</div> <!-- /col-md-3 -->
</div> <!-- /row -->
</form>
</div> <!-- /well -->
<?php
// Query the data. Get the raw data and process it
$q = "select id, fbjsondata from `data_raw` where fbdate='$date' and fbuser='$fb_client_id'";
$result = mysqli_query($config_conn, $q);
$seriesarr = array();
if (mysqli_num_rows($result) > 0) {
$series_raw = mysqli_fetch_row($result);
$series = objectToArray(json_decode($series_raw[1]));
foreach ($series['activities-heart-intraday']['dataset'] as $key=>$value) {
$time = $value['time'];
$hb = $value['value'];
$timearr = explode(":",$time);
$datearr = explode("-",$date);
$seriesarr[] = "[Date.UTC($datearr[0],$datearr[1]-1,$datearr[2],$timearr[0],$timearr[1],$timearr[2]), $hb]";
}
}
// Print the data / Show Chart
?>
<div id='charts'></div>
<script>
Highcharts.chart('charts', {
title: {
text: 'Fitbit Heart Rate Data for <?php echo $fb_client_id; ?>'
},
chart: {
zoomType: 'x',
},
subtitle: {
text: '<?php echo $date; ?>'
},
xAxis: {
type: 'datetime',
dateTimeLabelFormats: { // don't display the dummy year
hour: '%I %p',
minute: '%I:%M %p'
},
title: {
text: 'Time'
}
},
yAxis: {
title: {
text: 'Heart Rate'
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'middle'
},
plotOptions: {
series: {
pointStart: Date.UTC(1970, 01, 01, 0, 0, 0)
}
},
series: [{
name: 'Heart Rate',
showInLegend: false,
data: [
<?php
echo implode(",",$seriesarr);
?>
]
}]
});
</script>
<!-- /charts -->
<hr>
<!-- Other data including detailed table and summary -->
<div class="row">
<!-- headers for tables shown later -->
<div class="col-md-5 pull-left">
<h4>Heart Rate Summary</h4>
</div>
<div class="col-md-6 pull-right">
<a class="btn btn-primary pull-right" href="download.php?date=<?php echo $date; ?>">Export to Excel</a>
<h4>Heart Rate Detailed Data</h4>
</div>
<!-- /headers -->
<div class="clear"><!-- --></div>
<!-- Table with Heart Rate Summary -->
<div class="col-md-5 pull-left">
<table class="table table-bordered table-striped">
<thead>
<th>Name</th>
<th>Minutes Spent</th>
<th>Calories</th>
<th>HB Range</th>
</thead>
<?php
$hbsummary = $series['activities-heart'][0];
$i=0;
$color = array('active','success','warning','danger','active','active','active','active');
foreach ($hbsummary['heartRateZones'] as $hbsummarydata1) {
echo "<tr class='$color[$i]'>";
echo "<td>".$hbsummarydata1['name']."</td>\n";
echo "<td>".$hbsummarydata1['minutes']."</td>\n";
echo "<td>".$hbsummarydata1['caloriesOut']."</td>\n";
echo "<td>".$hbsummarydata1['min'].'-'.$hbsummarydata1['max']."</td>\n";
echo "</tr>";
$i++;
}
?>
</table>
</div> <!-- /col-md-5 summary -->
<!-- Table with Heart Rate Detailed Data -->
<div class="col-md-6 pull-right pre-scrollable">
<table class="table table-bordered" id='hrdata'>
<thead>
<th>Date & Time</th>
<th>Heart Rate</th>
</thead>
<?php
if (mysqli_num_rows($result) == '0') {
echo "<tr><td colspan=2 style='height:200px;'>No data available</td></tr>\n";
}
foreach ($series['activities-heart-intraday']['dataset'] as $key=>$value) {
echo "<tr><td>$date $value[time]</td><td>$value[value]</td></tr>\n";
}
?>
</table>
</div> <!-- /col-md-6 detailed -->
<div style='clear:both;'><!-- --></div>
<hr>
© 2017 Vivek Kapoor, <a href='https://exain.wordpress.com'>https://exain.wordpress.com</a>
<P> </P>
</div> <!-- /container -->
<script>
// Date Picker Configuration
$('#datepicker').datepicker({
autoclose: true,
format: "yyyy-mm-dd"
});
$('#datepicker').on('show', function(e){
if ( e.date ) {
$(this).data('stickyDate', e.date);
}
else {
$(this).data('stickyDate', null);
}
});
$('#datepicker').on('hide', function(e){
var stickyDate = $(this).data('stickyDate');
if ( !e.date && stickyDate ) {
$(this).datepicker('setDate', stickyDate);
$(this).data('stickyDate', null);
}
$('#form').submit();
});
</script>
</body>
</html>