forked from FOSS/BangleApps
Correct calculation of daily summary for movement
- Heartrate was being summed from the DB instead of movement itself - The daily average value was inadvertently being divided by 8 relative the hourly data, resulting in very low precisionmaster
parent
4061bd2f5e
commit
e94f420356
|
@ -22,3 +22,4 @@
|
|||
0.21: Update boot.min.js.
|
||||
0.22: Fix timeout for heartrate sensor on 3 minute setting (#2435)
|
||||
0.23: Fix HRM logic
|
||||
0.24: Correct daily health summary for movement (some logic errors resulted in garbage data being written)
|
||||
|
|
|
@ -52,7 +52,7 @@ Bangle.on("health", health => {
|
|||
return String.fromCharCode(
|
||||
health.steps>>8,health.steps&255, // 16 bit steps
|
||||
health.bpm, // 8 bit bpm
|
||||
Math.min(health.movement / 8, 255)); // movement
|
||||
Math.min(health.movement, 255)); // movement
|
||||
}
|
||||
|
||||
var rec = getRecordIdx(d);
|
||||
|
@ -68,6 +68,12 @@ Bangle.on("health", health => {
|
|||
require("Storage").write(fn, "HEALTH1\0", 0, DB_FILE_LEN); // header
|
||||
}
|
||||
var recordPos = DB_HEADER_LEN+(rec*DB_RECORD_LEN);
|
||||
|
||||
// scale down reported movement value in order to fit it within a
|
||||
// uint8 DB field
|
||||
health = Object.assign({}, health);
|
||||
health.movement /= 8;
|
||||
|
||||
require("Storage").write(fn, getRecordData(health), recordPos, DB_FILE_LEN);
|
||||
if (rec%DB_RECORDS_PER_DAY != DB_RECORDS_PER_DAY-2) return;
|
||||
// we're at the end of the day. Read in all of the data for the day and sum it up
|
||||
|
@ -82,10 +88,10 @@ Bangle.on("health", health => {
|
|||
var dt = f.substr(recordPos, DB_RECORD_LEN);
|
||||
if (dt!="\xFF\xFF\xFF\xFF") {
|
||||
health.steps += (dt.charCodeAt(0)<<8)+dt.charCodeAt(1);
|
||||
health.movement += dt.charCodeAt(2);
|
||||
health.movCnt++;
|
||||
var bpm = dt.charCodeAt(2);
|
||||
health.bpm += bpm;
|
||||
health.movement += dt.charCodeAt(3);
|
||||
health.movCnt++;
|
||||
if (bpm) health.bpmCnt++;
|
||||
}
|
||||
recordPos -= DB_RECORD_LEN;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
function l(){var a=require("Storage").readJSON("health.json",1)||{},d=Bangle.getHealthStatus("day").steps;a.stepGoalNotification&&0<a.stepGoal&&d>=a.stepGoal&&(d=(new Date(Date.now())).toISOString().split("T")[0],!a.stepGoalNotificationDate||a.stepGoalNotificationDate<d)&&(Bangle.buzz(200,.5),require("notify").show({title:a.stepGoal+" steps",body:"You reached your step goal!",icon:atob("DAyBABmD6BaBMAsA8BCBCBCBCA8AAA==")}),a.stepGoalNotificationDate=d,require("Storage").writeJSON("health.json",
|
||||
a))}(function(){var a=0|(require("Storage").readJSON("health.json",1)||{}).hrm;if(1==a||2==a){var d=function(){Bangle.setHRMPower(1,"health");setTimeout(function(){return Bangle.setHRMPower(0,"health")},6E4*a);if(1==a){var b=function(){Bangle.setHRMPower(1,"health");setTimeout(function(){Bangle.setHRMPower(0,"health")},6E4)};setTimeout(b,2E5);setTimeout(b,4E5)}};Bangle.on("health",d);Bangle.on("HRM",function(b){90<b.confidence&&1>Math.abs(Bangle.getHealthStatus().bpm-b.bpm)&&Bangle.setHRMPower(0,
|
||||
"health")});90<Bangle.getHealthStatus().bpmConfidence||d()}else Bangle.setHRMPower(!!a,"health")})();Bangle.on("health",function(a){function d(c){return String.fromCharCode(c.steps>>8,c.steps&255,c.bpm,Math.min(c.movement/8,255))}var b=new Date(Date.now()-59E4);a&&0<a.steps&&l();var f=function(c){return 145*(c.getDate()-1)+6*c.getHours()+(0|6*c.getMinutes()/60)}(b);b=function(c){return"health-"+c.getFullYear()+"-"+(c.getMonth()+1)+".raw"}(b);var g=require("Storage").read(b);if(g){var e=g.substr(8+
|
||||
4*f,4);if("\u00ff\u00ff\u00ff\u00ff"!=e){print("HEALTH ERR: Already written!");return}}else require("Storage").write(b,"HEALTH1\x00",0,17988);var h=8+4*f;require("Storage").write(b,d(a),h,17988);if(143==f%145)if(f=h+4,"\u00ff\u00ff\u00ff\u00ff"!=g.substr(f,4))print("HEALTH ERR: Daily summary already written!");else{a={steps:0,bpm:0,movement:0,movCnt:0,bpmCnt:0};for(var k=0;144>k;k++)e=g.substr(h,4),"\u00ff\u00ff\u00ff\u00ff"!=e&&(a.steps+=(e.charCodeAt(0)<<8)+e.charCodeAt(1),a.movement+=e.charCodeAt(2),
|
||||
a.movCnt++,e=e.charCodeAt(2),a.bpm+=e,e&&a.bpmCnt++),h-=4;a.bpmCnt&&(a.bpm/=a.bpmCnt);a.movCnt&&(a.movement/=a.movCnt);require("Storage").write(b,d(a),f,17988)}})
|
||||
(function(){var a=0|(require("Storage").readJSON("health.json",1)||{}).hrm;if(1==a||2==a){var c=function(){Bangle.setHRMPower(1,"health");setTimeout(function(){return Bangle.setHRMPower(0,"health")},6E4*a);if(1==a){var b=function(){Bangle.setHRMPower(1,"health");setTimeout(function(){Bangle.setHRMPower(0,"health")},6E4)};setTimeout(b,2E5);setTimeout(b,4E5)}};Bangle.on("health",c);Bangle.on("HRM",function(b){90<b.confidence&&1>Math.abs(Bangle.getHealthStatus().bpm-b.bpm)&&Bangle.setHRMPower(0,"health")});
|
||||
90<Bangle.getHealthStatus().bpmConfidence||c()}else Bangle.setHRMPower(!!a,"health")})();
|
||||
Bangle.on("health",function(a){function c(g){return String.fromCharCode(g.steps>>8,g.steps&255,g.bpm,Math.min(g.movement,255))}var b=new Date(Date.now()-59E4);a&&0<a.steps&&q();var f=145*(b.getDate()-1)+6*b.getHours()+(0|6*b.getMinutes()/60);b="health-"+b.getFullYear()+"-"+(b.getMonth()+1)+".raw";var h=require("Storage").read(b);if(h){var e=h.substr(8+4*f,4);if("\xff\xff\xff\xff"!=e){print("HEALTH ERR: Already written!");return}}else require("Storage").write(b,"HEALTH1\x00",0,17988);var m=
|
||||
8+4*f;a=Object.assign({},a);a.movement/=8;require("Storage").write(b,c(a),m,17988);if(143==f%145)if(f=m+4,"\xff\xff\xff\xff"!=h.substr(f,4))print("HEALTH ERR: Daily summary already written!");else{a={steps:0,bpm:0,movement:0,movCnt:0,bpmCnt:0};for(var n=0;144>n;n++){e=h.substr(m,4);if("\xff\xff\xff\xff"!=e){a.steps+=(e.charCodeAt(0)<<8)+e.charCodeAt(1);var p=e.charCodeAt(2);a.bpm+=p;a.movement+=e.charCodeAt(3);a.movCnt++;p&&a.bpmCnt++}m-=4}a.bpmCnt&&(a.bpm/=a.bpmCnt);a.movCnt&&(a.movement/=
|
||||
a.movCnt);require("Storage").write(b,c(a),f,17988)}});
|
||||
function q(){var a=require("Storage").readJSON("health.json",1)||{},c=Bangle.getHealthStatus("day").steps;a.stepGoalNotification&&0<a.stepGoal&&c>=a.stepGoal&&(c=(new Date(Date.now())).toISOString().split("T")[0],!a.stepGoalNotificationDate||a.stepGoalNotificationDate<c)&&(Bangle.buzz(200,.5),require("notify").show({title:a.stepGoal+" steps",body:"You reached your step goal!",icon:atob("DAyBABmD6BaBMAsA8BCBCBCBCA8AAA==")}),a.stepGoalNotificationDate=c,require("Storage").writeJSON("health.json",a))}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"id": "health",
|
||||
"name": "Health Tracking",
|
||||
"shortName": "Health",
|
||||
"version": "0.23",
|
||||
"version": "0.24",
|
||||
"description": "Logs health data and provides an app to view it",
|
||||
"icon": "app.png",
|
||||
"tags": "tool,system,health",
|
||||
|
|
Loading…
Reference in New Issue