From d2b44ec5081472448d7c0c0f8c0e520c6f314ff7 Mon Sep 17 00:00:00 2001 From: Sean Rhea Date: Sun, 20 Dec 2009 14:52:40 -0500 Subject: [PATCH] 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. --- src/AerobicDecoupling.cpp | 2 +- src/BasicRideMetrics.cpp | 22 +++++++++++----------- src/BikeScore.cpp | 10 +++++----- src/DanielsPoints.cpp | 2 +- src/RideMetric.h | 28 ++++++++++++++++------------ src/WeeklySummaryWindow.cpp | 12 ++++++------ 6 files changed, 40 insertions(+), 36 deletions(-) diff --git a/src/AerobicDecoupling.cpp b/src/AerobicDecoupling.cpp index 2e53aae0c..d9c22ba7b 100644 --- a/src/AerobicDecoupling.cpp +++ b/src/AerobicDecoupling.cpp @@ -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, diff --git a/src/BasicRideMetrics.cpp b/src/BasicRideMetrics.cpp index 2e8c1b7e1..55c43420e 100644 --- a/src/BasicRideMetrics.cpp +++ b/src/BasicRideMetrics.cpp @@ -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(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(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) { diff --git a/src/BikeScore.cpp b/src/BikeScore.cpp index 70fda17a3..0bbe855d1 100644 --- a/src/BikeScore.cpp +++ b/src/BikeScore.cpp @@ -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(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(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, diff --git a/src/DanielsPoints.cpp b/src/DanielsPoints.cpp index d82cbb546..ce92c10e1 100644 --- a/src/DanielsPoints.cpp +++ b/src/DanielsPoints.cpp @@ -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, diff --git a/src/RideMetric.h b/src/RideMetric.h index a597be595..31ecc25cd 100644 --- a/src/RideMetric.h +++ b/src/RideMetric.h @@ -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(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 *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 *copy = new QVector; 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 &dependencies(const QString &name) const { - assert(metrics.contains(name)); - QVector *result = dependencyMap.value(name); + const QVector &dependencies(const QString &symbol) const { + assert(metrics.contains(symbol)); + QVector *result = dependencyMap.value(symbol); return result ? *result : noDeps; } }; diff --git a/src/WeeklySummaryWindow.cpp b/src/WeeklySummaryWindow.cpp index 7b02a86d3..0b9e4748e 100644 --- a/src/WeeklySummaryWindow.cpp +++ b/src/WeeklySummaryWindow.cpp @@ -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); }