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]
This commit is contained in:
Mark Liversedge
2020-09-12 09:58:30 +01:00
parent 1593576cff
commit f358f335b0
2 changed files with 32 additions and 0 deletions

View File

@@ -20,6 +20,7 @@
#define _GC_Athlete_h 1
#include "Measures.h"
#include "DataFilter.h"
#include <QDir>
#include <QSqlDatabase>
@@ -135,6 +136,9 @@ class Athlete : public QObject
// named filters / queries
NamedSearches *namedSearches;
// DataFilter global storage/cache
QMap<QString,Result> dfcache;
Context *context;
// ride collection

View File

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