diff --git a/src/DataFilter.cpp b/src/DataFilter.cpp index 550d770f7..82df1bcdc 100644 --- a/src/DataFilter.cpp +++ b/src/DataFilter.cpp @@ -243,6 +243,7 @@ void Leaf::validateFilter(DataFilter *df, Leaf *leaf) QRegExp bestValidSymbols("^(apower|power|hr|cadence|speed|torque|vam|xpower|np|wpk)$", Qt::CaseInsensitive); QRegExp tizValidSymbols("^(power|hr)$", Qt::CaseInsensitive); QRegExp configValidSymbols("^(cp|w\\'|pmax|cv|d\\'|scv|sd\\'|height|weight|lthr|maxhr|rhr|units)$", Qt::CaseInsensitive); + QRegExp constValidSymbols("^(e|pi)$", Qt::CaseInsensitive); // just do basics for now QString symbol = leaf->series->lvalue.n->toLower(); if (leaf->function == "sts" || leaf->function == "lts" || leaf->function == "sb" || leaf->function == "rr") { @@ -262,6 +263,19 @@ void Leaf::validateFilter(DataFilter *df, Leaf *leaf) if (leaf->function == "config" && !configValidSymbols.exactMatch(symbol)) DataFiltererrors << QString(QObject::tr("invalid data series for config(): %1")).arg(symbol); + if (leaf->function == "const") { + if (!constValidSymbols.exactMatch(symbol)) + DataFiltererrors << QString(QObject::tr("invalid literal for const(): %1")).arg(symbol); + else { + + // convert to a float + leaf->type = Leaf::Float; + leaf->lvalue.f = 0.0L; + if (symbol == "e") leaf->lvalue.f = MATHCONST_E; + if (symbol == "pi") leaf->lvalue.f = MATHCONST_PI; + } + } + if (leaf->function == "best" || leaf->function == "tiz") { // now set the series type used as parameter 1 to best/tiz leaf->seriesType = nameToSeries(symbol); diff --git a/src/DataFilter.h b/src/DataFilter.h index 9b06c67a1..51398631f 100644 --- a/src/DataFilter.h +++ b/src/DataFilter.h @@ -123,4 +123,20 @@ class DataFilter : public QObject }; extern int DataFilterdebug; + +// some constants we provide to help accessed via const(name) +#define MATHCONST_E 2.718281828459045235360287471352662498L /* e */ +#define MATHCONST_LOG2E 1.442695040888963407359924681001892137L /* log_2 e */ +#define MATHCONST_LOG10E 0.434294481903251827651128918916605082L /* log_10 e */ +#define MATHCONST_LN2 0.693147180559945309417232121458176568L /* log_e 2 */ +#define MATHCONST_LN10 2.302585092994045684017991454684364208L /* log_e 10 */ +#define MATHCONST_PI 3.141592653589793238462643383279502884L /* pi */ +#define MATHCONST_PI_2 1.570796326794896619231321691639751442L /* pi/2 */ +#define MATHCONST_PI_4 0.785398163397448309615660845819875721L /* pi/4 */ +#define MATHCONST_1_PI 0.318309886183790671537767526745028724L /* 1/pi */ +#define MATHCONST_2_PI 0.636619772367581343075535053490057448L /* 2/pi */ +#define MATHCONST_2_SQRTPI 1.128379167095512573896158903121545172L /* 2/sqrt(pi) */ +#define MATHCONST_SQRT2 1.414213562373095048801688724209698079L /* sqrt(2) */ +#define MATHCONST_SQRT1_2 0.707106781186547524400844362104849039L /* 1/sqrt(2) */ + #endif diff --git a/src/DataFilter.l b/src/DataFilter.l index 6ed69b88b..331d31456 100644 --- a/src/DataFilter.l +++ b/src/DataFilter.l @@ -46,6 +46,8 @@ [Ee][Nn][Dd][Ss][Ww][Ii][Tt][Hh] DataFilterlval.op = ENDSWITH; return ENDSWITH; [Cc][Oo][Nn][Tt][Aa][Ii][Nn][Ss] DataFilterlval.op = CONTAINS; return CONTAINS; + /* functions identified by name in the lexer is probably + going to limit us in the future */ [Bb][Ee][Ss][Tt] strcpy(DataFilterlval.function, "best"); return BEST; [Tt][Ii][Zz] strcpy(DataFilterlval.function, "tiz"); return TIZ; [Ll][Tt][Ss] strcpy(DataFilterlval.function, "lts"); return LTS; @@ -53,6 +55,7 @@ [Ss][Bb] strcpy(DataFilterlval.function, "sb"); return SB; [Rr][Rr] strcpy(DataFilterlval.function, "rr"); return RR; [Cc][Oo][Nn][Ff][Ii][Gg] strcpy(DataFilterlval.function, "config"); return CONFIG; +[Cc][Oo][Nn][Ss][Tt] strcpy(DataFilterlval.function, "const"); return CONST; "&&" DataFilterlval.op = AND; return AND; [Aa][nN][Dd] DataFilterlval.op = AND; return AND; diff --git a/src/DataFilter.y b/src/DataFilter.y index 83165d39a..0c354c133 100644 --- a/src/DataFilter.y +++ b/src/DataFilter.y @@ -54,7 +54,7 @@ extern Leaf *root; // root node for parsed statement // Constants can be a string or a number %token DF_STRING DF_INTEGER DF_FLOAT -%token BEST TIZ STS LTS SB RR CONFIG +%token BEST TIZ STS LTS SB RR CONFIG CONST // comparative operators %token Q COL @@ -210,6 +210,11 @@ value : symbol { $$ = $1; } $$->series = $3; $$->lvalue.l = NULL; } + | CONST '(' symbol ')' { $$ = new Leaf(); $$->type = Leaf::Function; + $$->function = QString($1); + $$->series = $3; + $$->lvalue.l = NULL; + } ; %% diff --git a/src/LTMTool.cpp b/src/LTMTool.cpp index ff4bfa20e..1690425ae 100644 --- a/src/LTMTool.cpp +++ b/src/LTMTool.cpp @@ -1748,6 +1748,8 @@ EditMetricDetailDialog::EditMetricDetailDialog(Context *context, LTMTool *ltmToo list << "config(maxhr)"; list << "config(rhr)"; list << "config(units)"; + list << "const(e)"; + list << "const(pi)"; list << "ctl"; list << "tsb"; list << "atl";