From 9da6488d537fd53d7d423f5dc4d8ec6d8b417c6d Mon Sep 17 00:00:00 2001 From: Mark Liversedge Date: Wed, 20 Jan 2010 14:47:03 +0000 Subject: [PATCH] True Interval Patch, second part The best interval dialog rounded intervals to the nearest second due to a casting of a double to int. This was introduced by Mark L during the intervals code patch and is an error. All the plots have now been adjusted to correctly determine if a ride point is within an interval. Related cropping and binning issues in 3d plot an Histogram plot have also been corrected. fixes #15 --- src/BestIntervalDialog.cpp | 4 ++-- src/ModelPlot.cpp | 17 +++++++++-------- src/PfPvPlot.cpp | 3 ++- src/PowerHist.cpp | 12 +++++++----- src/PowerHist.h | 2 +- src/WkoRideFile.cpp | 2 +- 6 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/BestIntervalDialog.cpp b/src/BestIntervalDialog.cpp index 461c7d5be..967aae385 100644 --- a/src/BestIntervalDialog.cpp +++ b/src/BestIntervalDialog.cpp @@ -229,12 +229,12 @@ BestIntervalDialog::findClicked() resultsTable->setItem(row, 2, n); // hidden columns - start, stop - QString strt = QString("%1").arg((int) interval.start); // can't use secs as it gets modified + QString strt = QString("%1").arg(interval.start); // can't use secs as it gets modified QTableWidgetItem *st = new QTableWidgetItem; st->setText(strt); resultsTable->setItem(row, 3, st); - QString stp = QString("%1").arg((int)(interval.start + x)); + QString stp = QString("%1").arg(interval.start + x); QTableWidgetItem *sp = new QTableWidgetItem; sp->setText(stp); resultsTable->setItem(row, 4, sp); diff --git a/src/ModelPlot.cpp b/src/ModelPlot.cpp index c93ff3538..8b5dc9384 100644 --- a/src/ModelPlot.cpp +++ b/src/ModelPlot.cpp @@ -358,14 +358,14 @@ ModelDataProvider::ModelDataProvider (BasicModelPlot &plot, ModelSettings *setti foreach(const RideFilePoint *point, settings->ride->ride()->dataPoints()) { // get x and z bin values - round to nearest bin - double dx = pointType(point, settings->x)/settings->xbin; - int binx = settings->xbin * Qwt3D::round(dx); + double dx = pointType(point, settings->x); + int binx = settings->xbin * floor(dx / settings->xbin); - double dy = pointType(point, settings->y)/settings->ybin; - int biny = settings->ybin * Qwt3D::round(dy); + double dy = pointType(point, settings->y); + int biny = settings->ybin * floor(dy / settings->ybin); // ignore zero points - if (settings->ignore && (binx==0 || biny==0)) continue; + if (settings->ignore && (dx==0 || dy==0)) continue; // get z value double zed=0; @@ -431,8 +431,8 @@ ModelDataProvider::ModelDataProvider (BasicModelPlot &plot, ModelSettings *setti // filter for interval for(int i=0; iintervals.count(); i++) { IntervalItem *curr = settings->intervals.at(i); - if (point->secs >= curr->start && point->secs <= curr->stop) { - + if ((point->secs + settings->ride->ride()->recIntSecs()) > curr->start + && point->secs < curr->stop) { // update colors int colcount = settings->colorProvider->num.value(lookup,0.0); double currentcol = settings->colorProvider->color.value(lookup, 0.0); @@ -576,7 +576,8 @@ ModelDataProvider::ModelDataProvider (BasicModelPlot &plot, ModelSettings *setti z = iz.value(); if (first == true) { - minz = maxz = iz.value(); + minz = 0; + maxz = iz.value(); } else { if (z > maxz) maxz = z; if (z < minz) minz = z; diff --git a/src/PfPvPlot.cpp b/src/PfPvPlot.cpp index 4e5134b98..dbde9994b 100644 --- a/src/PfPvPlot.cpp +++ b/src/PfPvPlot.cpp @@ -430,7 +430,8 @@ PfPvPlot::showIntervals(RideItem *_rideItem) IntervalItem *current = dynamic_cast(mainWindow->allIntervalItems()->child(t)); if ((current != NULL) && current->isSelected()) { ++high; - if (p1->secs>=current->start && p1->secs<=current->stop) { + if (p1->secs+ride->recIntSecs() > current->start + && p1->secs< current->stop) { if (mergeIntervals()) dataSetInterval[0].insert(std::make_pair(aepf, cpv)); else diff --git a/src/PowerHist.cpp b/src/PowerHist.cpp index c7c0e804c..638c3f96d 100644 --- a/src/PowerHist.cpp +++ b/src/PowerHist.cpp @@ -362,7 +362,9 @@ PowerHist::recalc() if (!array) return; - int count = int(ceil((arrayLength - 1) / binw)); + // we add a bin on the end since the last "incomplete" bin + // will be dropped otherwise + int count = int(ceil((arrayLength - 1) / binw))+1; // allocate space for data, plus beginning and ending point QVector parameterValue(count+2); @@ -377,7 +379,7 @@ PowerHist::recalc() parameterValue[i] = high * delta; totalTime[i] = 1e-9; // nonzero to accomodate log plot totalTimeSelected[i] = 1e-9; // nonzero to accomodate log plot - while (low < high) { + while (low < high && lowlow) totalTimeSelected[i] += dt * (*selectedArray)[low]; totalTime[i] += dt * (*array)[low++]; @@ -436,7 +438,7 @@ PowerHist::setData(RideItem *_rideItem) double speed_factor = (useMetricUnits ? 1.0 : 0.62137119); foreach(const RideFilePoint *p1, ride->dataPoints()) { - bool selected = isSelected(p1); + bool selected = isSelected(p1, ride->recIntSecs()); int wattsIndex = int(floor(p1->watts / wattsDelta)); if (wattsIndex >= 0 && wattsIndex < maxSize) { @@ -706,12 +708,12 @@ bool PowerHist::shadeZones() const ); } -bool PowerHist::isSelected(const RideFilePoint *p) { +bool PowerHist::isSelected(const RideFilePoint *p, double sample) { if (mainWindow->allIntervalItems() != NULL) { for (int i=0; iallIntervalItems()->childCount(); i++) { IntervalItem *current = dynamic_cast(mainWindow->allIntervalItems()->child(i)); if (current != NULL) { - if (current->isSelected() && p->secs>=current->start && p->secs<=current->stop) { + if (current->isSelected() && p->secs+sample>current->start && p->secsstop) { return true; } } diff --git a/src/PowerHist.h b/src/PowerHist.h index c8f3e5f22..5ab5abff7 100644 --- a/src/PowerHist.h +++ b/src/PowerHist.h @@ -131,7 +131,7 @@ class PowerHist : public QwtPlot static const int cadDigits = 0; void setParameterAxisTitle(); - bool isSelected(const RideFilePoint *p); + bool isSelected(const RideFilePoint *p, double); bool useMetricUnits; // whether metric units are used (or imperial) }; diff --git a/src/WkoRideFile.cpp b/src/WkoRideFile.cpp index db9af4d86..13d33a57a 100644 --- a/src/WkoRideFile.cpp +++ b/src/WkoRideFile.cpp @@ -131,7 +131,7 @@ RideFile *WkoFileReader::openRideFile(QFile &file, QStringList &errors) const continue; // out of bounds if (references.at(i)->stop < datapoints.count()) - add.stop = datapoints.at(references.at(i)->stop)->secs; + add.stop = datapoints.at(references.at(i)->stop)->secs + rideFile->recIntSecs()-.001; else continue; // out of bounds