Metrics: Add Calories based on average HR

fixes #1249
This commit is contained in:
Damien
2015-01-14 22:29:53 +01:00
parent 1620b9d0ea
commit e5bcc5edee
2 changed files with 68 additions and 1 deletions

View File

@@ -2553,3 +2553,69 @@ static bool addLeftRight()
}
static bool leftRightAdded = addLeftRight();
//////////////////////////////////////////////////////////////////////////////
struct TotalCalories : public RideMetric {
Q_DECLARE_TR_FUNCTIONS(TotalCalories)
private:
double average_hr, athlete_weight, duration, athlete_age;
public:
TotalCalories()
{
setSymbol("total_kcalories");
setInternalName("Calories");
}
void initialize() {
setName(tr("Calories (HR)"));
setMetricUnits(tr("kcal"));
setImperialUnits(tr("kcal"));
setType(RideMetric::Total);
}
void compute(const RideFile *ride, const Zones *, int,
const HrZones *, int,
const QHash<QString,RideMetric*> &deps,
const Context *context) {
average_hr = deps.value("average_hr")->value(true);
athlete_weight = deps.value("athlete_weight")->value(true);
duration = deps.value("time_riding")->value(true); // time_riding or workout_time ?
athlete_age = ride->startTime().date().year() - appsettings->cvalue(context->athlete->cyclist, GC_DOB).toDate().year();
bool male = appsettings->cvalue(context->athlete->cyclist, GC_SEX).toInt() == 0;
double kcalories = 0.0;
if (duration>0 && average_hr>0 && athlete_weight>0 && athlete_age>0) {
//Male: ((-55.0969 + (0.6309 x HR) + (0.1988 x W) + (0.2017 x A))/4.184) x 60 x T
//Female: ((-20.4022 + (0.4472 x HR) - (0.1263 x W) + (0.074 x A))/4.184) x 60 x T
if (male)
kcalories = ((-55.0969 + (0.6309 * average_hr) + (0.1988 * athlete_weight) + (0.2017 * athlete_age))/4.184) * duration/60;
else
kcalories = ((-20.4022 + (0.4472 * average_hr) + (0.1263 * athlete_weight) + (0.074 * athlete_age))/4.184) * duration/60;
}
setValue(kcalories);
}
bool isRelevantForRide(const RideItem *ride) const { return ride->present.contains("H"); }
RideMetric *clone() const { return new TotalCalories(*this); }
};
static bool addTotalCalories() {
QVector<QString> deps;
deps.append("average_hr");
deps.append("time_riding");
deps.append("athlete_weight");
RideMetricFactory::instance().addMetric(TotalCalories(), &deps);
return true;
}
static bool totalCaloriesAdded = addTotalCalories();
///////////////////////////////////////////////////////////////////////////////

View File

@@ -102,8 +102,9 @@
// 96 06 Jan 2015 Damien Grauser Garmin Cycling Dynamics
// 97 07 Jan 2015 Mark Liversedge Added isSwim first class variable
// 98 10 Jan 2015 Ale Martinez Added Triscore and SwimScore metrics
// 99 14 Jan 2015 Damien Grauser Added TotalCalories
int DBSchemaVersion = 98;
int DBSchemaVersion = 99;
RideMetricFactory *RideMetricFactory::_instance;
QVector<QString> RideMetricFactory::noDeps;