Cache StressCalculator in LTMPlot

A bit of a compromise since really we should move the
stress calculators to the Athlete class and reuse when
no filtering is applied.

This code fix just means the SC is not recalculated for
each of the individual curves (LTS, STS etc) and pretty
much halves (or better) the time taken to refresh the
LTMPlot.

For those with very few rides (<500) this isn't much of
an issue, but for some with lots (2000 or more) it can
be quite tedious.
This commit is contained in:
Mark Liversedge
2013-12-06 19:32:41 +00:00
parent b960aaeddd
commit 4d6b78f222
2 changed files with 56 additions and 8 deletions

View File

@@ -63,6 +63,7 @@ LTMPlot::LTMPlot(LTMWindow *parent, Context *context) :
grid->attach(this);
settings = NULL;
cogganPMC = skibaPMC = NULL; // cache when replotting a PMC
configUpdate(); // set basic colors
@@ -100,6 +101,15 @@ LTMPlot::setAxisTitle(int axis, QString label)
void
LTMPlot::setData(LTMSettings *set)
{
QTime timer;
timer.start();
//qDebug()<<"Starting.."<<timer.elapsed();
// wipe away last cached stress calculator
if (cogganPMC) { delete cogganPMC; cogganPMC=NULL; }
if (skibaPMC) { delete cogganPMC; cogganPMC=NULL; }
settings = set;
// For each metric in chart, translate units and name if default uname
@@ -176,6 +186,8 @@ LTMPlot::setData(LTMSettings *set)
return;
}
//qDebug()<<"Wiped previous.."<<timer.elapsed();
// count the bars since we format them side by side and need
// to now how to offset them from each other
// unset stacking if not a bar chart too since we don't support
@@ -229,6 +241,8 @@ LTMPlot::setData(LTMSettings *set)
}
}
//qDebug()<<"Created curve data.."<<timer.elapsed();
// setup the curves
double width = appsettings->value(this, GC_LINEWIDTH, 2.0).toDouble();
bool donestack = false;
@@ -391,6 +405,7 @@ LTMPlot::setData(LTMSettings *set)
} // end of reverse for stacked plots
//qDebug()<<"First plotting iteration.."<<timer.elapsed();
// do all curves excepts stacks in order
// we skip stacked entries because they
@@ -409,6 +424,8 @@ LTMPlot::setData(LTMSettings *set)
else
createTODCurveData(settings, metricDetail, xdata, ydata, count);
//qDebug()<<"Create curve data.."<<timer.elapsed();
// Create a curve
QwtPlotCurve *current = new QwtPlotCurve(metricDetail.uname);
if (metricDetail.type == METRIC_BEST)
@@ -709,6 +726,8 @@ LTMPlot::setData(LTMSettings *set)
current->setData(xdata.data(),ydata.data(), count + 1);
current->setBaseline(metricDetail.baseline);
//qDebug()<<"Set Curve Data.."<<timer.elapsed();
// update min/max Y values for the chosen axis
if (current->maxYValue() > maxY[axisid]) maxY[axisid] = current->maxYValue();
if (current->minYValue() < minY[axisid]) minY[axisid] = current->minYValue();
@@ -717,6 +736,9 @@ LTMPlot::setData(LTMSettings *set)
}
//qDebug()<<"Second plotting iteration.."<<timer.elapsed();
if (settings->groupBy != LTM_TOD) {
// make start date always fall on a Monday
@@ -774,8 +796,13 @@ LTMPlot::setData(LTMSettings *set)
if (settings->groupBy != LTM_TOD)
refreshMarkers(settings->start.date(), settings->end.date(), settings->groupBy);
//qDebug()<<"Final tidy.."<<timer.elapsed();
// plot
replot();
//qDebug()<<"Replot and done.."<<timer.elapsed();
}
void
@@ -981,14 +1008,23 @@ LTMPlot::createPMCCurveData(LTMSettings *settings, MetricDetail metricDetail,
// create the Stress Calculation List
// FOR ALL RIDE FILES
StressCalculator *sc = new StressCalculator(
context->athlete->cyclist,
settings->start,
settings->end,
(appsettings->value(this, GC_STS_DAYS,7)).toInt(),
(appsettings->value(this, GC_LTS_DAYS,42)).toInt());
StressCalculator *sc ;
sc->calculateStress(context, context->athlete->home.absolutePath(), scoreType, settings->ltmTool->isFiltered(), settings->ltmTool->filters());
if (scoreType == "coggan_tss" && cogganPMC) {
sc = cogganPMC;
} else if (scoreType == "skiba_bike_score" && skibaPMC) {
sc = skibaPMC;
} else {
sc = new StressCalculator(
context->athlete->cyclist,
settings->start,
settings->end,
(appsettings->value(this, GC_STS_DAYS,7)).toInt(),
(appsettings->value(this, GC_LTS_DAYS,42)).toInt());
sc->calculateStress(context, context->athlete->home.absolutePath(), scoreType, settings->ltmTool->isFiltered(), settings->ltmTool->filters());
}
// pick out any data that is in the date range selected
// convert to SummaryMetric Format used on the plot
@@ -1037,7 +1073,14 @@ LTMPlot::createPMCCurveData(LTMSettings *settings, MetricDetail metricDetail,
customData << add;
}
delete sc;
if (scoreType == "coggan_tss") {
cogganPMC = sc;
} else if (scoreType == "skiba_bike_score") {
skibaPMC = sc;
} else {
delete sc;
}
}
int

View File

@@ -37,6 +37,7 @@ class LTMPlotBackground;
class LTMWindow;
class LTMPlotZoneLabel;
class LTMScaleDraw;
class StressCalculator;
class LTMPlot : public QwtPlot
{
@@ -97,6 +98,10 @@ class LTMPlot : public QwtPlot
int chooseYAxis(QString);
void refreshZoneLabels(int);
void refreshMarkers(QDate from, QDate to, int groupby);
// remember the coggan or skiba stress calculators
// so it isn't recalculated for each data series!
StressCalculator *cogganPMC, *skibaPMC;
};
// Produce Labels for X-Axis