-
Notifications
You must be signed in to change notification settings - Fork 447
/
LeftRightBalance.cpp
87 lines (74 loc) · 2.89 KB
/
LeftRightBalance.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* Copyright (c) 2012 Damien Grauser (Damien.Grauser@pev-geneve.ch)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "RideMetric.h"
#include "Zones.h"
#include "RideItem.h"
#include "Context.h"
#include "Athlete.h"
#include "Specification.h"
#include <cmath>
#include <QApplication>
class LeftRightBalance : public RideMetric {
Q_DECLARE_TR_FUNCTIONS(LeftRightBalance)
double count, total;
public:
LeftRightBalance()
{
setSymbol("left_right_balance");
setInternalName("Left/Right Balance");
}
void initialize() {
setName(tr("Left/Right Balance"));
setMetricUnits(tr("%"));
setImperialUnits(tr("%"));
setType(RideMetric::Average);
setPrecision(1);
setDescription(tr("Left/Right Balance shows the proportion of power coming from each pedal for rides and the proportion of Ground Contact Time from each leg for runs."));
}
void compute(RideItem *item, Specification spec, const QHash<QString,RideMetric*> &) {
// no ride or no samples
if (spec.isEmpty(item->ride())) {
setValue(RideFile::NIL);
setCount(0);
return;
}
total = count = 0;
RideFileIterator it(item->ride(), spec);
while (it.hasNext()) {
struct RideFilePoint *point = it.next();
if (((point->watts > 0.0f && point->cad) || (point->rcontact && point->rcad)) && point->lrbalance != RideFile::NA) {
total += point->lrbalance;
++count;
}
}
setValue(count > 0 ? total / count : 0);
setCount(count);
}
QString toString(bool useMetricUnits) const
{
double v1 = value(useMetricUnits);
double v2 = 100-v1;
return QString("%1-%2").arg(v1, 0, 'f', this->precision()).arg(v2, 0, 'f', this->precision());
}
bool isRelevantForRide(const RideItem *ride) const { return ride->present.contains("V"); }
MetricClass classification() const { return Undefined; }
MetricValidity validity() const { return Unknown; }
RideMetric *clone() const { return new LeftRightBalance(*this); }
};
static bool leftRightBalanceAdded =
RideMetricFactory::instance().addMetric(LeftRightBalance());