diff --git a/src/Core/DataFilter.cpp b/src/Core/DataFilter.cpp index f85ba48f7..ee880631c 100644 --- a/src/Core/DataFilter.cpp +++ b/src/Core/DataFilter.cpp @@ -17,6 +17,7 @@ */ #include "Utils.h" +#include "Statistic.h" #include "DataFilter.h" #include "Context.h" #include "Athlete.h" @@ -200,6 +201,9 @@ static struct { // not need the data to be sorted, as it uses argsort internally. As // you can pass multiple vectors they are uniqued in sync with the first list. + { "variance", 1 }, // variance(v) - calculates the variance for the elements in the vector. + { "stddev", 1 }, // stddev(v) - calculates the standard deviation for elements in the vector. + // add new ones above this line { "", -1 } @@ -2948,6 +2952,7 @@ Result Leaf::eval(DataFilterRuntime *df, Leaf *leaf, float x, long it, RideItem return returning; } + // uniq if (leaf->function == "uniq") { // evaluate all the lists @@ -2968,7 +2973,7 @@ Result Leaf::eval(DataFilterRuntime *df, Leaf *leaf, float x, long it, RideItem // diff length? if (current.vector.count() != len) { - fprintf(stderr, "sort list '%s': not the same length, ignored\n", symbol.toStdString().c_str()); fflush(stderr); + fprintf(stderr, "uniq list '%s': not the same length, ignored\n", symbol.toStdString().c_str()); fflush(stderr); continue; } @@ -3211,6 +3216,21 @@ Result Leaf::eval(DataFilterRuntime *df, Leaf *leaf, float x, long it, RideItem return returning; } + // stddev + if (leaf->function == "variance") { + // array + Result v = eval(df,leaf->fparms[0],x, it, m, p, c, s, d); + Statistic calc; + return calc.variance(v.vector, v.vector.count()); + } + + if (leaf->function == "stddev") { + // array + Result v = eval(df,leaf->fparms[0],x, it, m, p, c, s, d); + Statistic calc; + return calc.standarddeviation(v.vector, v.vector.count()); + } + // pmc if (leaf->function == "pmc") { diff --git a/src/Metrics/Statistic.h b/src/Metrics/Statistic.h index b852b4c43..5da3f6cc1 100644 --- a/src/Metrics/Statistic.h +++ b/src/Metrics/Statistic.h @@ -40,15 +40,6 @@ class Statistic double corr(QVector &Xi, QVector &Yi,int n); double average(QVector &Xi,int n); - protected: - long points; - double sumX, sumY; - double sumXsquared, - sumYsquared; - double sumXY; - double a, b, c; // a = intercept, b = slope, c = r2 - - private: // Maths functions used by the plots QVector array_temp; //Déclaration d'un tableau temporaire @@ -70,6 +61,14 @@ class Statistic double variance(QVector &val,int n); double standarddeviation(QVector &val,int n); + protected: + long points; + double sumX, sumY; + double sumXsquared, + sumYsquared; + double sumXY; + double a, b, c; // a = intercept, b = slope, c = r2 + }; #endif