2018-09-09 18:46:43 +02:00
|
|
|
#include <QLocale>
|
2017-11-26 18:54:03 +01:00
|
|
|
#include "data/data.h"
|
2017-09-24 19:54:13 +02:00
|
|
|
#include "cadencegraphitem.h"
|
2016-11-06 03:28:08 +01:00
|
|
|
#include "cadencegraph.h"
|
|
|
|
|
|
|
|
|
|
|
|
CadenceGraph::CadenceGraph(QWidget *parent) : GraphTab(parent)
|
|
|
|
{
|
|
|
|
_showTracks = true;
|
|
|
|
|
2018-09-09 15:27:44 +02:00
|
|
|
GraphView::setYUnits(tr("rpm"));
|
2016-11-06 03:28:08 +01:00
|
|
|
setYLabel(tr("Cadence"));
|
|
|
|
|
|
|
|
setSliderPrecision(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CadenceGraph::setInfo()
|
|
|
|
{
|
|
|
|
if (_showTracks) {
|
2018-09-09 18:46:43 +02:00
|
|
|
QLocale l(QLocale::system());
|
|
|
|
|
|
|
|
GraphView::addInfo(tr("Average"), l.toString(avg() * yScale()
|
2016-11-06 03:28:08 +01:00
|
|
|
+ yOffset(), 'f', 1) + UNIT_SPACE + yUnits());
|
2018-09-09 18:46:43 +02:00
|
|
|
GraphView::addInfo(tr("Maximum"), l.toString(max() * yScale()
|
2016-11-06 03:28:08 +01:00
|
|
|
+ yOffset(), 'f', 1) + UNIT_SPACE + yUnits());
|
|
|
|
} else
|
|
|
|
clearInfo();
|
|
|
|
}
|
|
|
|
|
2018-05-04 19:36:37 +02:00
|
|
|
QList<GraphItem*> CadenceGraph::loadData(const Data &data)
|
2016-11-06 03:28:08 +01:00
|
|
|
{
|
2018-05-04 19:36:37 +02:00
|
|
|
QList<GraphItem*> graphs;
|
|
|
|
|
2016-11-06 03:28:08 +01:00
|
|
|
for (int i = 0; i < data.tracks().count(); i++) {
|
2019-01-31 01:46:53 +01:00
|
|
|
const Track &track = data.tracks().at(i);
|
|
|
|
const Graph &graph = track.cadence();
|
2016-11-06 03:28:08 +01:00
|
|
|
|
2019-01-31 01:46:53 +01:00
|
|
|
if (!graph.isValid()) {
|
2016-11-06 03:28:08 +01:00
|
|
|
skipColor();
|
2018-05-04 19:36:37 +02:00
|
|
|
graphs.append(0);
|
|
|
|
} else {
|
|
|
|
CadenceGraphItem *gi = new CadenceGraphItem(graph, _graphType);
|
|
|
|
GraphView::addGraph(gi);
|
2019-01-31 01:46:53 +01:00
|
|
|
_avg.append(QPointF(track.distance(), gi->avg()));
|
2018-05-04 19:36:37 +02:00
|
|
|
graphs.append(gi);
|
2016-11-06 03:28:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-04 19:36:37 +02:00
|
|
|
for (int i = 0; i < data.routes().count(); i++) {
|
2016-11-06 03:28:08 +01:00
|
|
|
skipColor();
|
2018-05-04 19:36:37 +02:00
|
|
|
graphs.append(0);
|
|
|
|
}
|
2016-11-06 03:28:08 +01:00
|
|
|
|
2019-01-31 01:46:53 +01:00
|
|
|
for (int i = 0; i < data.areas().count(); i++)
|
|
|
|
skipColor();
|
|
|
|
|
2016-11-06 03:28:08 +01:00
|
|
|
setInfo();
|
|
|
|
redraw();
|
2018-05-04 19:36:37 +02:00
|
|
|
|
|
|
|
return graphs;
|
2016-11-06 03:28:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
qreal CadenceGraph::avg() const
|
|
|
|
{
|
|
|
|
qreal sum = 0, w = 0;
|
|
|
|
|
2019-03-15 19:43:17 +01:00
|
|
|
for (int i = 0; i < _avg.size(); i++) {
|
|
|
|
const QPointF &p = _avg.at(i);
|
|
|
|
sum += p.y() * p.x();
|
|
|
|
w += p.x();
|
2016-11-06 03:28:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return (sum / w);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CadenceGraph::clear()
|
|
|
|
{
|
|
|
|
_avg.clear();
|
|
|
|
|
2019-03-05 22:34:50 +01:00
|
|
|
GraphTab::clear();
|
2016-11-06 03:28:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CadenceGraph::showTracks(bool show)
|
|
|
|
{
|
|
|
|
_showTracks = show;
|
|
|
|
|
|
|
|
showGraph(show);
|
|
|
|
setInfo();
|
|
|
|
|
|
|
|
redraw();
|
|
|
|
}
|