mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-13 16:18:42 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user