Add HrPw Metric

.. as a ratio of Average Power to Average Heartrate
   hrpw = ap / ahr
This commit is contained in:
Mark Liversedge
2014-09-07 22:15:12 +01:00
parent a0d6d6d865
commit 3578c9caca
2 changed files with 50 additions and 1 deletions

View File

@@ -744,6 +744,54 @@ struct AvgHeartRate : public RideMetric {
static bool avgHeartRateAdded =
RideMetricFactory::instance().addMetric(AvgHeartRate());
///////////////////////////////////////////////////////////////////////////////
class HrPw : public RideMetric {
Q_DECLARE_TR_FUNCTIONS(HrPw)
public:
HrPw()
{
setSymbol("hrpw");
setInternalName("HrPw Ratio");
}
void initialize() {
setName(tr("HrPw Ratio"));
setImperialUnits("");
setMetricUnits("");
setPrecision(3);
setType(RideMetric::Peak);
}
void compute(const RideFile *, const Zones *, int,
const HrZones *, int,
const QHash<QString,RideMetric*> &deps,
const Context *) {
AvgHeartRate *hr = dynamic_cast<AvgHeartRate*>(deps.value("average_hr"));
AvgPower *pw = dynamic_cast<AvgPower*>(deps.value("average_power"));
if (hr->value(true) > 100 && pw->value(true) > 100) { // ignore silly rides with low values
setValue(pw->value(true) / hr->value(true));
} else {
setValue(0);
}
}
RideMetric *clone() const { return new HrPw(*this); }
};
static bool addHrPw()
{
QVector<QString> deps;
deps.append("average_power");
deps.append("average_hr");
RideMetricFactory::instance().addMetric(HrPw(), &deps);
return true;
}
static bool hrpwAdded = addHrPw();
///////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
struct AvgCadence : public RideMetric {

View File

@@ -102,8 +102,9 @@
// 81 16 Aug 2014 Joern Rischmueller Added 'Elevation Loss'
// 82 23 Aug 2014 Mark Liversedge Added W'bal Matches
// 83 05 Sep 2014 Joern Rischmueler Added 'Time Carrying' and 'Elevation Gain Carrying'
// 84 08 Sep 2014 Mark Liversedge Added HrPw Ratio
int DBSchemaVersion = 83;
int DBSchemaVersion = 84;
DBAccess::DBAccess(Context* context) : context(context), db(NULL)
{