Added Simple Average trend type to Metrics Trends charts

Combined with the Group By feature, it allows a simple way
to see weekly, monthly and yearly averages for cumulative
metrics s.t. Duration, Distance, TSS, etc.
This commit is contained in:
Alejandro Martinez
2016-10-25 23:06:29 -03:00
parent 7c78c928a8
commit f33cf61ca3
3 changed files with 45 additions and 0 deletions

View File

@@ -793,6 +793,49 @@ LTMPlot::setData(LTMSettings *set)
curves.insert(trendSymbol, trend);
}
}
// Simple Average
if (metricDetail.trendtype == 4 && count > 2) {
// override class variable as doing it temporarily for trend line only
double maxX = 0.5 + groupForDate(settings->end.date(), settings->groupBy) -
groupForDate(settings->start.date(), settings->groupBy);
QString trendName = QString(tr("%1 average")).arg(metricDetail.uname);
QString trendSymbol = QString("%1_trend")
.arg((metricDetail.type == METRIC_BEST || metricDetail.type == METRIC_STRESS) ?
metricDetail.bestSymbol : metricDetail.symbol);
QwtPlotCurve *trend = new QwtPlotCurve(trendName);
trend->setVisible(!metricDetail.hidden);
// cosmetics
QPen cpen = QPen(metricDetail.penColor.darker(200));
cpen.setWidth(2); // double thickness for trend lines
cpen.setStyle(Qt::SolidLine);
trend->setPen(cpen);
if (appsettings->value(this, GC_ANTIALIAS, true).toBool()==true)
trend->setRenderHint(QwtPlotItem::RenderAntialiased);
trend->setBaseline(0);
trend->setYAxis(axisid);
trend->setStyle(QwtPlotCurve::Lines);
// perform simple average
LTMTrend regress(xdata.data(), ydata.data(), count);
double xtrend[2], ytrend[2];
xtrend[0] = 0.0;
ytrend[0] = regress.getYavg();
// point 2 is at far right of chart, not the last point
// since we may be forecasting...
xtrend[1] = maxX;
ytrend[1] = regress.getYavg();
trend->setSamples(xtrend,ytrend, 2);
trend->attach(this);
trend->setItemAttribute(QwtPlotItem::Legend, false);
curves.insert(trendSymbol, trend);
}
}
// highlight outliers

View File

@@ -2025,6 +2025,7 @@ EditMetricDetailDialog::EditMetricDetailDialog(Context *context, LTMTool *ltmToo
trendType->addItem(tr("Linear Trend"));
trendType->addItem(tr("Quadratic Trend"));
trendType->addItem(tr("Moving Average"));
trendType->addItem(tr("Simple Average"));
trendType->setCurrentIndex(metricDetail->trendtype);
// add to grid

View File

@@ -28,6 +28,7 @@ class LTMTrend
double getYforX(double x) const { return (a + b * x); }
double intercept() { return a; }
double slope() { return b; }
double getYavg() { return points > 0 ? sumY / (double)points : 0.0; }
double minX, maxX, minY, maxY; // for the data set we have