aggregateWith takes a const reference

This commit is contained in:
Sean Rhea
2009-12-20 16:59:04 -05:00
parent 0d7e923c93
commit e16443e23f
6 changed files with 45 additions and 50 deletions

View File

@@ -82,8 +82,6 @@ class AerobicDecoupling : public RideMetric {
} }
} }
bool canAggregate() const { return false; }
void aggregateWith(RideMetric *) { assert(false); }
RideMetric *clone() const { return new AerobicDecoupling(*this); } RideMetric *clone() const { return new AerobicDecoupling(*this); }
}; };

View File

@@ -37,7 +37,7 @@ class WorkoutTime : public RideMetric {
seconds = ride->dataPoints().back()->secs; seconds = ride->dataPoints().back()->secs;
} }
bool canAggregate() const { return true; } bool canAggregate() const { return true; }
void aggregateWith(RideMetric *other) { seconds += other->value(true); } void aggregateWith(const RideMetric &other) { seconds += other.value(true); }
RideMetric *clone() const { return new WorkoutTime(*this); } RideMetric *clone() const { return new WorkoutTime(*this); }
}; };
@@ -65,8 +65,8 @@ class TimeRiding : public RideMetric {
} }
} }
bool canAggregate() const { return true; } bool canAggregate() const { return true; }
void aggregateWith(RideMetric *other) { void aggregateWith(const RideMetric &other) {
secsMovingOrPedaling += other->value(true); secsMovingOrPedaling += other.value(true);
} }
RideMetric *clone() const { return new TimeRiding(*this); } RideMetric *clone() const { return new TimeRiding(*this); }
}; };
@@ -94,7 +94,7 @@ class TotalDistance : public RideMetric {
km = ride->dataPoints().back()->km; km = ride->dataPoints().back()->km;
} }
bool canAggregate() const { return true; } bool canAggregate() const { return true; }
void aggregateWith(RideMetric *other) { km += other->value(true); } void aggregateWith(const RideMetric &other) { km += other.value(true); }
RideMetric *clone() const { return new TotalDistance(*this); } RideMetric *clone() const { return new TotalDistance(*this); }
}; };
@@ -132,8 +132,8 @@ class ElevationGain : public RideMetric {
} }
} }
bool canAggregate() const { return true; } bool canAggregate() const { return true; }
void aggregateWith(RideMetric *other) { void aggregateWith(const RideMetric &other) {
elegain += other->value(true); elegain += other.value(true);
} }
RideMetric *clone() const { return new ElevationGain(*this); } RideMetric *clone() const { return new ElevationGain(*this); }
}; };
@@ -162,10 +162,10 @@ class TotalWork : public RideMetric {
} }
} }
bool canAggregate() const { return true; } bool canAggregate() const { return true; }
void aggregateWith(RideMetric *other) { void aggregateWith(const RideMetric &other) {
assert(symbol() == other->symbol()); assert(symbol() == other.symbol());
TotalWork *tw = dynamic_cast<TotalWork*>(other); const TotalWork &tw = dynamic_cast<const TotalWork&>(other);
joules += tw->joules; joules += tw.joules;
} }
RideMetric *clone() const { return new TotalWork(*this); } RideMetric *clone() const { return new TotalWork(*this); }
}; };
@@ -198,11 +198,11 @@ class AvgSpeed : public RideMetric {
if (point->kph > 0.0) secsMoving += ride->recIntSecs(); if (point->kph > 0.0) secsMoving += ride->recIntSecs();
} }
bool canAggregate() const { return true; } bool canAggregate() const { return true; }
void aggregateWith(RideMetric *other) { void aggregateWith(const RideMetric &other) {
assert(symbol() == other->symbol()); assert(symbol() == other.symbol());
AvgSpeed *as = dynamic_cast<AvgSpeed*>(other); const AvgSpeed &as = dynamic_cast<const AvgSpeed&>(other);
secsMoving += as->secsMoving; secsMoving += as.secsMoving;
km += as->km; km += as.km;
} }
RideMetric *clone() const { return new AvgSpeed(*this); } RideMetric *clone() const { return new AvgSpeed(*this); }
}; };

View File

