mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-01-19 04:02:09 +01:00
Fixed broken speed calculation
Optimization
This commit is contained in:
parent
24835db090
commit
1cd726691e
@ -69,31 +69,25 @@ static Graph filter(const Graph &g, int window)
|
|||||||
Track::Track(const TrackData &data) : _data(data)
|
Track::Track(const TrackData &data) : _data(data)
|
||||||
{
|
{
|
||||||
QVector<qreal> acceleration;
|
QVector<qreal> acceleration;
|
||||||
qreal ds;
|
qreal ds, dt;
|
||||||
int last;
|
|
||||||
|
|
||||||
_time.append(0);
|
_time.append(0);
|
||||||
_distance.append(0);
|
_distance.append(0);
|
||||||
_speed.append(0);
|
_speed.append(0);
|
||||||
acceleration.append(0);
|
acceleration.append(0);
|
||||||
|
|
||||||
last = 0;
|
|
||||||
for (int i = 1; i < _data.count(); i++) {
|
for (int i = 1; i < _data.count(); i++) {
|
||||||
ds = _data.at(i).coordinates().distanceTo(_data.at(i-1).coordinates());
|
ds = _data.at(i).coordinates().distanceTo(_data.at(i-1).coordinates());
|
||||||
_distance.append(ds);
|
_distance.append(_distance.at(i-1) + ds);
|
||||||
|
|
||||||
if (_data.first().hasTimestamp() && _data.at(i).hasTimestamp()
|
if (_data.first().hasTimestamp() && _data.at(i).hasTimestamp()
|
||||||
&& _data.at(i).timestamp() >= _data.at(last).timestamp()) {
|
&& _data.at(i).timestamp() >= _data.at(i-1).timestamp())
|
||||||
_time.append(_data.first().timestamp().msecsTo(
|
_time.append(_data.first().timestamp().msecsTo(
|
||||||
_data.at(i).timestamp()) / 1000.0);
|
_data.at(i).timestamp()) / 1000.0);
|
||||||
last = i;
|
else
|
||||||
} else
|
|
||||||
_time.append(NAN);
|
_time.append(NAN);
|
||||||
|
|
||||||
if (std::isnan(_time.at(i)) || std::isnan(_time.at(i-1)))
|
dt = _time.at(i) - _time.at(i-1);
|
||||||
_speed.append(NAN);
|
|
||||||
else {
|
|
||||||
qreal dt = _time.at(i) - _time.at(i-1);
|
|
||||||
if (dt < 1e-3) {
|
if (dt < 1e-3) {
|
||||||
_speed.append(_speed.at(i-1));
|
_speed.append(_speed.at(i-1));
|
||||||
acceleration.append(acceleration.at(i-1));
|
acceleration.append(acceleration.at(i-1));
|
||||||
@ -104,7 +98,6 @@ Track::Track(const TrackData &data) : _data(data)
|
|||||||
qreal dv = _speed.at(i) - _speed.at(i-1);
|
qreal dv = _speed.at(i) - _speed.at(i-1);
|
||||||
acceleration.append(dv / dt);
|
acceleration.append(dv / dt);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
_pause = 0;
|
_pause = 0;
|
||||||
for (int i = 1; i < _data.count(); i++) {
|
for (int i = 1; i < _data.count(); i++) {
|
||||||
@ -116,14 +109,16 @@ Track::Track(const TrackData &data) : _data(data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_outlierEliminate)
|
if (!_outlierEliminate)
|
||||||
|
return;
|
||||||
|
|
||||||
_outliers = eliminate(acceleration);
|
_outliers = eliminate(acceleration);
|
||||||
|
|
||||||
QSet<int>::const_iterator it;
|
QSet<int>::const_iterator it;
|
||||||
for (it = _stop.constBegin(); it != _stop.constEnd(); ++it)
|
for (it = _stop.constBegin(); it != _stop.constEnd(); ++it)
|
||||||
_outliers.remove(*it);
|
_outliers.remove(*it);
|
||||||
|
|
||||||
last = 0;
|
int last = 0;
|
||||||
for (int i = 0; i < _data.size(); i++) {
|
for (int i = 0; i < _data.size(); i++) {
|
||||||
if (_outliers.contains(i))
|
if (_outliers.contains(i))
|
||||||
last++;
|
last++;
|
||||||
@ -133,12 +128,16 @@ Track::Track(const TrackData &data) : _data(data)
|
|||||||
for (int i = last + 1; i < _data.size(); i++) {
|
for (int i = last + 1; i < _data.size(); i++) {
|
||||||
if (_outliers.contains(i))
|
if (_outliers.contains(i))
|
||||||
continue;
|
continue;
|
||||||
if (discardStopPoint(i))
|
if (discardStopPoint(i)) {
|
||||||
_distance[i] = _distance.at(last);
|
_distance[i] = _distance.at(last);
|
||||||
else {
|
_speed[i] = 0;
|
||||||
|
} else {
|
||||||
ds = _data.at(i).coordinates().distanceTo(
|
ds = _data.at(i).coordinates().distanceTo(
|
||||||
_data.at(last).coordinates());
|
_data.at(last).coordinates());
|
||||||
_distance[i] = _distance.at(last) + ds;
|
_distance[i] = _distance.at(last) + ds;
|
||||||
|
|
||||||
|
dt = _time.at(i) - _time.at(last);
|
||||||
|
_speed[i] = (dt < 1e-3) ? _speed.at(last) : ds / dt;
|
||||||
}
|
}
|
||||||
last = i;
|
last = i;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user