DataFilter - Metric aggretation honors AggregateZero and Count

When computing metric averages
This commit is contained in:
Alejandro Martinez
2023-01-16 12:52:27 -03:00
parent c65f313de5
commit bfa4b4b977
2 changed files with 6 additions and 4 deletions

View File

@@ -4912,6 +4912,8 @@ Result Leaf::eval(DataFilterRuntime *df, Leaf *leaf, const Result &x, long it, R
double minimum=0;
double maximum=0;
double count=0;
// do we aggregate zero values ?
bool aggZero = e ? e->aggregateZero() : true;
// loop through rides for daterange
foreach(RideItem *ride, m->context->athlete->rideCache->rides()) {
@@ -4929,14 +4931,14 @@ Result Leaf::eval(DataFilterRuntime *df, Leaf *leaf, const Result &x, long it, R
value= QTime(0,0,0).secsTo(ride->dateTime.time());
if (wantstrings) asstring = ride->dateTime.toString("hh:mm:ss");
} else {
value = ride->getForSymbol(df->lookupMap.value(symbol,""), GlobalContext::context()->useMetricUnits);
value = ride->getForSymbol(o_symbol, GlobalContext::context()->useMetricUnits);
if (wantstrings) e ? asstring = e->toString(value) : "(null)";
}
// keep count of time for ride, useful when averaging
count++;
double duration = ride->getForSymbol("workout_time");
totalduration += duration;
double duration = ride->getCountForSymbol(o_symbol);
if (value || aggZero) totalduration += duration;
withduration += value * duration;
runningtotal += value;
if (count==1) {

View File

@@ -607,7 +607,7 @@ RideCache::getAggregate(QString name, Specification spec, bool useMetricUnits, b
// get this value
double value = item->getForSymbol(name);
double count = item->getForSymbol("workout_time"); // for averaging
double count = item->getCountForSymbol(name); // for averaging
// check values are bounded, just in case
if (std::isnan(value) || std::isinf(value)) value = 0;