1
0
Fork 0

Merge pull request #2441 from myxor/health_0.18

Health: Show step goal in daily step chart
master
Gordon Williams 2023-01-05 10:17:58 +00:00 committed by GitHub
commit 9ccb8f079d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 4 deletions

View File

@ -16,3 +16,4 @@
0.15: Fix charts (fix #1366)
0.16: Code tidyup, add back button in top left of health app graphs
0.17: Add automatic translation of bar chart labels
0.18: Show step goal in daily step chart

View File

@ -1,6 +1,6 @@
# Health Tracking
Logs health data to a file every 10 minutes, and provides an app to view it
Logs health data to a file in a defined interval, and provides an app to view it
**BETA - requires firmware 2v11 or later**
@ -22,6 +22,7 @@ Stores:
* **Heart Rt** - Whether to monitor heart rate or not
* **Off** - Don't turn HRM on, but record heart rate if the HRM was turned on by another app/widget
* **3 Min** - Turn HRM on every 3 minutes (for each heath entry) and turn it off after 1 minute, or when a good reading is found
* **10 Min** - Turn HRM on every 10 minutes (for each heath entry) and turn it off after 2 minutes, or when a good reading is found
* **Always** - Keep HRM on all the time (more accurate recording, but reduces battery life to ~36 hours)
* **Daily Step Goal** - Default 10000, daily step goal for pedometer apps to use

View File

@ -38,6 +38,7 @@ function menuHRM() {
function stepsPerHour() {
E.showMessage(/*LANG*/"Loading...");
current_selection = "stepsPerHour";
var data = new Uint16Array(24);
require("health").readDay(new Date(), h=>data[h.hr]+=h.steps);
setButton(menuStepCount);
@ -46,14 +47,17 @@ function stepsPerHour() {
function stepsPerDay() {
E.showMessage(/*LANG*/"Loading...");
current_selection = "stepsPerDay";
var data = new Uint16Array(31);
require("health").readDailySummaries(new Date(), h=>data[h.day]+=h.steps);
setButton(menuStepCount);
barChart(/*LANG*/"DAY", data);
drawHorizontalLine(settings.stepGoal);
}
function hrmPerHour() {
E.showMessage(/*LANG*/"Loading...");
current_selection = "hrmPerHour";
var data = new Uint16Array(24);
var cnt = new Uint8Array(23);
require("health").readDay(new Date(), h=>{
@ -67,6 +71,7 @@ function hrmPerHour() {
function hrmPerDay() {
E.showMessage(/*LANG*/"Loading...");
current_selection = "hrmPerDay";
var data = new Uint16Array(31);
var cnt = new Uint8Array(31);
require("health").readDailySummaries(new Date(), h=>{
@ -80,6 +85,7 @@ function hrmPerDay() {
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);
setButton(menuMovement);
@ -88,6 +94,7 @@ function movementPerHour() {
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);
setButton(menuMovement);
@ -97,12 +104,14 @@ function movementPerDay() {
// Bar Chart Code
const w = g.getWidth();
const h = g.getHeight();
const bar_bot = 140;
var data_len;
var chart_index;
var chart_max_datum;
var chart_label;
var chart_data;
var current_selection;
// find the max value in the array, using a loop due to array size
function max(arr) {
@ -131,7 +140,6 @@ function barChart(label, dt) {
}
function drawBarChart() {
const bar_bot = 140;
const bar_width = (w - 2) / 9; // we want 9 bars, bar 5 in the centre
var bar_top;
var bar;
@ -157,6 +165,11 @@ function drawBarChart() {
}
}
function drawHorizontalLine(value) {
const top = bar_bot - 100 * value / chart_max_datum;
g.setColor(g.theme.fg).drawLine(0, top ,g.getWidth(), top);
}
function setButton(fn) {
Bangle.setUI({mode:"custom",
back:fn,
@ -170,9 +183,13 @@ function setButton(fn) {
return fn();
}
drawBarChart();
if (current_selection == "stepsPerDay") {
drawHorizontalLine(settings.stepGoal);
}
}});
}
Bangle.loadWidgets();
Bangle.drawWidgets();
var settings = require("Storage").readJSON("health.json",1)||{};
menuMain();

View File

@ -60,7 +60,7 @@ exports.readDailySummaries = function(d, cb) {
}
}
// Read all records from the given month
// Read all records from the given day
exports.readDay = function(d, cb) {
var rec = getRecordIdx(d);
var fn = getRecordFN(d);

View File

@ -2,7 +2,7 @@
"id": "health",
"name": "Health Tracking",
"shortName": "Health",
"version": "0.17",
"version": "0.18",
"description": "Logs health data and provides an app to view it",
"icon": "app.png",
"tags": "tool,system,health",