diff --git a/apps/health/ChangeLog b/apps/health/ChangeLog index 9b98e32b7..da68bc0e7 100644 --- a/apps/health/ChangeLog +++ b/apps/health/ChangeLog @@ -23,3 +23,6 @@ 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) +0.25: lib.read* methods now return correctly scaled movement + movement graph in app is now an average, not sum + fix 11pm slot for daily HRM \ No newline at end of file diff --git a/apps/health/app.js b/apps/health/app.js index bd708207b..fdc69dd28 100644 --- a/apps/health/app.js +++ b/apps/health/app.js @@ -59,7 +59,7 @@ function hrmPerHour() { E.showMessage(/*LANG*/"Loading..."); current_selection = "hrmPerHour"; var data = new Uint16Array(24); - var cnt = new Uint8Array(23); + var cnt = new Uint8Array(24); require("health").readDay(new Date(), h=>{ data[h.hr]+=h.bpm; if (h.bpm) cnt[h.hr]++; @@ -87,7 +87,12 @@ function movementPerHour() { E.showMessage(/*LANG*/"Loading..."); current_selection = "movementPerHour"; var data = new Uint16Array(24); - require("health").readDay(new Date(), h=>data[h.hr]+=h.movement); + var cnt = new Uint8Array(24); + require("health").readDay(new Date(), h=>{ + data[h.hr]+=h.movement + cnt[h.hr]++; + }); + data.forEach((d,i)=>data[i] = d/cnt[i]); setButton(menuMovement); barChart(/*LANG*/"HOUR", data); } @@ -96,7 +101,12 @@ function movementPerDay() { E.showMessage(/*LANG*/"Loading..."); current_selection = "movementPerDay"; var data = new Uint16Array(31); - require("health").readDailySummaries(new Date(), h=>data[h.day]+=h.movement); + var cnt = new Uint8Array(31); + require("health").readDailySummaries(new Date(), h=>{ + data[h.hr]+=h.movement + cnt[h.hr]++; + }); + data.forEach((d,i)=>data[i] = d/cnt[i]); setButton(menuMovement); barChart(/*LANG*/"DAY", data); } diff --git a/apps/health/boot.min.js b/apps/health/boot.min.js index afda9189a..0d1a80f4c 100644 --- a/apps/health/boot.min.js +++ b/apps/health/boot.min.js @@ -1,6 +1,5 @@ -(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){90Math.abs(Bangle.getHealthStatus().bpm-b.bpm)&&Bangle.setHRMPower(0,"health")}); -90>8,g.steps&255,g.bpm,Math.min(g.movement,255))}var b=new Date(Date.now()-59E4);a&&0n;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=(new Date(Date.now())).toISOString().split("T")[0],!a.stepGoalNotificationDate||a.stepGoalNotificationDate=a.stepGoal&&(d=(new Date(Date.now())).toISOString().split("T")[0],!a.stepGoalNotificationDate||a.stepGoalNotificationDateBangle.setHRMPower(0,"health"),6E4*a);if(1==a){function b(){Bangle.setHRMPower(1,"health");setTimeout(()=>{Bangle.setHRMPower(0,"health")},6E4)}setTimeout(b,2E5);setTimeout(b,4E5)}}Bangle.on("health",d);Bangle.on("HRM",b=>{90Math.abs(Bangle.getHealthStatus().bpm-b.bpm)&&Bangle.setHRMPower(0,"health")});90{function d(c){return String.fromCharCode(c.steps>>8,c.steps&255,c.bpm,Math.min(c.movement,255))}var b=new Date(Date.now()-59E4);a&&0k;k++){e=g.substr(h,4);if("\xff\xff\xff\xff"!=e){a.steps+=(e.charCodeAt(0)<<8)+e.charCodeAt(1);var l=e.charCodeAt(2);a.bpm+=l;a.movement+=e.charCodeAt(3);a.movCnt++; +l&&a.bpmCnt++}h-=4}a.bpmCnt&&(a.bpm/=a.bpmCnt);a.movCnt&&(a.movement/=a.movCnt);require("Storage").write(b,d(a),f,17988)}}) \ No newline at end of file diff --git a/apps/health/lib.js b/apps/health/lib.js index 3a52ad59f..7ecbd5bff 100644 --- a/apps/health/lib.js +++ b/apps/health/lib.js @@ -29,7 +29,7 @@ exports.readAllRecords = function(d, cb) { day:day+1, hr : hr, min:m*10, steps : (h.charCodeAt(0)<<8) | h.charCodeAt(1), bpm : h.charCodeAt(2), - movement : h.charCodeAt(3) + movement : h.charCodeAt(3)*8 }); } idx += DB_RECORD_LEN; @@ -53,7 +53,7 @@ exports.readDailySummaries = function(d, cb) { day:day+1, steps : (h.charCodeAt(0)<<8) | h.charCodeAt(1), bpm : h.charCodeAt(2), - movement : h.charCodeAt(3) + movement : h.charCodeAt(3)*8 }); } idx += DB_RECORDS_PER_DAY*DB_RECORD_LEN; @@ -75,7 +75,7 @@ exports.readDay = function(d, cb) { hr : hr, min:m*10, steps : (h.charCodeAt(0)<<8) | h.charCodeAt(1), bpm : h.charCodeAt(2), - movement : h.charCodeAt(3) + movement : h.charCodeAt(3)*8 }); } idx += DB_RECORD_LEN; diff --git a/apps/health/lib.min.js b/apps/health/lib.min.js index 4bdc4c0fb..5d0bed2c2 100644 --- a/apps/health/lib.min.js +++ b/apps/health/lib.min.js @@ -1,3 +1,3 @@ -function h(a){return"health-"+a.getFullYear()+"-"+(a.getMonth()+1)+".raw"}function k(a){return 145*(a.getDate()-1)+6*a.getHours()+(0|6*a.getMinutes()/60)}exports.readAllRecords=function(a,f){a=h(a);a=require("Storage").read(a);if(void 0!==a)for(var c=8,d=0;31>d;d++){for(var b=0;24>b;b++)for(var e=0;6>e;e++){var g=a.substr(c,4);"\u00ff\u00ff\u00ff\u00ff"!=g&&f({day:d+1,hr:b,min:10*e,steps:g.charCodeAt(0)<<8|g.charCodeAt(1),bpm:g.charCodeAt(2),movement:g.charCodeAt(3)});c+= -4}c+=4}};exports.readDailySummaries=function(a,f){k(a);a=h(a);a=require("Storage").read(a);if(void 0!==a)for(var c=584,d=0;31>d;d++){var b=a.substr(c,4);"\u00ff\u00ff\u00ff\u00ff"!=b&&f({day:d+1,steps:b.charCodeAt(0)<<8|b.charCodeAt(1),bpm:b.charCodeAt(2),movement:b.charCodeAt(3)});c+=580}};exports.readDay=function(a,f){k(a);var c=h(a);c=require("Storage").read(c);if(void 0!==c){a=8+580*(a.getDate()-1);for(var d=0;24>d;d++)for(var b=0;6>b;b++){var e=c.substr(a,4);"\u00ff\u00ff\u00ff\u00ff"!=e&&f({hr:d, -min:10*b,steps:e.charCodeAt(0)<<8|e.charCodeAt(1),bpm:e.charCodeAt(2),movement:e.charCodeAt(3)});a+=4}}} \ No newline at end of file +function h(a){return"health-"+a.getFullYear()+"-"+(a.getMonth()+1)+".raw"}function k(a){return 145*(a.getDate()-1)+6*a.getHours()+(0|6*a.getMinutes()/60)}exports.readAllRecords=function(a,f){a=h(a);a=require("Storage").read(a);if(void 0!==a)for(var c=8,d=0;31>d;d++){for(var b=0;24>b;b++)for(var e=0;6>e;e++){var g=a.substr(c,4);"\xff\xff\xff\xff"!=g&&f({day:d+1,hr:b,min:10*e,steps:g.charCodeAt(0)<<8|g.charCodeAt(1),bpm:g.charCodeAt(2),movement:8*g.charCodeAt(3)});c+= +4}c+=4}};exports.readDailySummaries=function(a,f){k(a);a=h(a);a=require("Storage").read(a);if(void 0!==a)for(var c=584,d=0;31>d;d++){var b=a.substr(c,4);"\xff\xff\xff\xff"!=b&&f({day:d+1,steps:b.charCodeAt(0)<<8|b.charCodeAt(1),bpm:b.charCodeAt(2),movement:8*b.charCodeAt(3)});c+=580}};exports.readDay=function(a,f){k(a);var c=h(a);c=require("Storage").read(c);if(void 0!==c){a=8+580*(a.getDate()-1);for(var d=0;24>d;d++)for(var b=0;6>b;b++){var e=c.substr(a,4);"\xff\xff\xff\xff"!=e&& +f({hr:d,min:10*b,steps:e.charCodeAt(0)<<8|e.charCodeAt(1),bpm:e.charCodeAt(2),movement:8*e.charCodeAt(3)});a+=4}}} \ No newline at end of file diff --git a/apps/health/metadata.json b/apps/health/metadata.json index a95f6b19b..5ff3bb3a0 100644 --- a/apps/health/metadata.json +++ b/apps/health/metadata.json @@ -2,7 +2,7 @@ "id": "health", "name": "Health Tracking", "shortName": "Health", - "version": "0.24", + "version": "0.25", "description": "Logs health data and provides an app to view it", "icon": "app.png", "tags": "tool,system,health",