Skip to content

Commit

Permalink
health/interface: replace moving average with average
Browse files Browse the repository at this point in the history
  • Loading branch information
nxdefiant committed Nov 20, 2023
1 parent 12dcefe commit 69dbc18
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions apps/health/interface.html
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
var idx = DB_HEADER_LEN;
for (var day = 0; day < 31; day++) {
var dayData = {steps: 0, bpm: 0, movement: 0};
let bpmCnt = 0;
for (var hr = 0; hr < 24; hr++) { // actually 25, see below
for (var m = 0; m < DB_RECORDS_PER_HR; m++) {
var h = data.substr(idx, DB_RECORD_LEN);
Expand All @@ -153,7 +154,8 @@
};
dayData.steps += h.steps; // sum
if (h.bpm > 0) {
dayData.bpm = dayData.bpm > 0 ? (dayData.bpm + h.bpm) / 2 : h.bpm; // average
dayData.bpm = dayData.bpm + h.bpm;
bpmCnt++;
}
dayData.movement += h.movement; // sum
}
Expand All @@ -162,7 +164,9 @@
}
idx += DB_RECORD_LEN; // +1 because we have an extra record with totals
// for the end of the day

if (bpmCnt > 0) {
dayData.bpm = Math.round(dayData.bpm/bpmCnt); // average
}
dailyData[day + 1] = dayData;
}
return dailyData;
Expand Down

0 comments on commit 69dbc18

Please sign in to comment.