From 625f065834542797c81a962305bc51035a5aae95 Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Thu, 10 Oct 2024 20:31:17 +0100 Subject: [PATCH] pace: fix distance totalling --- apps/pace/app.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/apps/pace/app.ts b/apps/pace/app.ts index aa542c36b..79244865a 100644 --- a/apps/pace/app.ts +++ b/apps/pace/app.ts @@ -172,11 +172,15 @@ const onButton = () => { exs.start(); // aka reset exs.stats.dist.on("notify", (dist) => { - const prevDist = splits[splits.length - 1]?.dist ?? 0; + const prev = { time: 0, dist: 0 }; + for(const s of splits){ + prev.time += s.time; + prev.dist += s.dist; + } + const totalDist = dist.getValue(); - let thisSplit = totalDist - prevDist; - const prevTime = splits.reduce((t, s) => t + s.time, 0); - let thisTime = exs.state.duration - prevTime; + let thisSplit = totalDist - prev.dist; + let thisTime = exs.state.duration - prev.time; while(thisSplit > 1000) { splits.push({ dist: thisSplit as Dist, time: thisTime as Time });