From 528d880a9006ddffdd0d4be24431550da53e69a1 Mon Sep 17 00:00:00 2001 From: Jon Beverley Date: Wed, 30 Jul 2014 16:33:57 +0100 Subject: [PATCH] Derive Slope Data - If Alt data present then calculate slope - Smooth the slope data after calculation --- src/RideFile.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/RideFile.cpp b/src/RideFile.cpp index 028d8a85e..adb5782e9 100644 --- a/src/RideFile.cpp +++ b/src/RideFile.cpp @@ -1363,6 +1363,21 @@ RideFile::recalculateDerivedSeries() p->antiss = anTISS; } + // Slope + // If there is no slope data then it can be derived + // from distanct and altitude + if (lastP) { + if (!dataPresent.slope && dataPresent.alt && dataPresent.km) { + double deltaDistance = (p->km - lastP->km) * 1000; + double deltaAltitude = p->alt - lastP->alt; + if (deltaDistance>0) { + p->slope = (deltaAltitude / deltaDistance) * 100; + } else { + p->slope = 0; + } + } + } + // last point lastP = p; } @@ -1377,6 +1392,24 @@ RideFile::recalculateDerivedSeries() avgPoint->apower = APcount ? (APtotal / APcount) : 0; totalPoint->apower = APtotal; + // Smooth the slope if it has been derived + if (!dataPresent.slope && dataPresent.alt && dataPresent.km) { + // initialise rolling average + double rtot = 0; + for (int i=10; i>0 && dataPoints_.length()-i >=0; i--) { + rtot += dataPoints_[dataPoints_.length()-i]->slope; + } + + // now run backwards setting the rolling average + for (int i=dataPoints_.length()-1; i>=10; i--) { + double here = dataPoints_[i]->slope; + dataPoints_[i]->slope = rtot / 10; + rtot -= here; + rtot += dataPoints_[i-10]->slope; + } + setDataPresent(slope, true); + } + // and we're done dstale=false; }