mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-04-13 12:42:20 +00:00
Fix SEGV LTM Edit
.. when using Moving Average trend.
This commit is contained in:
100
src/LTMPlot.cpp
100
src/LTMPlot.cpp
@@ -755,36 +755,38 @@ LTMPlot::setData(LTMSettings *set)
|
|||||||
// we need to fill in the gaps sadly
|
// we need to fill in the gaps sadly
|
||||||
int lcount = xdata[count];
|
int lcount = xdata[count];
|
||||||
|
|
||||||
// calculated values
|
if (lcount) {
|
||||||
QVector<double> xtrend(lcount);
|
// calculated values
|
||||||
QVector<double> btrend(lcount);
|
QVector<double> xtrend(lcount);
|
||||||
QVector<double> ytrend(lcount);
|
QVector<double> btrend(lcount);
|
||||||
|
QVector<double> ytrend(lcount);
|
||||||
|
|
||||||
// initialise to same
|
// initialise to same
|
||||||
ytrend.fill(0);
|
ytrend.fill(0);
|
||||||
btrend.fill(0);
|
btrend.fill(0);
|
||||||
|
|
||||||
ytrend[0] = ydata[0];
|
ytrend[0] = ydata[0];
|
||||||
xtrend[0] = 0;
|
xtrend[0] = 0;
|
||||||
|
|
||||||
for (int n=1,i=1; i<= lcount; i++) {
|
for (int n=1,i=1; i<= lcount && i<xdata.size(); i++) {
|
||||||
|
|
||||||
// fill in gaps (and check bounds as we go too)
|
// fill in gaps (and check bounds as we go too)
|
||||||
while (n<=xdata[i] && n<lcount) {
|
while (n<=xdata[i] && n<lcount) {
|
||||||
ytrend[n] = alpha * ydata[i] + ( 1 - alpha )*( ytrend[n-1] + btrend[n-1] );
|
ytrend[n] = alpha * ydata[i] + ( 1 - alpha )*( ytrend[n-1] + btrend[n-1] );
|
||||||
btrend[n] = beta * ( ytrend[n] - ytrend[n-1] ) + ( 1 - beta ) * btrend[n-1];
|
btrend[n] = beta * ( ytrend[n] - ytrend[n-1] ) + ( 1 - beta ) * btrend[n-1];
|
||||||
xtrend[n] = n+1;
|
xtrend[n] = n+1;
|
||||||
n++;
|
n++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// point 2 is at far right of chart, not the last point
|
||||||
|
// since we may be forecasting...
|
||||||
|
trend->setSamples(xtrend.data(),ytrend.data(), xtrend.count());
|
||||||
|
|
||||||
|
trend->attach(this);
|
||||||
|
trend->setItemAttribute(QwtPlotItem::Legend, false);
|
||||||
|
curves.insert(trendSymbol, trend);
|
||||||
}
|
}
|
||||||
|
|
||||||
// point 2 is at far right of chart, not the last point
|
|
||||||
// since we may be forecasting...
|
|
||||||
trend->setSamples(xtrend.data(),ytrend.data(), xtrend.count());
|
|
||||||
|
|
||||||
trend->attach(this);
|
|
||||||
trend->setItemAttribute(QwtPlotItem::Legend, false);
|
|
||||||
curves.insert(trendSymbol, trend);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1860,36 +1862,38 @@ LTMPlot::setCompareData(LTMSettings *set)
|
|||||||
// we need to fill in the gaps sadly
|
// we need to fill in the gaps sadly
|
||||||
int lcount = xdata[count];
|
int lcount = xdata[count];
|
||||||
|
|
||||||
// calculated values
|
if (lcount) {
|
||||||
QVector<double> xtrend(lcount);
|
// calculated values
|
||||||
QVector<double> btrend(lcount);
|
QVector<double> xtrend(lcount);
|
||||||
QVector<double> ytrend(lcount);
|
QVector<double> btrend(lcount);
|
||||||
|
QVector<double> ytrend(lcount);
|
||||||
|
|
||||||
// initialise to same
|
// initialise to same
|
||||||
ytrend.fill(0);
|
ytrend.fill(0);
|
||||||
btrend.fill(0);
|
btrend.fill(0);
|
||||||
|
|
||||||
ytrend[0] = ydata[0];
|
ytrend[0] = ydata[0];
|
||||||
xtrend[0] = 0;
|
xtrend[0] = 0;
|
||||||
|
|
||||||
for (int n=1,i=1; i<= lcount; i++) {
|
for (int n=1,i=1; i<= lcount && i<xdata.size(); i++) {
|
||||||
|
|
||||||
// fill in gaps (and check bounds as we go too)
|
// fill in gaps (and check bounds as we go too)
|
||||||
while (n<=xdata[i] && n<lcount) {
|
while (n<=xdata[i] && n<lcount) {
|
||||||
ytrend[n] = alpha * ydata[i] + ( 1 - alpha )*( ytrend[n-1] + btrend[n-1] );
|
ytrend[n] = alpha * ydata[i] + ( 1 - alpha )*( ytrend[n-1] + btrend[n-1] );
|
||||||
btrend[n] = beta * ( ytrend[n] - ytrend[n-1] ) + ( 1 - beta ) * btrend[n-1];
|
btrend[n] = beta * ( ytrend[n] - ytrend[n-1] ) + ( 1 - beta ) * btrend[n-1];
|
||||||
xtrend[n] = n+1;
|
xtrend[n] = n+1;
|
||||||
n++;
|
n++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// point 2 is at far right of chart, not the last point
|
||||||
|
// since we may be forecasting...
|
||||||
|
trend->setSamples(xtrend.data(),ytrend.data(), xtrend.count());
|
||||||
|
|
||||||
|
trend->attach(this);
|
||||||
|
trend->setItemAttribute(QwtPlotItem::Legend, false);
|
||||||
|
curves.insert(trendSymbol, trend);
|
||||||
}
|
}
|
||||||
|
|
||||||
// point 2 is at far right of chart, not the last point
|
|
||||||
// since we may be forecasting...
|
|
||||||
trend->setSamples(xtrend.data(),ytrend.data(), xtrend.count());
|
|
||||||
|
|
||||||
trend->attach(this);
|
|
||||||
trend->setItemAttribute(QwtPlotItem::Legend, false);
|
|
||||||
curves.insert(trendSymbol, trend);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user