Skip to content

Commit

Permalink
Power Profile Peloton #1733
Browse files Browse the repository at this point in the history
  • Loading branch information
cagnulein committed Oct 27, 2023
1 parent 09ab5b1 commit 180a246
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
12 changes: 11 additions & 1 deletion src/homeform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6050,8 +6050,18 @@ void homeform::sendMail() {
QStringLiteral("Moving Time: ") + bluetoothManager->device()->movingTime().toString() + QStringLiteral("\n");
textMessage += QStringLiteral("Weight Loss (") + weightLossUnit + "): " + QString::number(WeightLoss, 'f', 2) +
QStringLiteral("\n");
textMessage += QStringLiteral("Estimated VO2Max: ") + QString::number(metric::calculateVO2Max(&Session), 'f', 1) +
textMessage += QStringLiteral("Estimated VO2Max: ") + QString::number(metric::calculateVO2Max(&Session), 'f', 0) +
QStringLiteral("\n");
double peak = metric::powerPeak(&Session, 5);
double weightKg = settings.value(QZSettings::weight, QZSettings::default_weight).toFloat();
textMessage += QStringLiteral("5 Seconds Power: ") + QString::number(peak, 'f', 0) +
QStringLiteral("W") + QString::number(peak/weightKg, 'f', 1) + QStringLiteral("W/Kg\n");
peak = metric::powerPeak(&Session, 60);
textMessage += QStringLiteral("1 Minute Power: ") + QString::number(peak, 'f', 0) +
QStringLiteral("W") + QString::number(peak/weightKg, 'f', 1) + QStringLiteral("W/Kg\n");
peak = metric::powerPeak(&Session, 5 * 60);
textMessage += QStringLiteral("5 Minutes Power: ") + QString::number(peak, 'f', 0) +
QStringLiteral("W") + QString::number(peak/weightKg, 'f', 1) + QStringLiteral("W/Kg\n");
if (bluetoothManager->device()->deviceType() == bluetoothdevice::BIKE) {
textMessage += QStringLiteral("Average Cadence: ") +
QString::number(((bike *)bluetoothManager->device())->currentCadence().average(), 'f', 0) +
Expand Down
16 changes: 10 additions & 6 deletions src/metric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,20 +282,18 @@ struct CompareBests {
}
};

// VO2 (L/min) = 0.0108 x power (W) + 0.007 x body mass (kg)
// power = 5 min peak power for a specific ride
double metric::calculateVO2Max(QList<SessionLine> *session) {
double metric::powerPeak(QList<SessionLine> *session, int seconds) {
QList<IntervalBest> bests;
QList<IntervalBest> _results;

uint windowSize = 5 * 60; // 5 mins
uint windowSize = seconds;
double total = 0.0;
QList<const SessionLine *> window;

if (session->count() == 0)
return -1;

// ride is shorter than the window size!
// ride is shorter than the window size!
if (windowSize > session->last().elapsedTime)
return -1;

Expand Down Expand Up @@ -325,7 +323,13 @@ double metric::calculateVO2Max(QList<SessionLine> *session) {

std::sort(bests.begin(), bests.end(), CompareBests());

double peak = bests.first().avg;
return bests.first().avg;
}

// VO2 (L/min) = 0.0108 x power (W) + 0.007 x body mass (kg)
// power = 5 min peak power for a specific ride
double metric::calculateVO2Max(QList<SessionLine> *session) {
double peak = powerPeak(session, 5*60);
QSettings settings;
return ((0.0108 * peak + 0.007 * settings.value(QZSettings::weight, QZSettings::default_weight).toFloat()) /
settings.value(QZSettings::weight, QZSettings::default_weight).toFloat()) *
Expand Down
2 changes: 2 additions & 0 deletions src/metric.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class metric {
static double calculateVO2Max(QList<SessionLine> *session);
static double calculateKCalfromHR(double HR_AVG, double elapsed);

static double powerPeak(QList<SessionLine> *session, int seconds);

private:
double m_value = 0;
double m_totValue = 0;
Expand Down

0 comments on commit 180a246

Please sign in to comment.