From f358f335b06e5192ba66739b005d704950d1e44a Mon Sep 17 00:00:00 2001 From: Mark Liversedge Date: Sat, 12 Sep 2020 09:58:30 +0100 Subject: [PATCH] DataFilter - store/fetch values .. saves/loads values to athlete global area, particularly useful when modelling as you can save away parameter estimates that may have been expensive to compute, and re-use them across series in a user chart. .. they are not saved across restarts, but we could fix that later if they become more useful .. store("name", value) and fetch("name"). if the named value does not exist 0 is returned. [publish binaries] --- src/Core/Athlete.h | 4 ++++ src/Core/DataFilter.cpp | 28 ++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/Core/Athlete.h b/src/Core/Athlete.h index 826e2add3..cb9402c5a 100644 --- a/src/Core/Athlete.h +++ b/src/Core/Athlete.h @@ -20,6 +20,7 @@ #define _GC_Athlete_h 1 #include "Measures.h" +#include "DataFilter.h" #include #include @@ -135,6 +136,9 @@ class Athlete : public QObject // named filters / queries NamedSearches *namedSearches; + // DataFilter global storage/cache + QMap dfcache; + Context *context; // ride collection diff --git a/src/Core/DataFilter.cpp b/src/Core/DataFilter.cpp index bda4d106f..70c545a08 100644 --- a/src/Core/DataFilter.cpp +++ b/src/Core/DataFilter.cpp @@ -320,6 +320,12 @@ static struct { // kind of interpolation applied (resample/interpolate are available to // do that if needed. + { "store", 2 }, // store("name", value) stores a global value that can be retrieved via + // the fetch("name") function below. Useful for passing data across data series + // in a user chart. + { "fetch", 1 }, // fetch("name") retrieves a value previously stored returns 0 if the value + // is not in the athlete store + // add new ones above this line { "", -1 } }; @@ -4649,6 +4655,28 @@ Result Leaf::eval(DataFilterRuntime *df, Leaf *leaf, Result x, long it, RideItem return Result(count); } + // store/fetch from athlete storage + if (leaf->function == "store") { + // name and value in parameter 1 and 2 + QString name= eval(df, leaf->fparms[0],x, it, m, p, c, s, d).string(); + Result value= eval(df, leaf->fparms[1],x, it, m, p, c, s, d); + + // store it away + m->context->athlete->dfcache.insert(name, value); + + return Result(0); + } + + if (leaf->function == "fetch") { + // name and value in parameter 1 and 2 + QString name= eval(df, leaf->fparms[0],x, it, m, p, c, s, d).string(); + + // store it away + Result returning = m->context->athlete->dfcache.value(name, Result(0)); + + return returning; + } + // access user chart curve data, if it's there if (leaf->function == "curve") {