-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_ratio.js
45 lines (38 loc) · 932 Bytes
/
run_ratio.js
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
// Run Ratio
function RR(data) {
// threshold cadence for running/walking/standing
const run_threshold = 120;
const walk_threshold = 40;
// check if data series is available
if (!data.hasOwnProperty('seriesSampled') ||
!data.seriesSampled.data.hasOwnProperty('cadence')) {
return null;
}
// extract relevant data
const {
seriesSampled: {
data: {
cadence
}
}
} = data;
const samples = cadence.length;
// put samples to bins
var idx;
var bins = { run: 0, walk: 0, stand: 0 };
for (idx = 0; idx < samples; idx++) {
if (cadence[idx] > run_threshold) {
bins.run++;
} else if (cadence[idx] > walk_threshold) {
bins.walk++;
} else {
bins.stand++;
}
}
bins.run /= samples;
bins.walk /= samples;
bins.stand /= samples;
return (bins.run * 100).toFixed();
}
// Additional code when added to tredict:
//APPEND return RR(this);