Skip to content

Commit

Permalink
CP plot show ride as power index
Browse files Browse the repository at this point in the history
.. similar to showing as a percent of athlete best, this
   scales the ride mmp to percent of the average athlete.
  • Loading branch information
liversedge committed Feb 3, 2019
1 parent ba8946d commit 8836252
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 7 deletions.
51 changes: 44 additions & 7 deletions src/Charts/CPPlot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ CPPlot::CPPlot(CriticalPowerWindow *parent, Context *context, bool rangemode) :
rideSeries(RideFile::watts),
isFiltered(false), shadeMode(2),
shadeIntervals(true), rangemode(rangemode),
showTest(true), showBest(true), filterBest(false), showPercent(false), showHeat(false), showPP(false), showHeatByDate(false), showDelta(false), showDeltaPercent(false),
showTest(true), showBest(true), filterBest(false), showPowerIndex(false), showPercent(false), showHeat(false), showPP(false), showHeatByDate(false), showDelta(false), showDeltaPercent(false),
plotType(0),
xAxisLinearOnSpeed(true),

Expand Down Expand Up @@ -673,7 +673,7 @@ CPPlot::plotModel()
heatCurve->attach(this);
}

setAxisVisible(yRight, showHeat || (showPercent && rideCurve));
setAxisVisible(yRight, showHeat || ((showPowerIndex||showPercent) && rideCurve));

// setAxisVisible(yRight, showHeat || showPercent);

Expand Down Expand Up @@ -1922,6 +1922,30 @@ CPPlot::plotRide(RideItem *rideItem)
if (showHeat) setAxisTitle(yRight, tr("Percent of Best / Heat Activities"));
else setAxisTitle(yRight, tr("Percent of Best"));

} else if (showPowerIndex && bestsCache && (rideSeries == RideFile::wattsKg || rideSeries == RideFile::watts)) {

// plot as power index if its a power series
QVector<double> samples(timeArray.size());

// power index ify from the cache and always use watts regardless
for(int i=0; i <samples.size() && i < rideItem->fileCache()->meanMaxArray(RideFile::watts).size() &&
i <bestsCache->meanMaxArray(rideSeries).size(); i++) {

samples[i] = powerIndex(rideItem->fileCache()->meanMaxArray(rideSeries)[i], i+1);
}
rideCurve->setSamples(timeArray.data() + 1, samples.data() + 1,
maxNonZero > 0 ? maxNonZero-1 : 0);

// did we get over 100% .. because if so
// we need to set the maxY on the RHS to reflect that
int max = rideCurve->maxYValue();
if (max < 1) max = 1;
else max = max * 1.05f;
setAxisScale(yRight, 0, max); // always 100

// set the right titles in case both Heat and Percent of best is show
setAxisTitle(yRight, tr("Power Index"));

} else {

// JUST A NORMAL CURVE
Expand All @@ -1936,8 +1960,8 @@ CPPlot::plotRide(RideItem *rideItem)

// which axis should it be on?
// and also make sure its visible
rideCurve->setYAxis(showPercent ? yRight : yLeft);
setAxisVisible(yRight, showPercent || showHeat);
rideCurve->setYAxis((showPercent||showPowerIndex) ? yRight : yLeft);
setAxisVisible(yRight, showPercent || showPowerIndex || showHeat);
rideCurve->attach(this);

zoomer->setZoomBase(false);
Expand Down Expand Up @@ -2125,10 +2149,13 @@ CPPlot::pointHover(QwtPlotCurve *curve, int index)
} else {

// eg: "### watts"
units2 = tr("%1 %2").arg(yvalue, 0, 'f', RideFile::decimalsFor(rideSeries))
if (showPercent) units2 = tr("%1 Percent").arg(yvalue, 0, 'f', RideFile::decimalsFor(rideSeries));
else if (showPowerIndex) units2 = tr("%1 Power Index").arg(yvalue, 0, 'f', RideFile::decimalsFor(rideSeries));
else units2 = tr("%1 %2").arg(yvalue, 0, 'f', RideFile::decimalsFor(rideSeries))
.arg(RideFile::unitName(rideSeries, context));
}


#if 0
// for the current ride curve, add a percent of rider's actual best.
if (!showPercent && curve == rideCurve && index >= 0 && getBests().count() > index) {

Expand All @@ -2140,7 +2167,8 @@ CPPlot::pointHover(QwtPlotCurve *curve, int index)
.arg((yvalue *100)/ bestY, 0, 'f', 0)
.arg(tr("Percent of Best"));
}
}
}
#endif


// for speed series add pace with units according to settings
Expand Down Expand Up @@ -2255,6 +2283,14 @@ CPPlot::setShowHeat(bool x)
clearCurves();
}

void
CPPlot::setShowPowerIndex(bool x)
{
showPowerIndex = x;
showPercent = showPowerIndex ? false : showPercent;
clearCurves();
}

