From 486c4d536c78f659ccf72d07ce7df89fb892bca2 Mon Sep 17 00:00:00 2001 From: Mark Liversedge Date: Sun, 28 Dec 2014 13:34:55 +0000 Subject: [PATCH] Selected Intervals Summary .. in sidebar, we summarise for all the selected intervals. .. we take into account if they overlap, so two intervals of 10 and 5 mins where the 5 min interval is wholly contained within the 10 minute interval will be summarised as 10 minutes not 15 minutes duration. --- src/IntervalSummaryWindow.cpp | 73 +++++++++++++++++++++++++++++++++-- src/IntervalSummaryWindow.h | 6 ++- 2 files changed, 74 insertions(+), 5 deletions(-) diff --git a/src/IntervalSummaryWindow.cpp b/src/IntervalSummaryWindow.cpp index 912727582..a3d5ed58a 100644 --- a/src/IntervalSummaryWindow.cpp +++ b/src/IntervalSummaryWindow.cpp @@ -69,6 +69,8 @@ void IntervalSummaryWindow::intervalSelected() return; } + // summary of currently selected + QList list; QString html = GCColor::css(); html += ""; if (context->athlete->allIntervalItems() != NULL) { @@ -76,11 +78,16 @@ void IntervalSummaryWindow::intervalSelected() IntervalItem *current = dynamic_cast(context->athlete->allIntervalItems()->child(i)); if (current != NULL) { if (current->isSelected()) { + list << current; calcInterval(current, html); } } } } + + // summary of all intervals selected + if (list.count()>1) calcInterval(list, html); + if (html == GCColor::css()+"") { html += "" + tr("select an interval for summary info") + ""; } @@ -112,11 +119,63 @@ IntervalSummaryWindow::intervalHover(RideFileInterval x) return; } -void IntervalSummaryWindow::calcInterval(IntervalItem* interval, QString& html) +static bool contains(const RideFile*ride, QList intervals, int index) +{ + foreach(IntervalItem *item, intervals) { + int start = ride->timeIndex(item->start); + int end = ride->timeIndex(item->stop); + + if (index >= start && index <= end) return true; + } + return false; +} + +void IntervalSummaryWindow::calcInterval(QList intervals, QString &html) { const RideFile* ride = context->ride ? context->ride->ride() : NULL; - bool metricUnits = context->athlete->useMetricUnits; + RideFile f(const_cast(ride)); + + // for concatenating intervals + RideFilePoint *last = NULL; + double timeOff=0; + double distOff=0; + + for (int i = 0; i < ride->dataPoints().count(); ++i) { + + // append points for selected intervals + const RideFilePoint *p = ride->dataPoints()[i]; + if (contains(ride, intervals, i)) { + + f.appendPoint(p->secs-timeOff, p->cad, p->hr, p->km-distOff, p->kph, p->nm, + p->watts, p->alt, p->lon, p->lat, p->headwind, p->slope, p->temp, p->lrbalance, + p->lte, p->rte, p->lps, p->rps, p->smo2, p->thb, + p->rvert, p->rcad, p->rcontact, 0); + + // derived data + last = f.dataPoints().last(); + last->np = p->np; + last->xp = p->xp; + last->apower = p->apower; + + } else { + + if (last) { + timeOff = p->secs - last->secs; + distOff = p->km - last->km; + } else { + timeOff = p->secs; + distOff = p->km; + } + } + } + + summary(f, QString("%1 intervals").arg(intervals.count()), html); +} + +void IntervalSummaryWindow::calcInterval(IntervalItem* interval, QString& html) +{ + const RideFile* ride = context->ride ? context->ride->ride() : NULL; RideFile f(const_cast(ride)); int start = ride->timeIndex(interval->start); @@ -134,6 +193,14 @@ void IntervalSummaryWindow::calcInterval(IntervalItem* interval, QString& html) l->xp = p->xp; l->apower = p->apower; } + + summary(f, interval->text(0), html); +} + +void IntervalSummaryWindow::summary(RideFile &f, QString name, QString &html) +{ + bool metricUnits = context->athlete->useMetricUnits; + if (f.dataPoints().size() == 0) { // Interval empty, do not compute any metrics html += "" + tr("empty interval") + ""; @@ -149,7 +216,7 @@ void IntervalSummaryWindow::calcInterval(IntervalItem* interval, QString& html) QHash metrics = RideMetric::computeMetrics(context, &f, context->athlete->zones(), context->athlete->hrZones(), intervalMetrics); - html += "" + interval->text(0) + ""; + html += "" + name + ""; html += " intervals, QString& html); // summarise a list + void calcInterval(IntervalItem* interval, QString& html); // summarise a single interval + void calcInterval(RideFileInterval interval, QString& html); // summarise a single interval + void summary(RideFile &f, QString title, QString &html); Context *context; };