Skip to content

Commit

Permalink
Merge pull request #4 from miguelbcr/hotfixes/#3-Errors_related_with_…
Browse files Browse the repository at this point in the history
…current_speed

#3-Errors related with current speed
  • Loading branch information
miguelbcr authored Oct 27, 2016
2 parents 7fd482f + d22d5b5 commit f09cd3c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

class GetTripDistance {
private long distanceAccumulated;
private long lastDistance;
private LatLong previousLatLong;
private LatLong currentLatLong;
private final Utilities utilities;
Expand All @@ -41,17 +40,13 @@ long getDistanceAccumulated() {
return distanceAccumulated;
}

long getLastDistance() {
return lastDistance;
}

Observable<Long> builtObservable() {
return utilities.getDistanceFromTo(previousLatLong, currentLatLong)
.concatMap(new Func1<Float, Observable<? extends Long>>() {
@Override public Observable<? extends Long> call(Float lastDistance) {
GetTripDistance.this.lastDistance = lastDistance.longValue();
distanceAccumulated += lastDistance.intValue();
return Observable.just(distanceAccumulated);
@Override public Observable<? extends Long> call(Float distance) {
long lastDistance = Math.round(distance);
distanceAccumulated += lastDistance;
return Observable.just(lastDistance);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class MeaningfulUpdatesLocation {
private Location previousLocation;
private Location currentLocation;
private final Utilities utilities;
private long lastMeaningfulDistance;

MeaningfulUpdatesLocation() {
utilities = new Utilities();
Expand All @@ -42,6 +43,10 @@ Location getCurrentLocation() {
return currentLocation;
}

long getLastMeaningfulDistance() {
return lastMeaningfulDistance;
}

Observable<Boolean> builtObservable(final int minDistanceTraveled) {
if (previousLocation == null) previousLocation = new Location("previousLocation");

Expand All @@ -53,7 +58,13 @@ Observable<Boolean> builtObservable(final int minDistanceTraveled) {
return utilities.getDistanceFromTo(previousLatLng, currentLatLng)
.map(new Func1<Float, Boolean>() {
@Override public Boolean call(Float distance) {
return minDistanceTraveled == 0 || distance >= minDistanceTraveled;
boolean isMeaningful = minDistanceTraveled == 0 || distance >= minDistanceTraveled;

if (isMeaningful) {
lastMeaningfulDistance = Math.round(distance);
}

return isMeaningful;
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void attachView(RxGpsServiceView view) {
long currentTime = System.currentTimeMillis() / 1000;
if (timeLastLocation == 0) timeLastLocation = currentTime;
timeLastLocation = currentTime - timeLastLocation;
getTripSpeed.setParams(distance.longValue(), timeLastLocation,
getTripSpeed.setParams(Math.round(distance), timeLastLocation,
gpsConfig.getFastestInterval() / 1000,
gpsConfig.getDiscardSpeedsAbove());
timeLastLocation = currentTime;
Expand Down Expand Up @@ -176,8 +176,9 @@ private Observable<RouteStats> getMeaningfulObservableRouteStats(Observable<Long
}
}).concatMap(new Func1<Long, Observable<Long>>() {
@Override public Observable<Long> call(Long timeElapsed) {
if (!isMeaningfulWaypoint) return Observable.just(distanceAccumulated);
if (isWaypointsEmpty() || hasOnlyOneWaypoint()) return Observable.just(distanceAccumulated);
if (!isMeaningfulWaypoint || isWaypointsEmpty() || hasOnlyOneWaypoint()) {
return Observable.just(meaningfulUpdatesLocation.getLastMeaningfulDistance());
}

getTripDistance.setParams(distanceAccumulated, getLatLongBeforeLast(), getLastLatLong());
return getTripDistance.builtObservable();
Expand All @@ -187,7 +188,7 @@ private Observable<RouteStats> getMeaningfulObservableRouteStats(Observable<Long
if (!isMeaningfulWaypoint) return Observable.just(speed);
distanceAccumulated = getTripDistance.getDistanceAccumulated();
lastTimeElapsed = timeElapsed - lastTimeElapsed;
getTripSpeed.setParams(getTripDistance.getLastDistance(), lastTimeElapsed,
getTripSpeed.setParams(distance, lastTimeElapsed,
gpsConfig.getFastestInterval() / 1000,
gpsConfig.getDiscardSpeedsAbove());
lastTimeElapsed = timeElapsed;
Expand Down Expand Up @@ -357,7 +358,7 @@ private void printLog(Location location) {
Log.d(TAG, "timeElapsed=" + timeElapsed +
" lastTimeElapsed=" + getTripSpeed.getLastTimeElapsed() +
" distance=" + distanceAccumulated +
" lastDistance=" + getTripDistance.getLastDistance() +
" lastDistance=" + meaningfulUpdatesLocation.getLastMeaningfulDistance() +
" speed=" + speed +
" speedAverage=" + speedAverage +
" speedMax=" + speedMax +
Expand Down

0 comments on commit f09cd3c

Please sign in to comment.