From 780ae993fff11b78347cae2796e75fe7712910db Mon Sep 17 00:00:00 2001 From: Mark Liversedge Date: Sun, 31 Jul 2011 23:24:04 +0100 Subject: [PATCH] Better support for Negative, Inf, NaN and High Values Some ride file formats use -1 to indicate sensor not present or data loss (e.g. TPX) and on occasion a NaN or Infinite value will be presented. This patch handles this by converting negative data sample values to zero and handling out of bounds values when selecting zone ranges. This is not a substitute for better handling of poor ride data but it reduces the effect. Also fixes #311. --- src/HrZones.cpp | 5 ++++- src/RideFile.cpp | 11 +++++++++++ src/Zones.cpp | 5 ++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/HrZones.cpp b/src/HrZones.cpp index 1882eeab4..31d08d2c6 100644 --- a/src/HrZones.cpp +++ b/src/HrZones.cpp @@ -440,7 +440,10 @@ int HrZones::whichZone(int rnum, double value) const if ((value >= info.lo) && (value < info.hi)) return j; } - return -1; + + // if we got here either it is negative, nan, inf or way high + if (value < 0 || isnan(value)) return 0; + else return range.zones.size()-1; } void HrZones::zoneInfo(int rnum, int znum, diff --git a/src/RideFile.cpp b/src/RideFile.cpp index 23d4d9f23..c3911849d 100644 --- a/src/RideFile.cpp +++ b/src/RideFile.cpp @@ -341,6 +341,17 @@ void RideFile::appendPoint(double secs, double cad, double hr, double km, double kph, double nm, double watts, double alt, double lon, double lat, double headwind, int interval) { + // negative values are not good, make them zero + // although alt, lat, lon, headwind can be negative of course! + if (secs<0) secs=0; + if (cad<0) cad=0; + if (hr<0) hr=0; + if (km<0) km=0; + if (kph<0) kph=0; + if (nm<0) nm=0; + if (watts<0) watts=0; + if (interval<0) interval=0; + dataPoints_.append(new RideFilePoint(secs, cad, hr, km, kph, nm, watts, alt, lon, lat, headwind, interval)); dataPresent.secs |= (secs != 0); diff --git a/src/Zones.cpp b/src/Zones.cpp index 4147a0f07..9239478b2 100644 --- a/src/Zones.cpp +++ b/src/Zones.cpp @@ -437,7 +437,10 @@ int Zones::whichZone(int rnum, double value) const if ((value >= info.lo) && (value < info.hi)) return j; } - return -1; + + // if we got here either it is negative, nan, inf or way high + if (value < 0 || isnan(value)) return 0; + else return range.zones.size()-1; } void Zones::zoneInfo(int rnum, int znum,