1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-28 05:34:47 +01:00

Code cleanup

This commit is contained in:
Martin Tůma 2016-06-27 20:30:45 +02:00
parent fc67f6f19a
commit 2695745d82
2 changed files with 21 additions and 42 deletions

View File

@ -81,39 +81,34 @@ static QVector<QPointF> filter(const QVector<QPointF> &v, int window)
Track::Track(const QVector<Trackpoint> &data) : _data(data) Track::Track(const QVector<Trackpoint> &data) : _data(data)
{ {
_distance = 0; qreal dist = 0;
for (int i = 1; i < _data.count(); i++) _dd.append(dist);
_dd.append(llDistance(_data.at(i).coordinates, for (int i = 1; i < _data.count(); i++) {
_data.at(i-1).coordinates)); dist += llDistance(_data.at(i).coordinates, _data.at(i-1).coordinates);
_dd.append(dist);
for (int i = 0; i < _dd.size(); i++) }
_distance += _dd.at(i);
} }
void Track::elevationGraph(QVector<QPointF> &graph) const void Track::elevationGraph(QVector<QPointF> &graph) const
{ {
qreal dist = 0;
QVector<QPointF> raw; QVector<QPointF> raw;
if (!_data.size()) if (!_data.size())
return; return;
if (_data.at(0).hasElevation()) for (int i = 0; i < _data.size(); i++)
raw.append(QPointF(0, _data.at(0).elevation - _data.at(0).geoidheight));
for (int i = 1; i < _data.size(); i++) {
dist += _dd.at(i-1);
if (_data.at(i).hasElevation()) if (_data.at(i).hasElevation())
raw.append(QPointF(dist, _data.at(i).elevation raw.append(QPointF(_dd.at(i), _data.at(i).elevation
- _data.at(i).geoidheight)); - _data.at(i).geoidheight));
}
graph = filter(raw, WINDOW_EF); graph = filter(raw, WINDOW_EF);
} }
void Track::speedGraph(QVector<QPointF> &graph) const void Track::speedGraph(QVector<QPointF> &graph) const
{ {
qreal dist = 0, v, ds, dt; qreal v, ds;
qint64 dt;
QVector<QPointF> raw; QVector<QPointF> raw;
if (!_data.size()) if (!_data.size())
@ -121,21 +116,17 @@ void Track::speedGraph(QVector<QPointF> &graph) const
raw.append(QPointF(0, 0)); raw.append(QPointF(0, 0));
for (int i = 1; i < _data.size(); i++) { for (int i = 1; i < _data.size(); i++) {
ds = _dd.at(i-1);
dist += ds;
if (_data.at(i).hasSpeed()) if (_data.at(i).hasSpeed())
v = _data.at(i).speed; v = _data.at(i).speed;
else if (_data.at(i).hasTimestamp()) { else if (_data.at(i).hasTimestamp()) {
dt = _data.at(i-1).timestamp.msecsTo(_data.at(i).timestamp) if (!(dt = _data.at(i-1).timestamp.msecsTo(_data.at(i).timestamp)))
/ 1000.0;
if (dt == 0)
continue; continue;
v = ds / dt; ds = _dd.at(i) - _dd.at(i-1);
v = ds / ((qreal)dt / 1000.0);
} else } else
continue; continue;
raw.append(QPointF(dist, v)); raw.append(QPointF(_dd.at(i), v));
} }
graph = filter(eliminate(raw, WINDOW_SE), WINDOW_SF); graph = filter(eliminate(raw, WINDOW_SE), WINDOW_SF);
@ -143,37 +134,26 @@ void Track::speedGraph(QVector<QPointF> &graph) const
void Track::heartRateGraph(QVector<QPointF> &graph) const void Track::heartRateGraph(QVector<QPointF> &graph) const
{ {
qreal dist = 0;
QVector<QPointF> raw; QVector<QPointF> raw;
if (!_data.size()) if (!_data.size())
return; return;
if (_data.at(0).hasHeartRate()) for (int i = 0; i < _data.count(); i++)
raw.append(QPointF(0, _data.at(0).heartRate));
for (int i = 1; i < _data.count(); i++) {
dist += _dd.at(i-1);
if (_data.at(i).hasHeartRate()) if (_data.at(i).hasHeartRate())
raw.append(QPointF(dist, _data.at(i).heartRate)); raw.append(QPointF(_dd.at(i), _data.at(i).heartRate));
}
graph = filter(eliminate(raw, WINDOW_HE), WINDOW_HF); graph = filter(eliminate(raw, WINDOW_HE), WINDOW_HF);
} }
void Track::temperatureGraph(QVector<QPointF> &graph) const void Track::temperatureGraph(QVector<QPointF> &graph) const
{ {
qreal dist = 0;
if (!_data.size()) if (!_data.size())
return; return;
if (_data.at(0).hasTemperature()) for (int i = 0; i < _data.size(); i++)
graph.append(QPointF(0, _data.at(0).temperature));
for (int i = 1; i < _data.size(); i++) {
dist += _dd.at(i-1);
if (_data.at(i).hasTemperature()) if (_data.at(i).hasTemperature())
graph.append(QPointF(dist, _data.at(i).temperature)); graph.append(QPointF(_dd.at(i), _data.at(i).temperature));
}
} }
void Track::track(QVector<QPointF> &track) const void Track::track(QVector<QPointF> &track) const
@ -187,14 +167,13 @@ qreal Track::time() const
if (_data.size() < 2) if (_data.size() < 2)
return 0; return 0;
return (_data.at(0).timestamp.msecsTo(_data.at(_data.size() - 1).timestamp) return (_data.first().timestamp.msecsTo(_data.last().timestamp) / 1000.0);
/ 1000.0);
} }
QDateTime Track::date() const QDateTime Track::date() const
{ {
if (_data.size()) if (_data.size())
return _data.at(0).timestamp; return _data.first().timestamp;
else else
return QDateTime(); return QDateTime();
} }

View File

@ -15,7 +15,7 @@ public:
void heartRateGraph(QVector<QPointF> &graph) const; void heartRateGraph(QVector<QPointF> &graph) const;
void temperatureGraph(QVector<QPointF> &graph) const; void temperatureGraph(QVector<QPointF> &graph) const;
void track(QVector<QPointF> &track) const; void track(QVector<QPointF> &track) const;
qreal distance() const {return _distance;} qreal distance() const {return _dd.last();}
qreal time() const; qreal time() const;
QDateTime date() const; QDateTime date() const;