From 75ffe17e562d6d68273a340540efc57347b22314 Mon Sep 17 00:00:00 2001 From: Paul Colby Date: Fri, 17 Nov 2017 20:43:25 +1100 Subject: [PATCH] Don't force 0 left power balance on 0 power #81 Technically, a zero total power results in a divide-by-zero, so there is not valid correct result. We were defaulting, in this case, to zero left-balance, but this doesn't really make any more sense than any other value. Now, we default to 50% left power if both left and right are equal (ie left os 50% of 0, and right is 50% of 0), which makes a lot more sense visually (eg when rendered in an application). We now also handle special case where left and right might be equally opposite in sign (eg -10 and +10), which still results in a zero total power. So here, we use a left-balance of 0 or 100%, if the left is the lesser (negative) or greater (positive) of the two respectively. --- src/polar/v2/trainingsession.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/polar/v2/trainingsession.cpp b/src/polar/v2/trainingsession.cpp index d42bc3c5..c569e18b 100644 --- a/src/polar/v2/trainingsession.cpp +++ b/src/polar/v2/trainingsession.cpp @@ -2185,8 +2185,9 @@ QStringList TrainingSession::toHRM(const bool rrDataOnly) const // In case we only have right power, not left. const int powerLeft = havePowerLeft ? currentPowerLeft : currentPower - currentPowerRight; // Convert the left and right powers into a left-right balance percentage. - const int leftBalance = (currentPower == 0) ? 0 : - qRound(100.0 * (float)powerLeft / (float)currentPower); + const int leftBalance = (currentPower == 0) + ? (currentPowerLeft == currentPowerRight) ? 50 : (currentPowerLeft < currentPowerRight) ? 0 : 100 + : qRound(100.0 * (float)powerLeft / (float)currentPower); if (leftBalance > 100) { qWarning() << "leftBalance of " << leftBalance << "% is greater than 100%"; }