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.
This commit is contained in:
Mark Liversedge
2015-08-21 10:28:17 +01:00
parent dbe92eec27
commit aced5805b1
4 changed files with 30 additions and 7 deletions

View File

@@ -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;
}

View File

@@ -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<QString, PMCData*> pmcData; // all the different PMC series
// athlete measures

View File

@@ -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))

View File

@@ -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_;