Permalink
Browse files

Merge pull request #2679 from amtriathlon/Measures

LTMPlot - Access to Measures by days
  • Loading branch information...
amtriathlon committed Nov 2, 2017
2 parents dfc27ff + 316983e commit fd090e6104cf14e6b143f7ac12ba57cf2f39c344
View
@@ -2614,6 +2614,9 @@ LTMPlot::createCurveData(Context *context, LTMSettings *settings, MetricDetail m
} else if (metricDetail.type == METRIC_FORMULA) {
createFormulaData(context, settings, metricDetail, x,y,n, forceZero);
return;
} else if (metricDetail.type == METRIC_D_MEASURE) {
createMeasureData(context, settings, metricDetail, x,y,n, forceZero);
return;
}
}
@@ -3530,6 +3533,88 @@ LTMPlot::createPMCData(Context *context, LTMSettings *settings, MetricDetail met
if (localPMC) delete localPMC;
}
void
LTMPlot::createMeasureData(Context *context, LTMSettings *settings, MetricDetail metricDetail, QVector<double>&x,QVector<double>&y,int&n, bool)
{
int maxdays = groupForDate(settings->end.date(), settings->groupBy)
- groupForDate(settings->start.date(), settings->groupBy);
// skip for negative or empty time periods.
if (maxdays <=0) return;
x.resize(maxdays+3); // one for start from zero plus two for 0 value added at head and tail
y.resize(maxdays+3); // one for start from zero plus two for 0 value added at head and tail
// iterate over it and create curve...
n=-1;
int lastDay=0;
unsigned long secondsPerGroupBy=0;
bool wantZero = true;
for (QDate date=settings->start.date(); date <= settings->end.date(); date = date.addDays(1)) {
// day we are on
int currentDay = groupForDate(date, settings->groupBy);
// value for day
double value = context->athlete->getMeasureValue(date, metricDetail.measureGroup, metricDetail.measureField, context->athlete->useMetricUnits);
if (value || wantZero) {
unsigned long seconds = 1;
if (currentDay > lastDay) {
if (lastDay && wantZero) {
while (lastDay<currentDay) {
lastDay++;
n++;
x[n]=lastDay - groupForDate(settings->start.date(), settings->groupBy);
y[n]=0;
}
} else {
n++;
}
y[n] = value;
x[n] = currentDay - groupForDate(settings->start.date(), settings->groupBy);
// only increment counter if nonzero or we aggregate zeroes
secondsPerGroupBy = seconds;
} else {
// sum totals, average averages and choose best for Peaks
int type = RideMetric::Average;
// first time thru
if (n<0) n++;
switch (type) {
case RideMetric::Total:
y[n] += value;
break;
case RideMetric::Average:
{
// average should be calculated taking into account
// the duration of the ride, otherwise high value but
// short rides will skew the overall average
y[n] = ((y[n]*secondsPerGroupBy)+(seconds*value)) / (secondsPerGroupBy+seconds);
break;
}
case RideMetric::Low:
if (value < y[n]) y[n] = value;
break;
case RideMetric::Peak:
if (value > y[n]) y[n] = value;
break;
case RideMetric::MeanSquareRoot:
if (value) y[n] = sqrt((pow(y[n],2)*secondsPerGroupBy + pow(value,2)*value)/(secondsPerGroupBy+seconds));
break;
}
secondsPerGroupBy += seconds; // increment for same group
}
lastDay = currentDay;
}
}
}
QwtAxisId
LTMPlot::chooseYAxis(QString units)
{
View
@@ -131,6 +131,9 @@ class LTMPlot : public QwtPlot
// create curve data from bests (from ridefile cache)
void createBestsData(Context *,LTMSettings *, MetricDetail, QVector<double>&, QVector<double>&, int&, bool=false);
// create curve data from Measure (Body, Hrv)
void createMeasureData(Context *,LTMSettings *, MetricDetail, QVector<double>&, QVector<double>&, int&, bool=false);
// create a curve based upon TOD
void createTODCurveData(Context *,LTMSettings *, MetricDetail, QVector<double>&, QVector<double>&, int&, bool=false);
@@ -227,6 +227,8 @@ QDataStream &operator<<(QDataStream &out, const LTMSettings &settings)
out<<metric.formula;
out<<static_cast<int>(metric.formulaType);
out<<metric.datafilter;
out<<metric.measureGroup;
out<<metric.measureField;
}
out<<settings.showData;
out<<settings.stack;
@@ -352,6 +354,10 @@ while(counter-- && !in.atEnd()) {
if (version >= 16) {
in >> m.datafilter;
}
if (version >= 17) {
in >> m.measureGroup;
in >> m.measureField;
}
bool keep=true;
// check for deprecated things and set keep=false if
// we don't support this any more !
View
@@ -50,8 +50,9 @@ class RideBest;
// 14 13 Aug 2015 Mark Liversedge Added formula metric type
// 15 13 Aug 2015 Mark Liversedge Added formula aggregation type Avg, Total, Low etc
// 16 14 Aug 2015 Mark Liversedge Added curve specific filter
// 17 01 Nov 2017 Ale Martinez Added Daily Measure type (Body/Hrv)
#define LTM_VERSION_NUMBER 16
#define LTM_VERSION_NUMBER 17
// group by settings
#define LTM_DAY 1
@@ -70,6 +71,7 @@ class RideBest;
#define METRIC_ESTIMATE 6
#define METRIC_STRESS 7
#define METRIC_FORMULA 8
#define METRIC_D_MEASURE 9
// type of estimate
#define ESTIMATE_WPRIME 0
@@ -104,7 +106,7 @@ class MetricDetail {
public:
MetricDetail() : type(METRIC_DB), stack(false), hidden(false), model(""), formulaType(RideMetric::Average), name(""),
metric(NULL), stressType(0),
metric(NULL), stressType(0), measureGroup(0), measureField(0),
smooth(false), trendtype(0), topN(0), lowestN(0), topOut(0), baseline(0.0),
curveStyle(QwtPlotCurve::Lines), symbolStyle(QwtSymbol::NoSymbol),
penColor(Qt::black), penAlpha(0), penWidth(1.0), penStyle(0),
@@ -140,6 +142,10 @@ class MetricDetail {
// for STRESS
int stressType; // 0-LTS 1-STS 2-SB 3-RR
// for DAILY MEASURES
int measureGroup; // 0-BODY 1-HRV
int measureField; // Weight, RMSSD, etc.
// GENERAL SETTINGS FOR A METRIC
QString uname, uunits; // user specified name and units (axis choice)
Oops, something went wrong.

0 comments on commit fd090e6

Please sign in to comment.