From 25b16a17385d8570eed875964bc866bb636def85 Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Sun, 22 Sep 2024 22:13:03 +0100 Subject: [PATCH] pace: use duration instead of time stat time is total (or elapsed) time, duration is active time --- apps/pace/app.js | 10 ++++++---- apps/pace/app.ts | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/apps/pace/app.js b/apps/pace/app.js index c12ef3e6a..40d215869 100644 --- a/apps/pace/app.js +++ b/apps/pace/app.js @@ -1,6 +1,7 @@ { var Layout_1 = require("Layout"); - var exs_1 = require("exstats").getStats(["time", "dist", "pacec"], { + var time_utils_1 = require("time_utils"); + var exs_1 = require("exstats").getStats(["dist", "pacec"], { notify: { dist: { increment: 1000, @@ -69,7 +70,8 @@ else { pace = "No GPS"; } - layout_1["time"].label = exs_1.stats.time.getString(); + var tm = time_utils_1.decodeTime(exs_1.state.duration); + layout_1["time"].label = tm.d ? time_utils_1.formatDuration(tm) : time_utils_1.formatTime(tm); layout_1["pace"].label = pace; layout_1.render(); if (now - lastUnlazy_1 > 30000) @@ -99,7 +101,7 @@ g.setColor("#fff").drawString("".concat(i + 1 + splitOffset_1, " @ ").concat(splitPace.toFixed(2)), 0, y); } var pace = exs_1.stats.pacec.getString(); - var splitTime = exs_1.stats.time.getValue() - totalTime; + var splitTime = exs_1.state.duration - totalTime; g.setColor("#fff").drawString("".concat(i + 1 + splitOffset_1, " @ ").concat(pace, " (").concat((splitTime / 1000).toFixed(2), ")"), 0, Bangle.appRect.y + i * (barSize + barSpacing) + barSpacing / 2); }; var pauseRun_1 = function () { @@ -125,7 +127,7 @@ var totalDist = dist.getValue(); var thisSplit = totalDist - prev; var prevTime = splits_1.reduce(function (a, b) { return a + b; }, 0); - var time = exs_1.stats.time.getValue() - prevTime; + var time = exs_1.state.duration - prevTime; while (thisSplit > 0) { splits_1.push(time); time = 0; diff --git a/apps/pace/app.ts b/apps/pace/app.ts index a9321501f..0351c4b3e 100644 --- a/apps/pace/app.ts +++ b/apps/pace/app.ts @@ -1,7 +1,8 @@ { const Layout = require("Layout"); +const time_utils = require("time_utils"); const exs = require("exstats").getStats( - ["time", "dist", "pacec"], + ["dist", "pacec"], { notify: { dist: { @@ -81,7 +82,8 @@ const draw = () => { pace = "No GPS"; } - layout["time"]!.label = exs.stats.time.getString(); + const tm = time_utils.decodeTime(exs.state.duration); + layout["time"]!.label = tm.d ? time_utils.formatDuration(tm) : time_utils.formatTime(tm); // formatTime throws if tm.d > 0 layout["pace"]!.label = pace; layout.render(); @@ -120,7 +122,7 @@ const drawSplits = () => { } const pace = exs.stats.pacec.getString(); - const splitTime = exs.stats.time.getValue() - totalTime; + const splitTime = exs.state.duration - totalTime; g.setColor("#fff").drawString( `${i + 1 + splitOffset} @ ${pace} (${(splitTime / 1000).toFixed(2)})`, @@ -156,7 +158,7 @@ exs.stats.dist.on("notify", (dist) => { const totalDist = dist.getValue(); let thisSplit = totalDist - prev; const prevTime = splits.reduce((a, b) => a + b, 0); - let time = exs.stats.time.getValue() - prevTime; + let time = exs.state.duration - prevTime; while(thisSplit > 0) { splits.push(time);