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.
This commit is contained in:
Mark Liversedge
2011-07-31 23:24:04 +01:00
committed by Gareth Coco
parent 57c7260a19
commit 00959bed8c
3 changed files with 19 additions and 2 deletions

View File

@@ -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,

View File

@@ -287,6 +287,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);

View File

@@ -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,