void
CPPlot::setShowPP(bool x)
{
Expand Down Expand Up @@ -2294,6 +2330,7 @@ void
CPPlot::setShowPercent(bool x)
{
showPercent = x;
showPowerIndex = showPercent ? false : showPowerIndex;
}

void
Expand Down
2 changes: 2 additions & 0 deletions src/Charts/CPPlot.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class CPPlot : public QwtPlot
void setRide(RideItem *rideItem);
void setDateRange(const QDate &start, const QDate &end, bool stale=false);
void setShowPercent(bool x);
void setShowPowerIndex(bool x);
void setShowTest(bool x);
void setShowBest(bool x);
void setFilterBest(bool x);
Expand Down Expand Up @@ -175,6 +176,7 @@ class CPPlot : public QwtPlot
bool showTest;
bool showBest;
bool filterBest;
bool showPowerIndex;
bool showPercent;
bool showHeat;
bool showEffort;
Expand Down
18 changes: 18 additions & 0 deletions src/Charts/CriticalPowerWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ CriticalPowerWindow::CriticalPowerWindow(Context *context, bool rangemode) :
QLabel *heaties = new QLabel(tr("Show Sustained Efforts"));
cl->addRow(heaties, showEffortCheck);

showPowerIndexCheck = new QCheckBox(this);
showPowerIndexCheck->setChecked(false); // default off
QLabel *indexify = new QLabel(tr("Show as Power Index"));
cl->addRow(indexify, showPowerIndexCheck);

showPercentCheck = new QCheckBox(this);
showPercentCheck->setChecked(false); // default off
QLabel *percentify = new QLabel(tr("Show as percentage"));
Expand Down Expand Up @@ -561,6 +566,7 @@ CriticalPowerWindow::CriticalPowerWindow(Context *context, bool rangemode) :
connect(rDeltaPercent, SIGNAL(stateChanged(int)), this, SLOT(rDeltaChanged()));
connect(showHeatByDateCheck, SIGNAL(stateChanged(int)), this, SLOT(showHeatByDateChanged(int)));
connect(showPercentCheck, SIGNAL(stateChanged(int)), this, SLOT(showPercentChanged(int)));
connect(showPowerIndexCheck, SIGNAL(stateChanged(int)), this, SLOT(showPowerIndexChanged(int)));
connect(showTestCheck, SIGNAL(stateChanged(int)), this, SLOT(showTestChanged(int)));
connect(showBestCheck, SIGNAL(stateChanged(int)), this, SLOT(showBestChanged(int)));
connect(filterBestCheck, SIGNAL(stateChanged(int)), this, SLOT(filterBestChanged(int)));
Expand Down Expand Up @@ -1840,6 +1846,7 @@ CriticalPowerWindow::showBestChanged(int state)
void
CriticalPowerWindow::showPercentChanged(int state)
{
if (state) showPowerIndexCheck->setChecked(false);
cpPlot->setShowPercent(state);
rPercent->setChecked(state);

Expand All @@ -1848,6 +1855,17 @@ CriticalPowerWindow::showPercentChanged(int state)
else cpPlot->setRide(currentRide);
}

void
CriticalPowerWindow::showPowerIndexChanged(int state)
{
if (state) showPercentCheck->setChecked(false);
cpPlot->setShowPowerIndex(state);

// redraw
if (rangemode) dateRangeChanged(DateRange());
else cpPlot->setRide(currentRide);
}

void
CriticalPowerWindow::rPercentChanged(int check)
{
Expand Down
6 changes: 6 additions & 0 deletions src/Charts/CriticalPowerWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class CriticalPowerWindow : public GcChartWindow
Q_PROPERTY(bool showTest READ showTest WRITE setShowTest USER true)
Q_PROPERTY(bool filterBest READ filterBest WRITE setFilterBest USER true)
Q_PROPERTY(bool showPercent READ showPercent WRITE setShowPercent USER true)
Q_PROPERTY(bool showPowerIndex READ showPowerIndex WRITE setShowPowerIndex USER true)
Q_PROPERTY(bool showGrid READ showGrid WRITE setShowGrid USER true)

// for retro compatibility
Expand Down Expand Up @@ -224,6 +225,9 @@ class CriticalPowerWindow : public GcChartWindow
bool showTest() { return showTestCheck->isChecked(); }
void setShowTest(bool x) { return showTestCheck->setChecked(x); }

bool showPowerIndex() { return showPowerIndexCheck->isChecked(); }
void setShowPowerIndex(bool x) { return showPowerIndexCheck->setChecked(x); }

bool showPercent() { return showPercentCheck->isChecked(); }
void setShowPercent(bool x) { return showPercentCheck->setChecked(x); }

Expand All @@ -246,6 +250,7 @@ class CriticalPowerWindow : public GcChartWindow
void showCSLinearChanged(int state);
void showHeatByDateChanged(int check);
void showPercentChanged(int check);
void showPowerIndexChanged(int check);
void showBestChanged(int check);
void showTestChanged(int check);
void filterBestChanged(int check);
Expand Down Expand Up @@ -319,6 +324,7 @@ class CriticalPowerWindow : public GcChartWindow
QCheckBox *showHeatCheck;
QCheckBox *showHeatByDateCheck;
QCheckBox *showPercentCheck;
QCheckBox *showPowerIndexCheck;
QCheckBox *showBestCheck;
QCheckBox *showTestCheck;
QCheckBox *filterBestCheck;
Expand Down

0 comments on commit 8836252

Please sign in to comment.