diff --git a/src/DBAccess.cpp b/src/DBAccess.cpp index 6a52a7c70..b2cd7ef58 100644 --- a/src/DBAccess.cpp +++ b/src/DBAccess.cpp @@ -71,8 +71,9 @@ // 50 29 Oct 2013 Mark Liversedge Added percentage time in heartrate zone // 51 05 Nov 2013 Mark Liversedge Added average aPower // 52 05 Nov 2013 Mark Liversedge Added EOA - Effect of Altitude +// 53 18 Dec 2013 Mark Liversedge Added Fatigue Index (for power) -int DBSchemaVersion = 52; +int DBSchemaVersion = 53; DBAccess::DBAccess(Context* context) : context(context), db(NULL) { diff --git a/src/PeakPower.cpp b/src/PeakPower.cpp index 8ab2eb173..2e37ec376 100644 --- a/src/PeakPower.cpp +++ b/src/PeakPower.cpp @@ -22,6 +22,46 @@ #include #include +class FatigueIndex : public RideMetric { + Q_DECLARE_TR_FUNCTIONS(FatigueIndex) + double maxp; + double minp; + + public: + + FatigueIndex() : maxp(0.0), minp(10000) + { + setType(RideMetric::Average); + setSymbol("power_fatigue_index"); + setInternalName("Fatigue Index"); + setName(tr("Fatigue Index")); + setMetricUnits(tr("%")); + setPrecision(1); // e.g. 99.9% + setImperialUnits(tr("%")); + + } + void compute(const RideFile *ride, const Zones *, int, + const HrZones *, int, + const QHash &, + const Context *) { + + if (ride->dataPoints().isEmpty() || !ride->areDataPresent()->watts) { + // no data + setValue(0.0); + + } else { + foreach(const RideFilePoint *point, ride->dataPoints()) { + if (point->watts < minp && point->watts != 0) minp = point->watts; + if (point->watts > maxp && point->watts != 0) maxp = point->watts; + } + + if (minp > maxp) setValue(0.00); // minp wasn't changed, all zeroes? + else setValue(100 * ((maxp-minp)/maxp)); // as a percentage + } + } + RideMetric *clone() const { return new FatigueIndex(*this); } +}; + class PeakPower : public RideMetric { Q_DECLARE_TR_FUNCTIONS(PeakPower) double watts; @@ -474,6 +514,8 @@ class PeakPowerHr60m : public PeakPowerHr { }; static bool addAllPeaks() { + RideMetricFactory::instance().addMetric(FatigueIndex()); // added here instead of new function + RideMetricFactory::instance().addMetric(PeakPower1s()); RideMetricFactory::instance().addMetric(PeakPower5s()); RideMetricFactory::instance().addMetric(PeakPower10s());