Skip to content

Commit

Permalink
Feedback Queue Update
Browse files Browse the repository at this point in the history
- renamed method
- added feedback location collect to onLocation listener
- created new methods to handle updating feedback and reroute queues
  • Loading branch information
electrostat committed Oct 23, 2017
1 parent bd2f284 commit 8ce5a00
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class NavigationService extends Service implements LocationEngineListener
private final IBinder localBinder = new LocalBinder();
private NavigationNotification navNotificationManager;
private List<SessionState> queuedRerouteEvents;
private List<FeedbackEvent> queuedFeedbackEvents;
private RingBuffer<Location> locationBuffer;
private long timeIntervalSinceLastOffRoute;
private MapboxNavigation mapboxNavigation;
Expand All @@ -67,8 +68,6 @@ public class NavigationService extends Service implements LocationEngineListener
private NavigationEngine thread;
private Location rawLocation;

private List<FeedbackEvent> queuedFeedbackEvents;

@Nullable
@Override
public IBinder onBind(Intent intent) {
Expand Down Expand Up @@ -199,20 +198,13 @@ public void onLocationChanged(Location location) {
locationBuffer.addLast(location);
thread.queueTask(MSG_LOCATION_UPDATED, NewLocationModel.create(location, mapboxNavigation,
recentDistancesFromManeuverInMeters));
Iterator<SessionState> iterator = queuedRerouteEvents.listIterator();
while (iterator.hasNext()) {
SessionState sessionState = iterator.next();
if (sessionState.lastRerouteLocation() != null
&& sessionState.lastRerouteLocation().equals(locationBuffer.peekFirst())
|| TimeUtils.dateDiff(sessionState.rerouteDate(), new Date(), TimeUnit.SECONDS)
> TWENTY_SECOND_INTERVAL) {
sendRerouteEvent(sessionState);
iterator.remove();
}
}

updateRerouteQueue(location);
updateFeedbackQueue(location);
}
}


/**
* Runs several checks on the actual rawLocation object itself in order to ensure that we are
* performing navigation progress on a accurate/valid rawLocation update.
Expand Down Expand Up @@ -274,12 +266,12 @@ public void onUserOffRoute(Location location, boolean userOffRoute) {
if (location.getTime() > timeIntervalSinceLastOffRoute
+ TimeUnit.SECONDS.toMillis(mapboxNavigation.options().secondsBeforeReroute())) {
timeIntervalSinceLastOffRoute = location.getTime();
if (mapboxNavigation.getSessionState().lastRerouteLocation() == null) {
if (mapboxNavigation.getSessionState().eventLocation() == null) {
rerouteSessionsStateUpdate();
} else {
Point lastReroutePoint = Point.fromLngLat(
mapboxNavigation.getSessionState().lastRerouteLocation().getLongitude(),
mapboxNavigation.getSessionState().lastRerouteLocation().getLatitude());
mapboxNavigation.getSessionState().eventLocation().getLongitude(),
mapboxNavigation.getSessionState().eventLocation().getLatitude());
if (TurfMeasurement.distance(lastReroutePoint,
Point.fromLngLat(location.getLongitude(), location.getLatitude()),
TurfConstants.UNIT_METERS)
Expand Down Expand Up @@ -324,23 +316,8 @@ public String recordFeedbackEvent(String feedbackType, String description,
.build();

FeedbackEvent feedbackEvent = new FeedbackEvent(feedbackEventSessionState, feedbackSource);
// TODO set feedback type and description from the parameters based
// TODO - note: these should use default values if the values passed are empty

// TODO Send 20 seconds later with "after" location updates
// runnable = new Runnable() {
// @Override
// public void run() {
// mapboxNavigation.setSessionState(mapboxNavigation.getSessionState().toBuilder()
// .afterRerouteLocations(Arrays.asList(
// locationBuffer.toArray(new Location[locationBuffer.size()])))
// .build());
//
//
// sendFeedbackEvent(mapboxNavigation.getSessionState());
// }
// };
// handler.postDelayed(runnable, TWENTY_SECOND_INTERVAL);
feedbackEvent.setDescription(description);
feedbackEvent.setFeedbackType(feedbackType);

return feedbackEvent.getFeedbackId();
}
Expand Down Expand Up @@ -376,13 +353,13 @@ void sendRerouteEvent(SessionState sessionState) {
.build();

NavigationMetricsWrapper.rerouteEvent(sessionState, routeProgress,
sessionState.lastRerouteLocation());
sessionState.eventLocation());

for (SessionState session : queuedRerouteEvents) {
queuedRerouteEvents.set(queuedRerouteEvents.indexOf(session),
session.toBuilder().lastRerouteDate(
sessionState.rerouteDate()
).build());
sessionState.rerouteDate()
).build());
}

mapboxNavigation.setSessionState(mapboxNavigation.getSessionState().toBuilder().lastRerouteDate(
Expand All @@ -405,4 +382,32 @@ private FeedbackEvent findQueuedFeedbackEvent(String feedbackId) {
}
return null;
}

private void updateFeedbackQueue(Location location) {
Iterator<FeedbackEvent> iterator = queuedFeedbackEvents.listIterator();
while (iterator.hasNext()) {
FeedbackEvent feedbackEvent = iterator.next();
if (feedbackEvent.getSessionState().eventLocation() != null
&& feedbackEvent.getSessionState().eventLocation().equals(locationBuffer.peekFirst())
|| TimeUtils.dateDiff(feedbackEvent.getSessionState().rerouteDate(), new Date(), TimeUnit.SECONDS)

This comment has been minimized.

Copy link
@danesfeder

danesfeder Oct 23, 2017

Contributor

Would both of these methods just send feedback / reroute events every 20 seconds regardless of if there is an actual event or not? Or would that fail because event location would be null cc @ericrwolfe

This comment has been minimized.

Copy link
@electrostat

electrostat Oct 23, 2017

Author Contributor

We do a check for a null location before these methods are called: line 196.

Then these 2 methods loop through the feedback and reroute queues respectively, everytime they are called, check if each event/session has either reached 20 items or been going for at least 20 seconds. Then it triggers a call to send the events immediately and removes the event/session from the queue.

Only change I just now noticed is that we should be passing the location buffer instead of just location to these methods. I can make that change now.

> TWENTY_SECOND_INTERVAL) {
sendFeedbackEvent(feedbackEvent);
iterator.remove();
}
}
}

private void updateRerouteQueue(Location location) {
Iterator<SessionState> iterator = queuedRerouteEvents.listIterator();
while (iterator.hasNext()) {
SessionState sessionState = iterator.next();
if (sessionState.eventLocation() != null
&& sessionState.eventLocation().equals(locationBuffer.peekFirst())
|| TimeUtils.dateDiff(sessionState.rerouteDate(), new Date(), TimeUnit.SECONDS)
> TWENTY_SECOND_INTERVAL) {
sendRerouteEvent(sessionState);
iterator.remove();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ int secondsSinceLastReroute() {
abstract Date lastRerouteDate();

@Nullable
abstract Location lastRerouteLocation();
abstract Location eventLocation();

abstract Date startTimestamp();

Expand Down

0 comments on commit 8ce5a00

Please sign in to comment.