From f57ac7d2b1312ce2a2ff1b7f18ea25d19c2e01f1 Mon Sep 17 00:00:00 2001 From: Mark Liversedge Date: Wed, 27 Apr 2011 20:48:39 +0100 Subject: [PATCH] Fix CP calculation for files with sub-recIntSecs samples Peak 1s - 5s critical heartrate was way off the charts and did not represent the data within the ride file. Almost certainly caused by the WKO+ file importer, or possibly by the WKO+ files themselves. It is possible to have ride files with samples that are shorter than recIntSecs, e.g. where the recording sample rate is 1s you might see: Time HR 01:21:32.0 157 01:21:32.7 157 01:21:33.0 157 In this case there are two samples between 1:21:32 and 1:21:33 rather than the expected one sample. The code to compute averages used the duration and recIntSecs to determine the average. This patch now maintains a count instead. Fixes #319 --- src/RideFileCache.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/RideFileCache.cpp b/src/RideFileCache.cpp index 8b418a01b..6fc9ed5c9 100644 --- a/src/RideFileCache.cpp +++ b/src/RideFileCache.cpp @@ -300,6 +300,7 @@ MeanMaxComputer::run() cpintpoint *p = &data.points[i]; double sum = 0.0; + int count = 0; double prev_secs = p->secs; // from current point to end loop over remaining points @@ -308,9 +309,11 @@ MeanMaxComputer::run() cpintpoint *q = &data.points[j]; - sum += data.rec_int_ms / 1000.0 * q->value; + sum += q->value; + count++; + double dur_secs = q->secs - p->secs; - double avg = sum / dur_secs; + double avg = sum / count; int dur_secs_top = (int) floor(dur_secs); int dur_secs_bot = qMax((int) floor(dur_secs - data.rec_int_ms / 1000.0), 0);