diff --git a/src/RideMetric.cpp b/src/RideMetric.cpp index ff6ca1aa4..ed9ef879e 100644 --- a/src/RideMetric.cpp +++ b/src/RideMetric.cpp @@ -111,8 +111,9 @@ // 105 09 May 2015 Ale Martinez Added PeakPace and PeakPaceSwim metrics // 106 09 May 2015 Mark Liversedge Added MMP Percentage - %age of power for duration vs CP model // 107 29 May 2015 Mark Liversedge Added AP as percent of maximum +// 108 29 Jun 2015 Mark Liversedge Added W' Power - average power contribution from W' -int DBSchemaVersion = 107; +int DBSchemaVersion = 108; RideMetricFactory *RideMetricFactory::_instance; QVector RideMetricFactory::noDeps; diff --git a/src/WPrime.cpp b/src/WPrime.cpp index 574c8bd16..a79832a20 100644 --- a/src/WPrime.cpp +++ b/src/WPrime.cpp @@ -721,6 +721,47 @@ class WPrimeExp : public RideMetric { RideMetric *clone() const { return new WPrimeExp(*this); } }; +class WPrimeWatts : public RideMetric { + Q_DECLARE_TR_FUNCTIONS(WPrimeWatts); + + public: + + WPrimeWatts() + { + setSymbol("skiba_wprime_watts"); + setInternalName("W' Watts"); + } + void initialize() { + setName(tr("W' Power")); + setType(RideMetric::Total); + setMetricUnits(tr("watts")); + setImperialUnits(tr("watts")); + setPrecision(0); + } + void compute(const RideFile *r, const Zones *zones, int zonerange, + const HrZones *, int, + const QHash &, + const Context *) { + + int cp = r->getTag("CP","0").toInt(); + if (!cp && zones && zonerange >=0) cp = zones->getCP(zonerange); + + double total = 0; + double secs = 0; + foreach(const RideFilePoint *point, r->dataPoints()) { + if (cp && point->watts > cp) { + total += r->recIntSecs() * (point->watts - cp); + secs += r->recIntSecs(); + } + } + setValue(total/secs); + setCount(secs); + } + + bool canAggregate() { return false; } + RideMetric *clone() const { return new WPrimeWatts(*this); } +}; + class CPExp : public RideMetric { Q_DECLARE_TR_FUNCTIONS(CPExp); @@ -773,6 +814,7 @@ static bool addMetrics() { RideMetricFactory::instance().addMetric(MaxMatch()); RideMetricFactory::instance().addMetric(WPrimeTau()); RideMetricFactory::instance().addMetric(WPrimeExp()); + RideMetricFactory::instance().addMetric(WPrimeWatts()); RideMetricFactory::instance().addMetric(CPExp()); return true; }