From aced5805b1c63adc4165b0bb2a99ebde6e3d14e1 Mon Sep 17 00:00:00 2001 From: Mark Liversedge Date: Fri, 21 Aug 2015 10:28:17 +0100 Subject: [PATCH] DataFilter in PMC - Part 2 of 3 .. slight fixup to use Leaf expression not the entire data filter in PMCData and now the series is stored in the Athlete PMC store alongside the other series. .. just need to adjust the parser to accept expr rather than symbols as inputs to the lts functions. --- src/Athlete.cpp | 19 +++++++++++++++++++ src/Athlete.h | 3 +++ src/PMCData.cpp | 12 ++++++------ src/PMCData.h | 3 ++- 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/Athlete.cpp b/src/Athlete.cpp index 15387799d..b6b357a5b 100644 --- a/src/Athlete.cpp +++ b/src/Athlete.cpp @@ -541,3 +541,22 @@ Athlete::getPMCFor(QString metricName, int stsdays, int ltsdays) return returning; } + +PMCData * +Athlete::getPMCFor(Leaf *expr, DataFilter *df, int stsdays, int ltsdays) +{ + PMCData *returning = NULL; + + // if we don't already have one, create it + returning = pmcData.value(expr->signature(), NULL); + if (!returning) { + + // specification is blank and passes for all + returning = new PMCData(context, Specification(), expr, df, stsdays, ltsdays); + + // add to our collection + pmcData.insert(expr->signature(), returning); + } + + return returning; +} diff --git a/src/Athlete.h b/src/Athlete.h index fc9a62aba..733494c6d 100644 --- a/src/Athlete.h +++ b/src/Athlete.h @@ -58,6 +58,8 @@ class Context; class ColorEngine; class AnalysisSidebar; class Tab; +class Leaf; +class DataFilter; class Athlete : public QObject { @@ -97,6 +99,7 @@ class Athlete : public QObject // PMC Data PMCData *getPMCFor(QString metricName, int stsDays = -1, int ltsDays = -1); // no Specification used! + PMCData *getPMCFor(Leaf *expr, DataFilter *df, int stsDays = -1, int ltsDays = -1); // no Specification used! QMap pmcData; // all the different PMC series // athlete measures diff --git a/src/PMCData.cpp b/src/PMCData.cpp index 319e2ff3c..9d5899615 100644 --- a/src/PMCData.cpp +++ b/src/PMCData.cpp @@ -42,6 +42,7 @@ 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) { QVariant lts = appsettings->cvalue(context->athlete->cyclist, GC_LTS_DAYS); @@ -63,17 +64,16 @@ PMCData::PMCData(Context *context, Specification spec, QString metricName, int s connect(context, SIGNAL(refreshUpdate(QDate)), this, SLOT(invalidate())); } -PMCData::PMCData(Context *context, Specification spec, DataFilter *df, int stsDays, int ltsDays) +PMCData::PMCData(Context *context, Specification spec, Leaf *expr, DataFilter *df, int stsDays, int ltsDays) : context(context), specification_(spec), metricName_(""), stsDays_(stsDays), ltsDays_(ltsDays), isstale(true) { // get defaults if not passed useDefaults = false; + + // use an expression fromDataFilter = true; this->df = df; - - // we're not from a datafilter - fromDataFilter = false; - df = NULL; + this->expr = expr; if (ltsDays < 0) { QVariant lts = appsettings->cvalue(context->athlete->cyclist, GC_LTS_DAYS); @@ -216,7 +216,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 = df->evaluate(item).number; + if (fromDataFilter) value = expr->eval(context, df, expr, item).number; else value = item->getForSymbol(metricName_); if (!std::isinf(value) && !std::isnan(value)) diff --git a/src/PMCData.h b/src/PMCData.h index a37c3b473..b604f1206 100644 --- a/src/PMCData.h +++ b/src/PMCData.h @@ -42,7 +42,7 @@ class PMCData : public QObject { // create a PMC data series for the athlete // for ALL date ranges PMCData(Context *, Specification specification, QString metricName, int stsDays=-1, int ltsDays=-1); - PMCData(Context *, Specification specification, DataFilter *df, int stsDays=-1, int ltsDays=-1); + PMCData(Context *, Specification specification, Leaf *expr, DataFilter *df, int stsDays=-1, int ltsDays=-1); // set parameters void setStsDays(int x) { stsDays_ = x; invalidate(); } @@ -99,6 +99,7 @@ class PMCData : public QObject { bool fromDataFilter; DataFilter *df; + Leaf *expr; // parameters QString metricName_;