Skip to content

Commit

Permalink
Don't force 0 left power balance on 0 power #81
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pcolby committed Nov 17, 2017
1 parent fbea6d1 commit 75ffe17
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/polar/v2/trainingsession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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%";
}
Expand Down

0 comments on commit 75ffe17

Please sign in to comment.