2017-11-26 18:54:03 +01:00
|
|
|
#include "data/data.h"
|
2017-09-24 19:54:13 +02:00
|
|
|
#include "powergraphitem.h"
|
2016-11-06 03:28:08 +01:00
|
|
|
#include "powergraph.h"
|
|
|
|
|
|
|
|
|
|
|
|
PowerGraph::PowerGraph(QWidget *parent) : GraphTab(parent)
|
|
|
|
{
|
|
|
|
_showTracks = true;
|
|
|
|
|
|
|
|
GraphView::setYUnits(tr("W"));
|
|
|
|
setYLabel(tr("Power"));
|
|
|
|
|
|
|
|
setSliderPrecision(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PowerGraph::setInfo()
|
|
|
|
{
|
|
|
|
if (_showTracks) {
|
|
|
|
GraphView::addInfo(tr("Average"), QString::number(avg() * yScale()
|
|
|
|
+ yOffset(), 'f', 1) + UNIT_SPACE + yUnits());
|
|
|
|
GraphView::addInfo(tr("Maximum"), QString::number(max() * yScale()
|
|
|
|
+ yOffset(), 'f', 1) + UNIT_SPACE + yUnits());
|
|
|
|
} else
|
|
|
|
clearInfo();
|
|
|
|
}
|
|
|
|
|
2018-05-04 19:36:37 +02:00
|
|
|
QList<GraphItem*> PowerGraph::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++) {
|
|
|
|
const Graph &graph = data.tracks().at(i)->power();
|
|
|
|
|
|
|
|
if (graph.size() < 2) {
|
|
|
|
skipColor();
|
2018-05-04 19:36:37 +02:00
|
|
|
graphs.append(0);
|
|
|
|
} else {
|
|
|
|
PowerGraphItem *gi = new PowerGraphItem(graph, _graphType);
|
|
|
|
GraphView::addGraph(gi);
|
|
|
|
_avg.append(QPointF(data.tracks().at(i)->distance(), gi->avg()));
|
|
|
|
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
|
|
|
|
|
|
|
setInfo();
|
|
|
|
redraw();
|
2018-05-04 19:36:37 +02:00
|
|
|
|
|
|
|
return graphs;
|
2016-11-06 03:28:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
qreal PowerGraph::avg() const
|
|
|
|
{
|
|
|
|
qreal sum = 0, w = 0;
|
|
|
|
QList<QPointF>::const_iterator it;
|
|
|
|
|
|
|
|
for (it = _avg.begin(); it != _avg.end(); it++) {
|
|
|
|
sum += it->y() * it->x();
|
|
|
|
w += it->x();
|
|
|
|
}
|
|
|
|
|
|
|
|
return (sum / w);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PowerGraph::clear()
|
|
|
|
{
|
|
|
|
_avg.clear();
|
|
|
|
|
|
|
|
GraphView::clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PowerGraph::showTracks(bool show)
|
|
|
|
{
|
|
|
|
_showTracks = show;
|
|
|
|
|
|
|
|
showGraph(show);
|
|
|
|
setInfo();
|
|
|
|
|
|
|
|
redraw();
|
|
|
|
}
|