rename RideMetric::name to RideMetric::symbol

The symbol of a ride metric is the string by which we refer to it in the
code, configuration files, and caches (like stress.cache).  It should not
be translated, and it should never be shown to the user.
This commit is contained in:
Sean Rhea
2009-12-20 14:52:40 -05:00
parent 9b4782ab98
commit d2b44ec508
6 changed files with 40 additions and 36 deletions

View File

@@ -42,7 +42,7 @@ class AerobicDecoupling : public RideMetric {
public:
AerobicDecoupling() : percent(0.0) {}
QString name() const { return "aerobic_decoupling"; }
QString symbol() const { return "aerobic_decoupling"; }
QString units(bool) const { return "%"; }
double value(bool) const { return percent; }
void compute(const RideFile *ride, const Zones *, int,

View File

@@ -25,7 +25,7 @@ class WorkoutTime : public RideMetric {
public:
WorkoutTime() : seconds(0.0) {}
QString name() const { return "workout_time"; }
QString symbol() const { return "workout_time"; }
QString units(bool) const { return "seconds"; }
double value(bool) const { return seconds; }
void compute(const RideFile *ride, const Zones *, int,
@@ -48,7 +48,7 @@ class TimeRiding : public PointwiseRideMetric {
public:
TimeRiding() : secsMovingOrPedaling(0.0) {}
QString name() const { return "time_riding"; }
QString symbol() const { return "time_riding"; }
QString units(bool) const { return "seconds"; }
double value(bool) const { return secsMovingOrPedaling; }
void perPoint(const RideFilePoint *point, double secsDelta,
@@ -74,7 +74,7 @@ class TotalDistance : public RideMetric {
public:
TotalDistance() : km(0.0) {}
QString name() const { return "total_distance"; }
QString symbol() const { return "total_distance"; }
QString units(bool metric) const { return metric ? "km" : "miles"; }
double value(bool metric) const {
return metric ? km : (km * MILES_PER_KM);
@@ -101,7 +101,7 @@ class ElevationGain : public PointwiseRideMetric {
public:
ElevationGain() : elegain(0.0), prevalt(0.0) {}
QString name() const { return "elevation_gain"; }
QString symbol() const { return "elevation_gain"; }
QString units(bool metric) const { return metric ? "meters" : "feet"; }
double value(bool metric) const {
return metric ? elegain : (elegain * FEET_PER_METER);
@@ -137,7 +137,7 @@ class TotalWork : public PointwiseRideMetric {
public:
TotalWork() : joules(0.0) {}
QString name() const { return "total_work"; }
QString symbol() const { return "total_work"; }
QString units(bool) const { return "kJ"; }
double value(bool) const { return joules / 1000.0; }
void perPoint(const RideFilePoint *point, double secsDelta,
@@ -147,7 +147,7 @@ class TotalWork : public PointwiseRideMetric {
}
bool canAggregate() const { return true; }
void aggregateWith(RideMetric *other) {
assert(name() == other->name());
assert(symbol() == other->symbol());
TotalWork *tw = dynamic_cast<TotalWork*>(other);
joules += tw->joules;
}
@@ -166,7 +166,7 @@ class AvgSpeed : public PointwiseRideMetric {
public:
AvgSpeed() : secsMoving(0.0), km(0.0) {}
QString name() const { return "average_speed"; }
QString symbol() const { return "average_speed"; }
QString units(bool metric) const { return metric ? "kph" : "mph"; }
double value(bool metric) const {
if (secsMoving == 0.0) return 0.0;
@@ -184,7 +184,7 @@ class AvgSpeed : public PointwiseRideMetric {
}
bool canAggregate() const { return true; }
void aggregateWith(RideMetric *other) {
assert(name() == other->name());
assert(symbol() == other->symbol());
AvgSpeed *as = dynamic_cast<AvgSpeed*>(other);
secsMoving += as->secsMoving;
km += as->km;
@@ -199,7 +199,7 @@ static bool avgSpeedAdded =
struct AvgPower : public AvgRideMetric {
QString name() const { return "average_power"; }
QString symbol() const { return "average_power"; }
QString units(bool) const { return "watts"; }
void perPoint(const RideFilePoint *point, double,
const RideFile *, const Zones *, int) {
@@ -218,7 +218,7 @@ static bool avgPowerAdded =
struct AvgHeartRate : public AvgRideMetric {
QString name() const { return "average_hr"; }
QString symbol() const { return "average_hr"; }
QString units(bool) const { return "bpm"; }
void perPoint(const RideFilePoint *point, double,
const RideFile *, const Zones *, int) {
@@ -237,7 +237,7 @@ static bool avgHeartRateAdded =
struct AvgCadence : public AvgRideMetric {
QString name() const { return "average_cad"; }
QString symbol() const { return "average_cad"; }
QString units(bool) const { return "rpm"; }
void perPoint(const RideFilePoint *point, double,
const RideFile *, const Zones *, int) {

View File

@@ -41,7 +41,7 @@ class XPower : public RideMetric {
public:
XPower() : xpower(0.0), secs(0.0) {}
QString name() const { return "skiba_xpower"; }
QString symbol() const { return "skiba_xpower"; }
QString units(bool) const { return "watts"; }
double value(bool) const { return xpower; }
void compute(const RideFile *ride, const Zones *, int,
@@ -88,7 +88,7 @@ class XPower : public RideMetric {
// added djconnel: allow RI to be combined across rides
bool canAggregate() const { return true; }
void aggregateWith(RideMetric *other) {
assert(name() == other->name());
assert(symbol() == other->symbol());
XPower *ap = dynamic_cast<XPower*>(other);
xpower = pow(xpower, bikeScoreN) * secs + pow(ap->xpower, bikeScoreN) * ap->secs;
secs += ap->secs;
@@ -106,7 +106,7 @@ class RelativeIntensity : public RideMetric {
public:
RelativeIntensity() : reli(0.0), secs(0.0) {}
QString name() const { return "skiba_relative_intensity"; }
QString symbol() const { return "skiba_relative_intensity"; }
QString units(bool) const { return ""; }
double value(bool) const { return reli; }
void compute(const RideFile *, const Zones *zones, int zoneRange,
@@ -123,7 +123,7 @@ class RelativeIntensity : public RideMetric {
// added djconnel: allow RI to be combined across rides
bool canAggregate() const { return true; }
void aggregateWith(RideMetric *other) {
assert(name() == other->name());
assert(symbol() == other->symbol());
RelativeIntensity *ap = dynamic_cast<RelativeIntensity*>(other);
reli = secs * pow(reli, bikeScoreN) + ap->secs * pow(ap->reli, bikeScoreN);
secs += ap->secs;
@@ -140,7 +140,7 @@ class BikeScore : public RideMetric {
public:
BikeScore() : score(0.0) {}
QString name() const { return "skiba_bike_score"; }
QString symbol() const { return "skiba_bike_score"; }
QString units(bool) const { return ""; }
double value(bool) const { return score; }
void compute(const RideFile *, const Zones *zones, int zoneRange,

View File

@@ -40,7 +40,7 @@ class DanielsPoints : public RideMetric {
public:
DanielsPoints() : score(0.0), cp(0.0) {}
QString name() const { return "daniels_points"; }
QString symbol() const { return "daniels_points"; }
QString units(bool) const { return ""; }
double value(bool) const { return score; }
void compute(const RideFile *ride, const Zones *zones,

View File

@@ -30,7 +30,11 @@ class Zones;
struct RideMetric {
virtual ~RideMetric() {}
virtual QString name() const = 0;
// The string by which we refer to this RideMetric in the code,
// configuration files, and caches (like stress.cache). It should
// not be translated, and it should never be shown to the user.
virtual QString symbol() const = 0;
virtual QString units(bool metric) const = 0;
virtual double value(bool metric) const = 0;
virtual void compute(const RideFile *ride,
@@ -74,7 +78,7 @@ class AvgRideMetric : public PointwiseRideMetric {
return total / count;
}
void aggregateWith(RideMetric *other) {
assert(name() == other->name());
assert(symbol() == other->symbol());
AvgRideMetric *as = dynamic_cast<AvgRideMetric*>(other);
count += as->count;
total += as->total;
@@ -106,30 +110,30 @@ class RideMetricFactory {
const QString &metricName(int i) const { return metricNames[i]; }
RideMetric *newMetric(const QString &name) const {
assert(metrics.contains(name));
return metrics.value(name)->clone();
RideMetric *newMetric(const QString &symbol) const {
assert(metrics.contains(symbol));
return metrics.value(symbol)->clone();
}
bool addMetric(const RideMetric &metric,
const QVector<QString> *deps = NULL) {
assert(!metrics.contains(metric.name()));
metrics.insert(metric.name(), metric.clone());
metricNames.append(metric.name());
assert(!metrics.contains(metric.symbol()));
metrics.insert(metric.symbol(), metric.clone());
metricNames.append(metric.symbol());
if (deps) {
QVector<QString> *copy = new QVector<QString>;
for (int i = 0; i < deps->size(); ++i) {
assert(metrics.contains((*deps)[i]));
copy->append((*deps)[i]);
}
dependencyMap.insert(metric.name(), copy);
dependencyMap.insert(metric.symbol(), copy);
}
return true;
}
const QVector<QString> &dependencies(const QString &name) const {
assert(metrics.contains(name));
QVector<QString> *result = dependencyMap.value(name);
const QVector<QString> &dependencies(const QString &symbol) const {
assert(metrics.contains(symbol));
QVector<QString> *result = dependencyMap.value(symbol);
return result ? *result : noDeps;
}
};

View File

@@ -204,30 +204,30 @@ WeeklySummaryWindow::refresh()
continue;
RideMetric *m;
if ((m = item->metrics.value(weeklySeconds->name()))) {
if ((m = item->metrics.value(weeklySeconds->symbol()))) {
weeklySeconds->aggregateWith(m);
dailySeconds[day]->aggregateWith(m);
}
if ((m = item->metrics.value(weeklyDistance->name()))) {
if ((m = item->metrics.value(weeklyDistance->symbol()))) {
weeklyDistance->aggregateWith(m);
dailyDistance[day]->aggregateWith(m);
}
if ((m = item->metrics.value(weeklyWork->name()))) {
if ((m = item->metrics.value(weeklyWork->symbol()))) {
weeklyWork->aggregateWith(m);
dailyW[day]->aggregateWith(m);
}
if ((m = item->metrics.value(weeklyCS->name())))
if ((m = item->metrics.value(weeklyCS->symbol())))
weeklyCS->aggregateWith(m);
if ((m = item->metrics.value(weeklyBS->name()))) {
if ((m = item->metrics.value(weeklyBS->symbol()))) {
weeklyBS->aggregateWith(m);
dailyBS[day]->aggregateWith(m);
}
if ((m = item->metrics.value(weeklyRelIntensity->name()))) {
if ((m = item->metrics.value(weeklyRelIntensity->symbol()))) {
weeklyRelIntensity->aggregateWith(m);
dailyRI[day]->aggregateWith(m);
}