From 92897a966b75be0ff1bb892f0192dbdc2b9eebaf Mon Sep 17 00:00:00 2001 From: Mark Liversedge Date: Mon, 16 May 2011 17:54:11 +0100 Subject: [PATCH] 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. --- src/AllPlot.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/AllPlot.cpp b/src/AllPlot.cpp index b9af003b1..30430fce2 100644 --- a/src/AllPlot.cpp +++ b/src/AllPlot.cpp @@ -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())