Better rounding of time in AllPlot

With realtime data there will often be samples with
timestamps like 940.002 and 940.998. This cuases an
issue on the ride plot, where it believes there is
no sample for 941 and therefore plots a zero value.

This patch rounds the timestamps to the nearest 100th
of a second, which is consistent with the mechanism
used in the ride editor.
This commit is contained in:
Mark Liversedge
2011-05-16 17:54:11 +01:00
committed by Gareth Coco
parent ca1c4def3a
commit 92897a966b

View File

@@ -701,7 +701,21 @@ AllPlot::setDataFromRide(RideItem *_rideItem)
arrayLength = 0;
foreach (const RideFilePoint *point, ride->dataPoints()) {
timeArray[arrayLength] = point->secs;
// we round the time to nearest 100th of a second
// before adding to the array, to avoid situation
// where 'high precision' time slice is an artefact
// of double precision or slight timing anomalies
// e.g. where realtime gives timestamps like
// 940.002 followed by 940.998 and were previouslt
// both rounded to 940s
//
// NOTE: this rounding mechanism is identical to that
// used by the Ride Editor.
double secs = floor(point->secs);
double msecs = round((point->secs - secs) * 100) * 10;
timeArray[arrayLength] = secs + msecs/1000;
if (!wattsArray.empty())
wattsArray[arrayLength] = max(0, point->watts);
if (!hrArray.empty())