From 08718a504d259d13bd6e80e5c1a7fefd3a7e92b3 Mon Sep 17 00:00:00 2001 From: Stiralbios Date: Wed, 11 May 2022 21:58:00 +0200 Subject: [PATCH 1/9] [ActivityReminder] First attempt to rework the inactivity detection --- apps/activityreminder/ChangeLog | 1 + apps/activityreminder/README.md | 4 +- apps/activityreminder/app.js | 50 ++++++----- apps/activityreminder/boot.js | 46 +++++----- apps/activityreminder/lib.js | 41 +++++++-- apps/activityreminder/metadata.json | 4 +- apps/activityreminder/settings.js | 126 +++++++++++++++------------- 7 files changed, 160 insertions(+), 112 deletions(-) diff --git a/apps/activityreminder/ChangeLog b/apps/activityreminder/ChangeLog index ef387d098..d4b5100a2 100644 --- a/apps/activityreminder/ChangeLog +++ b/apps/activityreminder/ChangeLog @@ -2,3 +2,4 @@ 0.02: Fix the settings bug and some tweaking 0.03: Do not alarm while charging 0.04: Obey system quiet mode +0.05: Battery optimisation, add the pause option, bug fixes diff --git a/apps/activityreminder/README.md b/apps/activityreminder/README.md index e8be66f3c..25e2c8d35 100644 --- a/apps/activityreminder/README.md +++ b/apps/activityreminder/README.md @@ -7,8 +7,8 @@ Different settings can be personalized: - Enable : Enable/Disable the app - Start hour: Hour to start the reminder - End hour: Hour to end the reminder -- Max inactivity: Maximum inactivity time to allow before the alert. From 15 to 60 min +- Max inactivity: Maximum inactivity time to allow before the alert. From 15 to 120 min - Dismiss delay: Delay added before the next alert if the alert is dismissed. From 5 to 60 min - Notice: If Dissmiss delay > Max inactivity then it will be equal Max inactivity +- Pause delay: Same as Dismiss delay but longer (usefull for meetings and such). From 30 to 240 min - Min steps: Minimal amount of steps to count as an activity diff --git a/apps/activityreminder/app.js b/apps/activityreminder/app.js index 811399ca6..fbf1b377e 100644 --- a/apps/activityreminder/app.js +++ b/apps/activityreminder/app.js @@ -1,40 +1,44 @@ -function drawAlert(){ - E.showPrompt("Inactivity detected",{ - title:"Activity reminder", - buttons : {"Ok": true,"Dismiss": false} - }).then(function(v) { - if(v == true){ - stepsArray = stepsArray.slice(0, activityreminder.maxInnactivityMin - 3); - require("activityreminder").saveStepsArray(stepsArray); - } - if(v == false){ - stepsArray = stepsArray.slice(0, activityreminder.maxInnactivityMin - activityreminder.dismissDelayMin); - require("activityreminder").saveStepsArray(stepsArray); - } +function drawAlert() { + E.showPrompt("Inactivity detected", { + title: "Activity reminder", + buttons: { "Ok": 1, "Dismiss": 2, "Pause": 3 } + }).then(function (v) { + if (v == 1) { + activityreminder_data.okDate = new Date(); + } + if (v == 2) { + activityreminder_data.dismissDate = new Date(); + } + if (v == 3) { + activityreminder_data.pauseDate = new Date(); + } + activityreminder.saveData(activityreminder_data); load(); }); // Obey system quiet mode: - if (!(require('Storage').readJSON('setting.json',1)||{}).quiet) { + if (!(storage.readJSON('setting.json', 1) || {}).quiet) { Bangle.buzz(400); } setTimeout(load, 20000); } -function run(){ - if(stepsArray.length == activityreminder.maxInnactivityMin){ - if (stepsArray[0] - stepsArray[stepsArray.length-1] < activityreminder.minSteps){ - drawAlert(); - } - }else{ - eval(require("Storage").read("activityreminder.settings.js"))(()=>load()); +function run() { + if (activityreminder.mustAlert(activityreminder_data, activityreminder_settings)) { + if (stepsArray[0] - stepsArray[stepsArray.length - 1] < activityreminder_settings.minSteps) { + drawAlert(); } + } else { + eval(storage.read("activityreminder.settings.js"))(() => load()); + } } +const activityreminder = require("activityreminder"); +const storage = require("Storage"); g.clear(); Bangle.loadWidgets(); Bangle.drawWidgets(); -activityreminder = require("activityreminder").loadSettings(); -stepsArray = require("activityreminder").loadStepsArray(); +activityreminder_settings = activityreminder.loadSettings(); +activityreminder_data = activityreminder.loadData(); run(); diff --git a/apps/activityreminder/boot.js b/apps/activityreminder/boot.js index 09aa9d757..1c08f6c9c 100644 --- a/apps/activityreminder/boot.js +++ b/apps/activityreminder/boot.js @@ -1,30 +1,38 @@ -function run(){ - if (Bangle.isCharging()) return; +function run() { + if (isNotWorn()) return; var now = new Date(); var h = now.getHours(); - if(h >= activityreminder.startHour && h < activityreminder.endHour){ - var health = Bangle.getHealthStatus("day"); - stepsArray.unshift(health.steps); - stepsArray = stepsArray.slice(0, activityreminder.maxInnactivityMin); - require("activityreminder").saveStepsArray(stepsArray); - } - else{ - if(stepsArray != []){ - stepsArray = []; - require("activityreminder").saveStepsArray(stepsArray); + var doAlert = false; + var doSave = false; + var health = Bangle.getHealthStatus("day"); + + if (h >= activityreminder_settings.startHour && h < activityreminder_settings.endHour) { + if (health.steps - activityreminder_data.stepsOnDate >= activityreminder_settings.minSteps) { + activityreminder_data.stepsOnDate = health.steps; + activityreminder_data.stepsDate = now; + doSave = true; } + doAlert = activityreminder.mustAlert(activityreminder_data, activityreminder_settings); } - if(stepsArray.length >= activityreminder.maxInnactivityMin){ - if (stepsArray[0] - stepsArray[stepsArray.length-1] < activityreminder.minSteps){ - load('activityreminder.app.js'); - } + + if (doSave) { + activityreminder.saveData(activityreminder_data); + } + if (doAlert) { + load('activityreminder.app.js'); } } +function isNotWorn() { + // todo check temperature and mouvement in a futur release + return Bangle.isCharging(); +} -activityreminder = require("activityreminder").loadSettings(); -if(activityreminder.enabled) { - stepsArray = require("activityreminder").loadStepsArray(); +const activityreminder = require("activityreminder"); +activityreminder_settings = activityreminder.loadSettings(); +if (activityreminder_settings.enabled) { + activityreminder_data = activityreminder.loadData(); + activityreminder.saveData(activityreminder_data); setInterval(run, 60000); } diff --git a/apps/activityreminder/lib.js b/apps/activityreminder/lib.js index 712842fba..e33428b06 100644 --- a/apps/activityreminder/lib.js +++ b/apps/activityreminder/lib.js @@ -1,22 +1,45 @@ -exports.loadSettings = function() { +const storage = require("Storage"); + +exports.loadSettings = function () { return Object.assign({ enabled: true, startHour: 9, endHour: 20, maxInnactivityMin: 30, dismissDelayMin: 15, + pauseDelayMin: 120, minSteps: 50 - }, require("Storage").readJSON("activityreminder.s.json", true) || {}); + }, storage.readJSON("activityreminder.s.json", true) || {}); }; -exports.writeSettings = function(settings){ - require("Storage").writeJSON("activityreminder.s.json", settings); +exports.writeSettings = function (settings) { + storage.writeJSON("activityreminder.s.json", settings); }; -exports.saveStepsArray = function(stepsArray) { - require("Storage").writeJSON("activityreminder.sa.json", stepsArray); +exports.saveData = function (data) { + storage.writeJSON("activityreminder.data.json", data); }; -exports.loadStepsArray = function(){ - return require("Storage").readJSON("activityreminder.sa.json") || []; -}; \ No newline at end of file +exports.loadData = function () { + var health = Bangle.getHealthStatus("day"); + return Object.assign({ + stepsDate: new Date(), + stepsOnDate: health.steps, + okDate: new Date('1/1/1970'), + dismissDate: new Date('1/1/1970'), + pauseDate: new Date('1/1/1970'), + }, + storage.readJSON("activityreminder.data.json") || {}); +}; + +exports.mustAlert = function(activityreminder_data, activityreminder_settings) { + var now = new Date(); + if ((now - activityreminder_data.stepsDate) / 60000 > activityreminder_settings.maxInnactivityMin) { // inactivity detected + if ((now - activityreminder_settings.okDate) / 60000 > 3 && // last alert was more than 3 min ago + (now - activityreminder_settings.dismissDate) / 60000 > activityreminder_settings.dismissDelayMin && // last alert was more than dismissDelayMin ago + (now - activityreminder_settings.pauseDate) / 60000 > activityreminder_settings.pauseDelayMin) { // last alert was more than pauseDelayMin ago + return true; + } + } + return false; +} \ No newline at end of file diff --git a/apps/activityreminder/metadata.json b/apps/activityreminder/metadata.json index 89b0fbc0b..15f10f2ed 100644 --- a/apps/activityreminder/metadata.json +++ b/apps/activityreminder/metadata.json @@ -3,7 +3,7 @@ "name": "Activity Reminder", "shortName":"Activity Reminder", "description": "A reminder to take short walks for the ones with a sedentary lifestyle", - "version":"0.04", + "version":"0.05", "icon": "app.png", "type": "app", "tags": "tool,activity", @@ -18,6 +18,6 @@ ], "data": [ {"name": "activityreminder.s.json"}, - {"name": "activityreminder.sa.json"} + {"name": "activityreminder.data.json"} ] } diff --git a/apps/activityreminder/settings.js b/apps/activityreminder/settings.js index e4f44efc6..6cd42913a 100644 --- a/apps/activityreminder/settings.js +++ b/apps/activityreminder/settings.js @@ -1,64 +1,76 @@ -(function(back) { +(function (back) { // Load settings - var settings = require("activityreminder").loadSettings(); + const storage = require("Storage"); + var settings = storage.loadSettings(); // Show the menu E.showMenu({ - "" : { "title" : "Activity Reminder" }, - "< Back" : () => back(), - 'Enable': { - value: settings.enabled, - format: v => v?"Yes":"No", - onchange: v => { - settings.enabled = v; - require("activityreminder").writeSettings(settings); - } + "": { "title": "Activity Reminder" }, + "< Back": () => back(), + 'Enable': { + value: settings.enabled, + format: v => v ? "Yes" : "No", + onchange: v => { + settings.enabled = v; + storage.writeSettings(settings); + } + }, + 'Start hour': { + value: settings.startHour, + min: 0, max: 24, + onchange: v => { + settings.startHour = v; + storage.writeSettings(settings); + } + }, + 'End hour': { + value: settings.endHour, + min: 0, max: 24, + onchange: v => { + settings.endHour = v; + storage.writeSettings(settings); + } + }, + 'Max inactivity': { + value: settings.maxInnactivityMin, + min: 15, max: 120, + onchange: v => { + settings.maxInnactivityMin = v; + storage.writeSettings(settings); }, - 'Start hour': { - value: settings.startHour, - min: 0, max: 24, - onchange: v => { - settings.startHour = v; - require("activityreminder").writeSettings(settings); - } - }, - 'End hour': { - value: settings.endHour, - min: 0, max: 24, - onchange: v => { - settings.endHour = v; - require("activityreminder").writeSettings(settings); - } - }, - 'Max inactivity': { - value: settings.maxInnactivityMin, - min: 15, max: 120, - onchange: v => { - settings.maxInnactivityMin = v; - require("activityreminder").writeSettings(settings); - }, - format: x => { - return x + " min"; - } - }, - 'Dismiss delay': { - value: settings.dismissDelayMin, - min: 5, max: 60, - onchange: v => { - settings.dismissDelayMin = v; - require("activityreminder").writeSettings(settings); - }, - format: x => { - return x + " min"; - } - }, - 'Min steps': { - value: settings.minSteps, - min: 10, max: 500, - onchange: v => { - settings.minSteps = v; - require("activityreminder").writeSettings(settings); - } - } + format: x => { + return x + " min"; + } + }, + 'Dismiss delay': { + value: settings.dismissDelayMin, + min: 5, max: 60, + onchange: v => { + settings.dismissDelayMin = v; + storage.writeSettings(settings); + }, + format: x => { + return x + " min"; + } + }, + 'Pause delay': { + value: settings.pauseDelayMin, + min: 30, max: 240, + onchange: v => { + settings.dismissDelayMin = v; + storage.writeSettings(settings); + }, + format: x => { + return x + " min"; + } + }, + 'Min steps': { + value: settings.minSteps, + min: 10, max: 500, + onchange: v => { + settings.minSteps = v; + storage.writeSettings(settings); + } + } }); }) From 76c80c6f934997d72ea30c30621c11964f409220 Mon Sep 17 00:00:00 2001 From: Stiralbios Date: Wed, 11 May 2022 22:11:33 +0200 Subject: [PATCH 2/9] [ActivityReminder] Try to fix settings --- apps/activityreminder/settings.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/apps/activityreminder/settings.js b/apps/activityreminder/settings.js index 6cd42913a..0557826df 100644 --- a/apps/activityreminder/settings.js +++ b/apps/activityreminder/settings.js @@ -1,7 +1,6 @@ (function (back) { // Load settings - const storage = require("Storage"); - var settings = storage.loadSettings(); + var settings = require("Storage").loadSettings(); // Show the menu E.showMenu({ @@ -12,7 +11,7 @@ format: v => v ? "Yes" : "No", onchange: v => { settings.enabled = v; - storage.writeSettings(settings); + require("Storage").writeSettings(settings); } }, 'Start hour': { @@ -20,7 +19,7 @@ min: 0, max: 24, onchange: v => { settings.startHour = v; - storage.writeSettings(settings); + require("Storage").writeSettings(settings); } }, 'End hour': { @@ -28,7 +27,7 @@ min: 0, max: 24, onchange: v => { settings.endHour = v; - storage.writeSettings(settings); + require("Storage").writeSettings(settings); } }, 'Max inactivity': { @@ -36,7 +35,7 @@ min: 15, max: 120, onchange: v => { settings.maxInnactivityMin = v; - storage.writeSettings(settings); + require("Storage").writeSettings(settings); }, format: x => { return x + " min"; @@ -47,7 +46,7 @@ min: 5, max: 60, onchange: v => { settings.dismissDelayMin = v; - storage.writeSettings(settings); + require("Storage").writeSettings(settings); }, format: x => { return x + " min"; @@ -57,8 +56,8 @@ value: settings.pauseDelayMin, min: 30, max: 240, onchange: v => { - settings.dismissDelayMin = v; - storage.writeSettings(settings); + settings.pauseDelayMin = v; + require("Storage").writeSettings(settings); }, format: x => { return x + " min"; @@ -69,7 +68,7 @@ min: 10, max: 500, onchange: v => { settings.minSteps = v; - storage.writeSettings(settings); + require("Storage").writeSettings(settings); } } }); From 5516a87b7734bdb800bb3e0b603ee70c84065817 Mon Sep 17 00:00:00 2001 From: Stiralbios Date: Wed, 11 May 2022 22:24:02 +0200 Subject: [PATCH 3/9] [ActivityReminder] fix my mistake with settings --- apps/activityreminder/settings.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/apps/activityreminder/settings.js b/apps/activityreminder/settings.js index 0557826df..134279f41 100644 --- a/apps/activityreminder/settings.js +++ b/apps/activityreminder/settings.js @@ -1,6 +1,7 @@ (function (back) { // Load settings - var settings = require("Storage").loadSettings(); + const activityreminder = require("activityreminder"); + var settings = activityreminder.loadSettings(); // Show the menu E.showMenu({ @@ -11,7 +12,7 @@ format: v => v ? "Yes" : "No", onchange: v => { settings.enabled = v; - require("Storage").writeSettings(settings); + activityreminder.writeSettings(settings); } }, 'Start hour': { @@ -19,7 +20,7 @@ min: 0, max: 24, onchange: v => { settings.startHour = v; - require("Storage").writeSettings(settings); + activityreminder.writeSettings(settings); } }, 'End hour': { @@ -27,7 +28,7 @@ min: 0, max: 24, onchange: v => { settings.endHour = v; - require("Storage").writeSettings(settings); + activityreminder.writeSettings(settings); } }, 'Max inactivity': { @@ -35,7 +36,7 @@ min: 15, max: 120, onchange: v => { settings.maxInnactivityMin = v; - require("Storage").writeSettings(settings); + activityreminder.writeSettings(settings); }, format: x => { return x + " min"; @@ -46,7 +47,7 @@ min: 5, max: 60, onchange: v => { settings.dismissDelayMin = v; - require("Storage").writeSettings(settings); + activityreminder.writeSettings(settings); }, format: x => { return x + " min"; @@ -57,7 +58,7 @@ min: 30, max: 240, onchange: v => { settings.pauseDelayMin = v; - require("Storage").writeSettings(settings); + activityreminder.writeSettings(settings); }, format: x => { return x + " min"; @@ -68,7 +69,7 @@ min: 10, max: 500, onchange: v => { settings.minSteps = v; - require("Storage").writeSettings(settings); + activityreminder.writeSettings(settings); } } }); From a5085c93c21e8f7f444a8ff2ffcc0d07d4c37a87 Mon Sep 17 00:00:00 2001 From: Stiralbios Date: Wed, 11 May 2022 22:31:34 +0200 Subject: [PATCH 4/9] [ActivityReminder] Fix default dates for the data --- apps/activityreminder/lib.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/activityreminder/lib.js b/apps/activityreminder/lib.js index e33428b06..329087649 100644 --- a/apps/activityreminder/lib.js +++ b/apps/activityreminder/lib.js @@ -25,9 +25,9 @@ exports.loadData = function () { return Object.assign({ stepsDate: new Date(), stepsOnDate: health.steps, - okDate: new Date('1/1/1970'), - dismissDate: new Date('1/1/1970'), - pauseDate: new Date('1/1/1970'), + okDate: new Date(1970, 1, 1), + dismissDate: new Date(1970, 1, 1), + pauseDate: new Date(1970, 1, 1), }, storage.readJSON("activityreminder.data.json") || {}); }; From ffcf550beaa8297c83514cd84a27796eb66ca983 Mon Sep 17 00:00:00 2001 From: Stiralbios Date: Wed, 11 May 2022 23:51:46 +0200 Subject: [PATCH 5/9] [ActivityReminder] Remove a forgotten part of the old code --- apps/activityreminder/app.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/apps/activityreminder/app.js b/apps/activityreminder/app.js index fbf1b377e..7338984dc 100644 --- a/apps/activityreminder/app.js +++ b/apps/activityreminder/app.js @@ -25,9 +25,7 @@ function drawAlert() { function run() { if (activityreminder.mustAlert(activityreminder_data, activityreminder_settings)) { - if (stepsArray[0] - stepsArray[stepsArray.length - 1] < activityreminder_settings.minSteps) { - drawAlert(); - } + drawAlert(); } else { eval(storage.read("activityreminder.settings.js"))(() => load()); } From 689e6e74702dc1018daa22f7b242888ad3aece95 Mon Sep 17 00:00:00 2001 From: Stiralbios Date: Thu, 12 May 2022 10:30:11 +0200 Subject: [PATCH 6/9] Fix dates loading from file --- apps/activityreminder/boot.js | 24 +++++++++++------------- apps/activityreminder/lib.js | 24 ++++++++++++++++++------ 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/apps/activityreminder/boot.js b/apps/activityreminder/boot.js index 1c08f6c9c..bc07ebc28 100644 --- a/apps/activityreminder/boot.js +++ b/apps/activityreminder/boot.js @@ -2,25 +2,21 @@ function run() { if (isNotWorn()) return; var now = new Date(); var h = now.getHours(); - var doAlert = false; - var doSave = false; var health = Bangle.getHealthStatus("day"); if (h >= activityreminder_settings.startHour && h < activityreminder_settings.endHour) { - if (health.steps - activityreminder_data.stepsOnDate >= activityreminder_settings.minSteps) { + if (health.steps - activityreminder_data.stepsOnDate >= activityreminder_settings.minSteps // more steps made than needed + || health.steps < activityreminder_data.stepsOnDate) { // new day or reboot of the watch activityreminder_data.stepsOnDate = health.steps; activityreminder_data.stepsDate = now; - doSave = true; + activityreminder.saveData(activityreminder_data); + } + + if(activityreminder.mustAlert(activityreminder_data, activityreminder_settings)){ + load('activityreminder.app.js'); } - doAlert = activityreminder.mustAlert(activityreminder_data, activityreminder_settings); } - if (doSave) { - activityreminder.saveData(activityreminder_data); - } - if (doAlert) { - load('activityreminder.app.js'); - } } function isNotWorn() { @@ -32,7 +28,9 @@ const activityreminder = require("activityreminder"); activityreminder_settings = activityreminder.loadSettings(); if (activityreminder_settings.enabled) { activityreminder_data = activityreminder.loadData(); - activityreminder.saveData(activityreminder_data); + if(activityreminder_data.firstLoad){ + activityreminder_data.firstLoad =false; + activityreminder.saveData(activityreminder_data); + } setInterval(run, 60000); } - diff --git a/apps/activityreminder/lib.js b/apps/activityreminder/lib.js index 329087649..141579cae 100644 --- a/apps/activityreminder/lib.js +++ b/apps/activityreminder/lib.js @@ -22,20 +22,32 @@ exports.saveData = function (data) { exports.loadData = function () { var health = Bangle.getHealthStatus("day"); - return Object.assign({ + var data = Object.assign({ + firstLoad: true, stepsDate: new Date(), stepsOnDate: health.steps, - okDate: new Date(1970, 1, 1), - dismissDate: new Date(1970, 1, 1), - pauseDate: new Date(1970, 1, 1), + okDate: new Date(1970), + dismissDate: new Date(1970), + pauseDate: new Date(1970), }, - storage.readJSON("activityreminder.data.json") || {}); + storage.readJSON("activityreminder.data.json") || {}); + + if(typeof(data.stepsDate) == "string") + data.stepsDate = new Date(data.stepsDate); + if(typeof(data.okDate) == "string") + data.okDate = new Date(data.okDate); + if(typeof(data.dismissDate) == "string") + data.dismissDate = new Date(data.dismissDate); + if(typeof(data.stepsDate) == "string") + data.pauseDate = new Date(data.pauseDate); + + return data; }; exports.mustAlert = function(activityreminder_data, activityreminder_settings) { var now = new Date(); if ((now - activityreminder_data.stepsDate) / 60000 > activityreminder_settings.maxInnactivityMin) { // inactivity detected - if ((now - activityreminder_settings.okDate) / 60000 > 3 && // last alert was more than 3 min ago + if ((now - activityreminder_settings.okDate) / 60000 > 3 && // last alert anwsered with ok was more than 3 min ago (now - activityreminder_settings.dismissDate) / 60000 > activityreminder_settings.dismissDelayMin && // last alert was more than dismissDelayMin ago (now - activityreminder_settings.pauseDate) / 60000 > activityreminder_settings.pauseDelayMin) { // last alert was more than pauseDelayMin ago return true; From 740b81e07667cc375d9d4dca91d0c6fdf1f914b9 Mon Sep 17 00:00:00 2001 From: Stiralbios Date: Thu, 12 May 2022 11:34:42 +0200 Subject: [PATCH 7/9] Fix mustAlert, and, hopefully use let and const the JS way --- apps/activityreminder/app.js | 4 ++-- apps/activityreminder/boot.js | 10 +++++----- apps/activityreminder/lib.js | 6 +++--- apps/activityreminder/settings.js | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/apps/activityreminder/app.js b/apps/activityreminder/app.js index 7338984dc..f3d72976e 100644 --- a/apps/activityreminder/app.js +++ b/apps/activityreminder/app.js @@ -37,6 +37,6 @@ const storage = require("Storage"); g.clear(); Bangle.loadWidgets(); Bangle.drawWidgets(); -activityreminder_settings = activityreminder.loadSettings(); -activityreminder_data = activityreminder.loadData(); +const activityreminder_settings = activityreminder.loadSettings(); +const activityreminder_data = activityreminder.loadData(); run(); diff --git a/apps/activityreminder/boot.js b/apps/activityreminder/boot.js index bc07ebc28..12e91bc12 100644 --- a/apps/activityreminder/boot.js +++ b/apps/activityreminder/boot.js @@ -1,8 +1,8 @@ function run() { if (isNotWorn()) return; - var now = new Date(); - var h = now.getHours(); - var health = Bangle.getHealthStatus("day"); + let now = new Date(); + let h = now.getHours(); + let health = Bangle.getHealthStatus("day"); if (h >= activityreminder_settings.startHour && h < activityreminder_settings.endHour) { if (health.steps - activityreminder_data.stepsOnDate >= activityreminder_settings.minSteps // more steps made than needed @@ -25,9 +25,9 @@ function isNotWorn() { } const activityreminder = require("activityreminder"); -activityreminder_settings = activityreminder.loadSettings(); +const activityreminder_settings = activityreminder.loadSettings(); if (activityreminder_settings.enabled) { - activityreminder_data = activityreminder.loadData(); + const activityreminder_data = activityreminder.loadData(); if(activityreminder_data.firstLoad){ activityreminder_data.firstLoad =false; activityreminder.saveData(activityreminder_data); diff --git a/apps/activityreminder/lib.js b/apps/activityreminder/lib.js index 141579cae..677e4cc0b 100644 --- a/apps/activityreminder/lib.js +++ b/apps/activityreminder/lib.js @@ -21,8 +21,8 @@ exports.saveData = function (data) { }; exports.loadData = function () { - var health = Bangle.getHealthStatus("day"); - var data = Object.assign({ + let health = Bangle.getHealthStatus("day"); + const data = Object.assign({ firstLoad: true, stepsDate: new Date(), stepsOnDate: health.steps, @@ -45,7 +45,7 @@ exports.loadData = function () { }; exports.mustAlert = function(activityreminder_data, activityreminder_settings) { - var now = new Date(); + let now = new Date(); if ((now - activityreminder_data.stepsDate) / 60000 > activityreminder_settings.maxInnactivityMin) { // inactivity detected if ((now - activityreminder_settings.okDate) / 60000 > 3 && // last alert anwsered with ok was more than 3 min ago (now - activityreminder_settings.dismissDate) / 60000 > activityreminder_settings.dismissDelayMin && // last alert was more than dismissDelayMin ago diff --git a/apps/activityreminder/settings.js b/apps/activityreminder/settings.js index 134279f41..9dff61f48 100644 --- a/apps/activityreminder/settings.js +++ b/apps/activityreminder/settings.js @@ -1,7 +1,7 @@ (function (back) { // Load settings const activityreminder = require("activityreminder"); - var settings = activityreminder.loadSettings(); + const settings = activityreminder.loadSettings(); // Show the menu E.showMenu({ From f46159ef8e80db516938017255eff71ee308b17e Mon Sep 17 00:00:00 2001 From: Stiralbios Date: Thu, 12 May 2022 12:21:21 +0200 Subject: [PATCH 8/9] [ActivityReminder] Actually commiting the fix to mustAlert --- apps/activityreminder/boot.js | 11 ++++++++++- apps/activityreminder/lib.js | 6 +++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/apps/activityreminder/boot.js b/apps/activityreminder/boot.js index 12e91bc12..7c094f521 100644 --- a/apps/activityreminder/boot.js +++ b/apps/activityreminder/boot.js @@ -10,6 +10,10 @@ function run() { activityreminder_data.stepsOnDate = health.steps; activityreminder_data.stepsDate = now; activityreminder.saveData(activityreminder_data); + /* todo in a futur release + add settimer to trigger like 10 secs after the stepsDate + minSteps + cancel all other timers of this app + */ } if(activityreminder.mustAlert(activityreminder_data, activityreminder_settings)){ @@ -20,7 +24,7 @@ function run() { } function isNotWorn() { - // todo check temperature and mouvement in a futur release + // todo in a futur release check temperature and mouvement in a futur release return Bangle.isCharging(); } @@ -33,4 +37,9 @@ if (activityreminder_settings.enabled) { activityreminder.saveData(activityreminder_data); } setInterval(run, 60000); + /* todo in a futur release + increase setInterval time to something that is still sensible (5 mins ?) + add settimer to trigger like 10 secs after the stepsDate + minSteps + cancel all other timers of this app + */ } diff --git a/apps/activityreminder/lib.js b/apps/activityreminder/lib.js index 677e4cc0b..7cc01c938 100644 --- a/apps/activityreminder/lib.js +++ b/apps/activityreminder/lib.js @@ -47,9 +47,9 @@ exports.loadData = function () { exports.mustAlert = function(activityreminder_data, activityreminder_settings) { let now = new Date(); if ((now - activityreminder_data.stepsDate) / 60000 > activityreminder_settings.maxInnactivityMin) { // inactivity detected - if ((now - activityreminder_settings.okDate) / 60000 > 3 && // last alert anwsered with ok was more than 3 min ago - (now - activityreminder_settings.dismissDate) / 60000 > activityreminder_settings.dismissDelayMin && // last alert was more than dismissDelayMin ago - (now - activityreminder_settings.pauseDate) / 60000 > activityreminder_settings.pauseDelayMin) { // last alert was more than pauseDelayMin ago + if ((now - activityreminder_data.okDate) / 60000 > 3 && // last alert anwsered with ok was more than 3 min ago + (now - activityreminder_data.dismissDate) / 60000 > activityreminder_settings.dismissDelayMin && // last alert was more than dismissDelayMin ago + (now - activityreminder_data.pauseDate) / 60000 > activityreminder_settings.pauseDelayMin) { // last alert was more than pauseDelayMin ago return true; } } From 255abe9c13b137295e139cab344c521730502ce7 Mon Sep 17 00:00:00 2001 From: Stiralbios Date: Thu, 12 May 2022 14:18:33 +0200 Subject: [PATCH 9/9] [ActivityReminder] fix bug on pauseDate --- apps/activityreminder/lib.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/activityreminder/lib.js b/apps/activityreminder/lib.js index 7cc01c938..5b7959827 100644 --- a/apps/activityreminder/lib.js +++ b/apps/activityreminder/lib.js @@ -38,7 +38,7 @@ exports.loadData = function () { data.okDate = new Date(data.okDate); if(typeof(data.dismissDate) == "string") data.dismissDate = new Date(data.dismissDate); - if(typeof(data.stepsDate) == "string") + if(typeof(data.pauseDate) == "string") data.pauseDate = new Date(data.pauseDate); return data;