From c3bf5210679e5eff90587a43586c9ca0e5789345 Mon Sep 17 00:00:00 2001 From: Marco H Date: Tue, 3 Jan 2023 08:15:37 +0100 Subject: [PATCH] Show step goal in daily step chart Documentation fixes --- apps/health/ChangeLog | 1 + apps/health/README.md | 3 ++- apps/health/app.js | 19 ++++++++++++++++++- apps/health/lib.js | 2 +- apps/health/metadata.json | 2 +- 5 files changed, 23 insertions(+), 4 deletions(-) diff --git a/apps/health/ChangeLog b/apps/health/ChangeLog index fc8f2c950..87a58a57b 100644 --- a/apps/health/ChangeLog +++ b/apps/health/ChangeLog @@ -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 diff --git a/apps/health/README.md b/apps/health/README.md index 3cc234a3f..01d506f7e 100644 --- a/apps/health/README.md +++ b/apps/health/README.md @@ -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 diff --git a/apps/health/app.js b/apps/health/app.js index 844dd7241..bd708207b 100644 --- a/apps/health/app.js +++ b/apps/health/app.js @@ -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(); diff --git a/apps/health/lib.js b/apps/health/lib.js index 2e3e0c002..3a52ad59f 100644 --- a/apps/health/lib.js +++ b/apps/health/lib.js @@ -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); diff --git a/apps/health/metadata.json b/apps/health/metadata.json index 12f6b617f..ecaf9b563 100644 --- a/apps/health/metadata.json +++ b/apps/health/metadata.json @@ -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",