1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-28 13:41:16 +01:00
GPXSee/src/heartrategraph.cpp

85 lines
1.5 KiB
C++
Raw Normal View History

2016-10-23 11:09:20 +02:00
#include "data.h"
#include "heartrategraph.h"
2016-06-24 00:55:44 +02:00
HeartRateGraph::HeartRateGraph(QWidget *parent) : GraphTab(parent)
{
_units = Metric;
2016-08-19 19:48:44 +02:00
_showTracks = true;
2016-03-28 19:04:58 +02:00
GraphView::setYUnits(tr("1/min"));
setYLabel(tr("Heart rate"));
2016-03-27 13:23:00 +02:00
setSliderPrecision(0);
}
2016-08-09 01:16:19 +02:00
void HeartRateGraph::setInfo()
{
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-10-23 11:09:20 +02:00
void HeartRateGraph::loadData(const Data &data, const QList<PathItem *> &paths)
{
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-09-19 23:35:04 +02:00
if (graph.size() < 2) {
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-10-23 11:09:20 +02:00
_avg.append(QPointF(data.tracks().at(i)->distance(), sum/w));
2016-09-19 00:56:10 +02:00
GraphView::loadGraph(graph, paths.at(i));
}
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();
}
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();
}
void HeartRateGraph::showTracks(bool show)
{
2016-08-19 19:48:44 +02:00
_showTracks = show;
showGraph(show);
2016-08-20 11:28:08 +02:00
setInfo();
redraw();
}