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
This commit is contained in:
Mark Liversedge
2011-04-27 20:48:39 +01:00
parent 64d44cdd0f
commit f57ac7d2b1

View File

@@ -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);