@@ -91,11 +91,11 @@ class XPower : public RideMetric {
// added djconnel: allow RI to be combined across rides // added djconnel: allow RI to be combined across rides
bool canAggregate() const { return true; } bool canAggregate() const { return true; }
void aggregateWith(RideMetric *other) { void aggregateWith(const RideMetric &other) {
assert(symbol() == other->symbol()); assert(symbol() == other.symbol());
XPower *ap = dynamic_cast<XPower*>(other); const XPower &ap = dynamic_cast<const XPower&>(other);
xpower = pow(xpower, bikeScoreN) * secs + pow(ap->xpower, bikeScoreN) * ap->secs; xpower = pow(xpower, bikeScoreN) * secs + pow(ap.xpower, bikeScoreN) * ap.secs;
secs += ap->secs; secs += ap.secs;
xpower = pow(xpower / secs, 1 / bikeScoreN); xpower = pow(xpower / secs, 1 / bikeScoreN);
} }
// end added djconnel // end added djconnel
@@ -128,11 +128,11 @@ class RelativeIntensity : public RideMetric {
// added djconnel: allow RI to be combined across rides // added djconnel: allow RI to be combined across rides
bool canAggregate() const { return true; } bool canAggregate() const { return true; }
void aggregateWith(RideMetric *other) { void aggregateWith(const RideMetric &other) {
assert(symbol() == other->symbol()); assert(symbol() == other.symbol());
RelativeIntensity *ap = dynamic_cast<RelativeIntensity*>(other); const RelativeIntensity &ap = dynamic_cast<const RelativeIntensity&>(other);
reli = secs * pow(reli, bikeScoreN) + ap->secs * pow(ap->reli, bikeScoreN); reli = secs * pow(reli, bikeScoreN) + ap.secs * pow(ap.reli, bikeScoreN);
secs += ap->secs; secs += ap.secs;
reli = pow(reli / secs, 1.0 / bikeScoreN); reli = pow(reli / secs, 1.0 / bikeScoreN);
} }
// end added djconnel // end added djconnel
@@ -171,7 +171,7 @@ class BikeScore : public RideMetric {
} }
RideMetric *clone() const { return new BikeScore(*this); } RideMetric *clone() const { return new BikeScore(*this); }
bool canAggregate() const { return true; } bool canAggregate() const { return true; }
void aggregateWith(RideMetric *other) { score += other->value(true); } void aggregateWith(const RideMetric &other) { score += other.value(true); }
}; };
static bool addAllThree() { static bool addAllThree() {

View File

@@ -97,10 +97,7 @@ class DanielsPoints : public RideMetric {
count(secsDelta, weighted); count(secsDelta, weighted);
} }
} }
virtual void aggregateWith(RideMetric *other) { void aggregateWith(const RideMetric &other) { score += other.value(true); }
DanielsPoints *cs = (DanielsPoints*) other;
score += cs->score;
}
RideMetric *clone() const { return new DanielsPoints(*this); } RideMetric *clone() const { return new DanielsPoints(*this); }
}; };

View File

@@ -69,7 +69,7 @@ struct RideMetric {
assert(false); assert(false);
} }
virtual bool canAggregate() const { return false; } virtual bool canAggregate() const { return false; }
virtual void aggregateWith(RideMetric *other) { virtual void aggregateWith(const RideMetric &other) {
(void) other; (void) other;
assert(false); assert(false);
} }
@@ -90,11 +90,11 @@ class AvgRideMetric : public RideMetric {
if (count == 0) return 0.0; if (count == 0) return 0.0;
return total / count; return total / count;
} }
void aggregateWith(RideMetric *other) { void aggregateWith(const RideMetric &other) {
assert(symbol() == other->symbol()); assert(symbol() == other.symbol());
AvgRideMetric *as = dynamic_cast<AvgRideMetric*>(other); const AvgRideMetric &as = dynamic_cast<const AvgRideMetric&>(other);
count += as->count; count += as.count;
total += as->total; total += as.total;
} }
}; };

View File

@@ -205,35 +205,35 @@ WeeklySummaryWindow::refresh()
RideMetric *m; RideMetric *m;
if ((m = item->metrics.value(weeklySeconds->symbol()))) { if ((m = item->metrics.value(weeklySeconds->symbol()))) {
weeklySeconds->aggregateWith(m); weeklySeconds->aggregateWith(*m);
dailySeconds[day]->aggregateWith(m); dailySeconds[day]->aggregateWith(*m);
} }
if ((m = item->metrics.value(weeklyDistance->symbol()))) { if ((m = item->metrics.value(weeklyDistance->symbol()))) {
weeklyDistance->aggregateWith(m); weeklyDistance->aggregateWith(*m);
dailyDistance[day]->aggregateWith(m); dailyDistance[day]->aggregateWith(*m);
} }
if ((m = item->metrics.value(weeklyWork->symbol()))) { if ((m = item->metrics.value(weeklyWork->symbol()))) {
weeklyWork->aggregateWith(m); weeklyWork->aggregateWith(*m);
dailyW[day]->aggregateWith(m); dailyW[day]->aggregateWith(*m);
} }
if ((m = item->metrics.value(weeklyCS->symbol()))) if ((m = item->metrics.value(weeklyCS->symbol())))
weeklyCS->aggregateWith(m); weeklyCS->aggregateWith(*m);
if ((m = item->metrics.value(weeklyBS->symbol()))) { if ((m = item->metrics.value(weeklyBS->symbol()))) {
weeklyBS->aggregateWith(m); weeklyBS->aggregateWith(*m);
dailyBS[day]->aggregateWith(m); dailyBS[day]->aggregateWith(*m);
} }
if ((m = item->metrics.value(weeklyRelIntensity->symbol()))) { if ((m = item->metrics.value(weeklyRelIntensity->symbol()))) {
weeklyRelIntensity->aggregateWith(m); weeklyRelIntensity->aggregateWith(*m);
dailyRI[day]->aggregateWith(m); dailyRI[day]->aggregateWith(*m);
} }
if ((m = item->metrics.value("skiba_xpower"))) if ((m = item->metrics.value("skiba_xpower")))
dailyXP[day]->aggregateWith(m); dailyXP[day]->aggregateWith(*m);
// compute time in zones // compute time in zones
if (zones) { if (zones) {