Skip to content

Commit

Permalink
Use units specified in zone settings for run/swim/default.
Browse files Browse the repository at this point in the history
Using Preferences->Athlete->Zones->Pace Zones for both Run/Swim to override Preferences->General->unit.
Simplify some code with if/else blocks.
Reorganize Tooltip variable argument order to match placement in text.
Still several problems around kph being used in chart y-value despite settings.
Use const when appropriate.
  • Loading branch information
mtbkeith committed Apr 20, 2017
1 parent f29942a commit 0980946
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 51 deletions.
49 changes: 26 additions & 23 deletions src/Charts/AllPlot.cpp
Expand Up @@ -6989,8 +6989,10 @@ AllPlot::pointHover(QwtPlotCurve *curve, int index)
if (index >= 0 && curve != standard->intervalHighlighterCurve &&
curve != standard->intervalHoverCurve && curve->isVisible()) {

int precision = 1; //< default to tens precision

const double xvalue = curve->sample(index).x();
double yvalue = curve->sample(index).y();
double xvalue = curve->sample(index).x();

X = xvalue;

Expand All @@ -7005,37 +7007,38 @@ AllPlot::pointHover(QwtPlotCurve *curve, int index)
// for speed curve add pace with units according to settings
// only when the activity is a run.
QString paceStr;
if (curve->title() == tr("Speed") && rideItem && rideItem->isRun) {
bool metricPace = appsettings->value(this, GC_PACE, true).toBool();
QString paceunit = metricPace ? tr("min/km") : tr("min/mile");
paceStr = tr("\n%1 %2").arg(context->athlete->useMetricUnits ? kphToPace(yvalue, metricPace, false) : mphToPace(yvalue, metricPace, false)).arg(paceunit);
}
if (curve->title() == tr("Speed") && rideItem && rideItem->isSwim) {
bool metricPace = appsettings->value(this, GC_SWIMPACE, true).toBool();
QString paceunit = metricPace ? tr("min/100m") : tr("min/100yd");
paceStr = tr("\n%1 %2").arg(context->athlete->useMetricUnits ? kphToPace(yvalue, metricPace, true) : mphToPace(yvalue, metricPace, true)).arg(paceunit);
}

// need to scale for W' bal
if (curve->title().text().contains("W'"))

if (curve->title() == tr("Speed") && rideItem) {
precision = 2;
if (rideItem->isRun) {
bool metricPace = appsettings->value(this, GC_PACE, true).toBool();
QString paceunit = metricPace ? tr("min/km") : tr("min/mile");
paceStr = tr("\n%1 %2").arg(context->athlete->useMetricUnits ? kphToPace(yvalue, metricPace, false) : mphToPace(yvalue, metricPace, false)).arg(paceunit);
} else if (rideItem->isSwim) {
bool metricPace = appsettings->value(this, GC_SWIMPACE, true).toBool();
QString paceunit = metricPace ? tr("min/100m") : tr("min/100yd");
paceStr = tr("\n%1 %2").arg(context->athlete->useMetricUnits ? kphToPace(yvalue, metricPace, true) : mphToPace(yvalue, metricPace, true)).arg(paceunit);
}
} else if (curve->title() == tr("W'")) {
// need to scale for W' bal
yvalue /= 1000.0f;

// output the tooltip
int precision = 1; //< default to tens precision
if (curve->title().text() == tr("Hb")) {
} else if (curve->title() == tr("Hb")) {
precision = 2;
} else if (curve->title().text() == tr("R-R")) {
} else if (curve->title() == tr("R-R")) {
precision = 3;
} else if (curve->title().text() == tr("Gear Ratio")) {
} else if (curve->title() == tr("Gear Ratio")) {
precision = 2;
}

QString text = QString("%1 %2%5\n%3 %4")
.arg(yvalue, 0, 'f', precision)
// output the tooltip
QString text = QString("%1\n%2 %3%4\n%5 %6")
.arg(this->axisTitle(curve->yAxis()).text())
.arg(yvalue, 0, 'f', precision)
.arg("") // TODO: determine units to describe mph, bpm, rpm, etc.
.arg(paceStr)
.arg(xstring)
.arg(this->axisTitle(curve->xAxis()).text())
.arg(paceStr);
;

// set that text up
tooltip->setText(text);
Expand Down
61 changes: 33 additions & 28 deletions src/Charts/CPPlot.cpp
Expand Up @@ -674,6 +674,7 @@ CPPlot::plotModel()

//CV
cpw->cpTitle->setText(tr("CV"));
// TODO: Should metric instead depend on the swim/run/default unit settings?
cpw->cpValue->setText(kphToString(pdModel->CP()));
cpw->cpRank->setText(zones ? zones->kphToPaceString(pdModel->CP(), metricPace) : "n/a");

Expand Down Expand Up @@ -1695,8 +1696,8 @@ CPPlot::pointHover(QwtPlotCurve *curve, int index)

if (index >= 0) {

double xvalue = curve->sample(index).x();
double yvalue = curve->sample(index).y();
const double xvalue = curve->sample(index).x();
const double yvalue = curve->sample(index).y();
QString text, dateStr, paceStr;
QString currentRidePercentStr;
QString units1;
Expand All @@ -1710,12 +1711,25 @@ CPPlot::pointHover(QwtPlotCurve *curve, int index)
dateStr = date.toString(tr("\nddd, dd MMM yyyy"));
}
}

bool metricPace = true;
if (isSwim) {
metricPace = appsettings->value(this, GC_SWIMPACE, true).toBool();
qDebug() << "swim pacing:" << (metricPace ? "metric":"imperial");
} else if (isRun) {
metricPace = appsettings->value(this, GC_PACE, true).toBool();
qDebug() << "run pacing:" << (metricPace ? "metric":"imperial");
} else {
metricPace = context->athlete->useMetricUnits;
qDebug() << "bike/default pacing:" << (metricPace ? "metric":"imperial");
}

if (criticalSeries == CriticalPowerWindow::veloclinicplot)
if (criticalSeries == CriticalPowerWindow::veloclinicplot) {
units1 = RideFile::unitName(rideSeries, context);
else
} else {
units1 = ""; // time --> no units

}

// no units for Heat Curve
if (curve == heatCurve) {
units2 = tr("%1 %2")
Expand All @@ -1738,14 +1752,9 @@ CPPlot::pointHover(QwtPlotCurve *curve, int index)
}
else if (criticalSeries == CriticalPowerWindow::kph)
{

// yAxis doesn't obey units settings yet, remove when fixed
if (context->athlete->useMetricUnits)
{
if (metricPace) {
units2 = tr("%1 kph").arg(yvalue, 0, 'f', RideFile::decimalsFor(rideSeries));
}
else
{
} else {
units2 = tr("%1 mph").arg(yvalue*MILES_PER_KM, 0, 'f', RideFile::decimalsFor(rideSeries));
}
}
Expand Down Expand Up @@ -1774,40 +1783,36 @@ CPPlot::pointHover(QwtPlotCurve *curve, int index)
if (isRun || isSwim) {
const PaceZones *zones = context->athlete->paceZones(isSwim);
if (zones) {
bool metricPace = appsettings->value(this, zones->paceSetting(), true).toBool();
paceStr = QString("\n%1 %2")
.arg(zones->kphToPaceString(yvalue, metricPace))
.arg(zones->paceUnits(metricPace));
}
}
double km = yvalue*xvalue/60.0; // distance in km

const double km = yvalue*xvalue/60.0; // distance in km
if (isSwim)
{
if (context->athlete->useMetricUnits)
{
if (metricPace) {
paceStr += tr("\n%1 m").arg(1000*km, 0, 'f', 0);
}
else
{
} else {
paceStr += tr("\n%1 yd").arg(1000*km/METERS_PER_YARD, 0, 'f', 0);
}
}
else
{
if (context->athlete->useMetricUnits)
{
if (metricPace) {
paceStr += tr("\n%1 km").arg(km, 0, 'f', 3);
}
else
{
} else {
paceStr += tr("\n%1 mi").arg(MILES_PER_KM*km, 0, 'f', 3);
}
}
}

// output the tooltip
text = QString("%1%2\n%3 %4%5%6")
.arg(criticalSeries == CriticalPowerWindow::veloclinicplot?QString("%1").arg(xvalue, 0, 'f', RideFile::decimalsFor(rideSeries)):interval_to_str(60.0*xvalue))
.arg(criticalSeries == CriticalPowerWindow::veloclinicplot ?
QString("%1").arg(xvalue, 0, 'f', RideFile::decimalsFor(rideSeries))
: interval_to_str(60.0*xvalue))
.arg(units1)
.arg(units2)
.arg(currentRidePercentStr)
Expand Down Expand Up @@ -1841,9 +1846,9 @@ CPPlot::exportBests(QString filename)

// just output for the bests curve
for (size_t i=0; i<bestsCurve->data()->size(); i++) {
double xvalue = bestsCurve->sample(i).x();
double yvalue = bestsCurve->sample(i).y();
double modelvalue = expmodel ? pdModel->y(xvalue) : 0;
const double xvalue = bestsCurve->sample(i).x();
const double yvalue = bestsCurve->sample(i).y();
const double modelvalue = expmodel ? pdModel->y(xvalue) : 0;

int index = xvalue * 60.00f;
QDate date;
Expand Down

0 comments on commit 0980946

Please sign in to comment.