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 "powergraphitem.h"
|
2016-11-06 03:28:08 +01:00
|
|
|
#include "powergraph.h"
|
|
|
|
|
|
|
|
|
|
|
|
PowerGraph::PowerGraph(QWidget *parent) : GraphTab(parent)
|
|
|
|
{
|
2023-02-04 23:59:47 +01:00
|
|
|
_showTracks = false;
|
2016-11-06 03:28:08 +01:00
|
|
|
|
|
|
|
GraphView::setYUnits(tr("W"));
|
|
|
|
setYLabel(tr("Power"));
|
|
|
|
|
|
|
|
setSliderPrecision(1);
|
|
|
|
}
|
|
|
|
|
2019-08-25 10:54:25 +02:00
|
|
|
PowerGraph::~PowerGraph()
|
|
|
|
{
|
|
|
|
qDeleteAll(_tracks);
|
|
|
|
}
|
|
|
|
|
2016-11-06 03:28:08 +01:00
|
|
|
void PowerGraph::setInfo()
|
|
|
|
{
|
|
|
|
if (_showTracks) {
|
2018-09-09 18:46:43 +02:00
|
|
|
QLocale l(QLocale::system());
|
|
|
|
|
2022-05-28 14:05:14 +02:00
|
|
|
#ifdef Q_OS_ANDROID
|
|
|
|
GraphView::addInfo(tr("Avg"), l.toString(avg() * yScale() + yOffset(),
|
|
|
|
'f', 1) + UNIT_SPACE + yUnits());
|
|
|
|
GraphView::addInfo(tr("Max"), l.toString(max() * yScale() + yOffset(),
|
|
|
|
'f', 1) + UNIT_SPACE + yUnits());
|
|
|
|
#else // Q_OS_ANDROID
|
2018-09-09 18:46:43 +02:00
|
|
|
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()
|
2022-05-28 14:05:14 +02:00
|
|
|
+ yOffset(), 'f', 1) + UNIT_SPACE + yUnits());
|
|
|
|
#endif // Q_OS_ANDROID
|
2016-11-06 03:28:08 +01:00
|
|
|
} 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++) {
|
2019-01-31 01:46:53 +01:00
|
|
|
const Track &track = data.tracks().at(i);
|
|
|
|
const Graph &graph = track.power();
|
2016-11-06 03:28:08 +01:00
|
|
|
|
2019-01-31 01:46:53 +01:00
|
|
|
if (!graph.isValid()) {
|
2019-08-25 10:54:25 +02:00
|
|
|
_palette.nextColor();
|
2018-05-04 19:36:37 +02:00
|
|
|
graphs.append(0);
|
|
|
|
} else {
|
2019-08-25 10:54:25 +02:00
|
|
|
PowerGraphItem *gi = new PowerGraphItem(graph, _graphType, _width,
|
|
|
|
_palette.nextColor());
|
|
|
|
|
|
|
|
_tracks.append(gi);
|
|
|
|
if (_showTracks)
|
|
|
|
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++) {
|
2019-08-25 10:54:25 +02:00
|
|
|
_palette.nextColor();
|
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++)
|
2019-08-25 10:54:25 +02:00
|
|
|
_palette.nextColor();
|
2019-01-31 01:46:53 +01:00
|
|
|
|
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;
|
|
|
|
|
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 PowerGraph::clear()
|
|
|
|
{
|
2019-08-25 10:54:25 +02:00
|
|
|
qDeleteAll(_tracks);
|
|
|
|
_tracks.clear();
|
|
|
|
|
2016-11-06 03:28:08 +01:00
|
|
|
_avg.clear();
|
|
|
|
|
2019-03-05 22:34:50 +01:00
|
|
|
GraphTab::clear();
|
2016-11-06 03:28:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PowerGraph::showTracks(bool show)
|
|
|
|
{
|
|
|
|
_showTracks = show;
|
|
|
|
|
2019-08-25 10:54:25 +02:00
|
|
|
for (int i = 0; i < _tracks.size(); i++) {
|
|
|
|
if (show)
|
|
|
|
addGraph(_tracks.at(i));
|
|
|
|
else
|
|
|
|
removeGraph(_tracks.at(i));
|
|
|
|
}
|
|
|
|
|
2016-11-06 03:28:08 +01:00
|
|
|
setInfo();
|
|
|
|
|
|
|
|
redraw();
|
|
|
|
}
|