-
• #2
I guess one way is you could use
Bangle.getStepCount
and log the steps to a file every minute.It might be better to refactor something in the health app or some other place, I don't know...
Edit: fix link
-
• #3
I checked the health boot.js code but if I understand correctly it also only listens for the "health" event and then saves the data to the database. And if I understand this commit correctly, "health" gets fired in
libs/banglejs/jswrap_bangle.c
and honestly, I was hoping for an easier approach than editing and recompiling C files for such a small feature. -
• #4
As you noted we only store health data every 10 minutes to help with battery/storage usage.
Yes, you'd be better off just checking
Bangle.getStepCount
every minute in your app and seeing how much it changed.Your app could have its own 'boot code' file (
yourapp.boot.js
) which set a 60 second interval so it'll always run in the background. I guess realistically you only really need to write to storage when you're doing >100 steps in a minute, so a lot of the time it wouldn't actually be writing anything to storage -
• #5
Okay thanks but what I don't understand: Doesn't the code in yourapp.boot.js also need to save data to storage every minute? Because if I understand it correctly when I switch apps or activities any running app gets terminated and thus any saved variables (to cache the step count at the end of the last minute) get cleared (like widgets) and the boot code needs to run again?
-
• #6
There's an
E.on("kill", function() { ... })
event that can get called when the code gets unloaded, so you can save any data in that.But if you only save for every minute where you have activity, that may only be 150 writes/week which is file. The only gotcha is preserving step count for the current minute when swapping apps, which you would have to save state for
-
• #7
Edit: Gordon beat me to it.
To keep information between resetting/loading of apps you can act on the E.kill event.
I guess one could also make the assumption that at times with lots of app switching you probably are not doing a lot of moving around. So it probably wouldn't impact the statistics too much doing without retaining info across resets/loads.
-
• #8
Thanks everyone!
I guess one could also make the assumption that at times with lots of app switching you probably are not doing a lot of moving around. So it probably wouldn't impact the statistics too much doing without retaining info across resets/loads.
Yes, that's probably true, so to save CPU and battery usage, I'll probably ignore App switches and not save data to storage, and assume that no significant activity was done during that time.
The WHO recommends to "perform at least 150 minutes of moderate intensity aerobic physical activity throughout the week or do at least 75 minutes of vigorous intensity aerobic physical activity throughout the week".
I would like to implement this into an app that records a minute as "moderate intensity" if more than 100 steps were performed or records it as a "vigorous intensity" if more than 130 steps were performed.
So far, I simply used
to get all health records of the last week to filter out the records with an appropriate step count (see code snippet below). However, BangleJS only saves step counts per 10 minutes (probably to save storage). This is understandable but gives more inaccurate results here:
How can I get the exact step count of the last minute only, to avoid averaging/guessing the step count like above?