From 180a2469025eea29ee107dde2ef6f6c7f88d8c94 Mon Sep 17 00:00:00 2001 From: Roberto Viola Date: Fri, 27 Oct 2023 10:53:51 +0200 Subject: [PATCH] Power Profile Peloton #1733 --- src/homeform.cpp | 12 +++++++++++- src/metric.cpp | 16 ++++++++++------ src/metric.h | 2 ++ 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/homeform.cpp b/src/homeform.cpp index 3a4f55162..811b280a5 100644 --- a/src/homeform.cpp +++ b/src/homeform.cpp @@ -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) + diff --git a/src/metric.cpp b/src/metric.cpp index 4cfef5508..31c174567 100644 --- a/src/metric.cpp +++ b/src/metric.cpp @@ -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 *session) { +double metric::powerPeak(QList *session, int seconds) { QList bests; QList _results; - uint windowSize = 5 * 60; // 5 mins + uint windowSize = seconds; double total = 0.0; QList 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; @@ -325,7 +323,13 @@ double metric::calculateVO2Max(QList *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 *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()) * diff --git a/src/metric.h b/src/metric.h index a8a2c6f9f..c13be8668 100644 --- a/src/metric.h +++ b/src/metric.h @@ -53,6 +53,8 @@ class metric { static double calculateVO2Max(QList *session); static double calculateKCalfromHR(double HR_AVG, double elapsed); + static double powerPeak(QList *session, int seconds); + private: double m_value = 0; double m_totValue = 0;