2016-10-23 11:09:20 +02:00
|
|
|
#include "data.h"
|
2016-03-21 22:37:55 +01:00
|
|
|
#include "heartrategraph.h"
|
|
|
|
|
|
|
|
|
2016-06-24 00:55:44 +02:00
|
|
|
HeartRateGraph::HeartRateGraph(QWidget *parent) : GraphTab(parent)
|
2016-03-21 22:37:55 +01:00
|
|
|
{
|
2016-03-27 15:04:58 +02:00
|
|
|
_units = Metric;
|
2016-08-19 19:48:44 +02:00
|
|
|
_showTracks = true;
|
2016-03-27 15:04:58 +02:00
|
|
|
|
2016-03-28 19:04:58 +02:00
|
|
|
GraphView::setYUnits(tr("1/min"));
|
2016-03-21 22:37:55 +01:00
|
|
|
setYLabel(tr("Heart rate"));
|
2016-03-27 15:04:58 +02:00
|
|
|
|
2016-03-27 13:23:00 +02:00
|
|
|
setSliderPrecision(0);
|
2016-03-21 22:37:55 +01:00
|
|
|
}
|
|
|
|
|
2016-08-09 01:16:19 +02:00
|
|
|
void HeartRateGraph::setInfo()
|
2016-03-21 22:37:55 +01:00
|
|
|
{
|
2016-08-19 19:48:44 +02:00
|
|
|
if (_showTracks) {
|
|
|
|
GraphView::addInfo(tr("Average"), QString::number(avg() * yScale(), 'f',
|
|
|
|
0) + UNIT_SPACE + yUnits());
|
|
|
|
GraphView::addInfo(tr("Maximum"), QString::number(max() * yScale(), 'f',
|
|
|
|
0) + UNIT_SPACE + yUnits());
|
|
|
|
} else
|
|
|
|
clearInfo();
|
2016-03-21 22:37:55 +01:00
|
|
|
}
|
|
|
|
|
2016-10-23 11:09:20 +02:00
|
|
|
void HeartRateGraph::loadData(const Data &data, const QList<PathItem *> &paths)
|
2016-03-21 22:37:55 +01:00
|
|
|
{
|
2016-10-23 11:09:20 +02:00
|
|
|
for (int i = 0; i < data.tracks().count(); i++) {
|
|
|
|
const Graph &graph = data.tracks().at(i)->heartRate();
|
2016-03-27 13:23:00 +02:00
|
|
|
qreal sum = 0, w = 0;
|
2016-03-21 22:37:55 +01:00
|
|
|
|
2016-09-19 23:35:04 +02:00
|
|
|
if (graph.size() < 2) {
|
2016-03-21 22:37:55 +01:00
|
|
|
skipColor();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-09-19 23:35:04 +02:00
|
|
|
for (int j = 1; j < graph.size(); j++) {
|
|
|
|
qreal ds = graph.at(j).s() - graph.at(j-1).s();
|
|
|
|
sum += graph.at(j).y() * ds;
|
2016-09-19 00:56:10 +02:00
|
|
|
w += ds;
|
2016-03-21 22:37:55 +01:00
|
|
|
}
|
2016-10-23 11:09:20 +02:00
|
|
|
_avg.append(QPointF(data.tracks().at(i)->distance(), sum/w));
|
2016-03-21 22:37:55 +01:00
|
|
|
|
2016-09-19 00:56:10 +02:00
|
|
|
GraphView::loadGraph(graph, paths.at(i));
|
2016-03-21 22:37:55 +01:00
|
|
|
}
|
2016-03-27 13:23:00 +02:00
|
|
|
|
2016-10-23 11:09:20 +02:00
|
|
|
for (int i = 0; i < data.routes().count(); i++)
|
2016-08-09 01:16:19 +02:00
|
|
|
skipColor();
|
|
|
|
|
|
|
|
setInfo();
|
|
|
|
|
|
|
|
redraw();
|
2016-03-21 22:37:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
qreal HeartRateGraph::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 HeartRateGraph::clear()
|
|
|
|
{
|
|
|
|
_avg.clear();
|
|
|
|
|
|
|
|
GraphView::clear();
|
|
|
|
}
|
|
|
|
|
2016-08-16 00:27:54 +02:00
|
|
|
void HeartRateGraph::showTracks(bool show)
|
|
|
|
{
|
2016-08-19 19:48:44 +02:00
|
|
|
_showTracks = show;
|
2016-08-16 00:27:54 +02:00
|
|
|
|
|
|
|
showGraph(show);
|
2016-08-20 11:28:08 +02:00
|
|
|
setInfo();
|
2016-08-16 00:27:54 +02:00
|
|
|
|
|
|
|
redraw();
|
|
|
|
}
|