Merge pull request #3106 from nxdefiant/master

health/interace: Replace moving average for bpm with avg
master
Gordon Williams 2023-11-20 09:30:14 +00:00 committed by GitHub
commit c0dbd64a43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 2 deletions

View File

@ -139,6 +139,7 @@ function getDailyData(data) {
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);
@ -152,7 +153,10 @@ function getDailyData(data) {
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;
@ -160,7 +164,9 @@ function getDailyData(data) {
}
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;