PMCData - create a DataFilter for eval at refresh time

To avoid crashes at refresh time on PMC formulas with an expression argument
like sts(BikeStress ?: TRIMP_Zonal_Points)
Fixes #3788
[publish binaries]
This commit is contained in:
Ale Martinez
2021-05-05 18:29:47 -03:00
parent 1e1ddfaaee
commit d932811c97
2 changed files with 6 additions and 6 deletions

View File

@@ -41,7 +41,6 @@ PMCData::PMCData(Context *context, Specification spec, QString metricName, int s
// we're not from a datafilter
fromDataFilter = false;
df = NULL;
expr = NULL;
if (ltsDays < 0) {
@@ -79,12 +78,10 @@ PMCData::PMCData(Context *context, Specification spec, Leaf *expr, DataFilterRun
// use a metric name
metricName_ = metricName;
fromDataFilter = false;
df = NULL;
expr = NULL;
} else {
// use an expression - TODO: are df and expr still valid at refresh?
// use an expression
fromDataFilter = true;
this->df = df;
this->expr = expr;
}
@@ -255,6 +252,8 @@ void PMCData::refresh()
}
}
DataFilter* df = new DataFilter(this, context);
// add the stress scores
foreach(RideItem *item, context->athlete->rideCache->rides()) {
@@ -267,7 +266,7 @@ void PMCData::refresh()
// although metrics are cleansed, we check here because development
// builds have a rideDB.json that has nan and inf values in it.
double value = 0;;
if (fromDataFilter) value = expr->eval(df, expr, 0, 0, item).number();
if (fromDataFilter) value = expr->eval(&df->rt, expr, 0, 0, item).number();
else value = item->getForSymbol(metricName_);
if (!std::isinf(value) && !std::isnan(value)) {
@@ -280,6 +279,8 @@ void PMCData::refresh()
}
}
delete df;
//
// STEP THREE Calculate sts/lts, sb and rr
//

View File

@@ -116,7 +116,6 @@ class PMCData : public QObject {
Specification specification_;
bool fromDataFilter;
DataFilterRuntime *df;
Leaf *expr;
// parameters