Skip to content

Commit

Permalink
Merge pull request #3106 from nxdefiant/master
Browse files Browse the repository at this point in the history
health/interace: Replace moving average for bpm with avg
  • Loading branch information
gfwilliams authored Nov 20, 2023
2 parents 9ea23e3 + 69dbc18 commit c0dbd64
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 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 @@ -152,15 +153,20 @@
movement : h.charCodeAt(3)
};
dayData.steps += h.steps; // sum
dayData.bpm = (dayData.bpm + h.bpm) / 2; // average
if (h.bpm > 0) {
dayData.bpm = dayData.bpm + h.bpm;
bpmCnt++;
}
dayData.movement += h.movement; // sum
}
idx += DB_RECORD_LEN;
}
}
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 c0dbd64

Please sign in to comment.