Skip to content

Conversation

@abhishek1508
Copy link
Contributor

@abhishek1508 abhishek1508 commented Feb 11, 2020

Description

Add logic to use user current location to request for faster route. Compare new route with current route to determine if it is faster #221

  • I have added any issue links
  • I have added all related labels (bug, feature, new API(s), SEMVER, etc.)
  • I have added the appropriate milestone and project boards

Goal

Add logic to use user current location to request for faster route. Compare new route with current route to determine if it is faster.

Implementation

Add logic to use user current location to request for faster route. Compare new route with current route to determine if it is faster.

Testing

Please describe the manual tests that you ran to verify your changes

  • I have tested locally (including SNAPSHOT upstream dependencies if needed) through testapp/demo app and run all activities to avoid regressions
  • I have tested via a test drive, or a simulation/mock location app
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have updated the CHANGELOG including this PR

@abhishek1508 abhishek1508 changed the title add logic to determine faster route Add logic to determine faster route Feb 11, 2020
@abhishek1508 abhishek1508 force-pushed the feature/ak-#221_faster_route_current_location branch from a581b69 to bbb3c3a Compare February 11, 2020 01:11
Copy link

@LukasPaczos LukasPaczos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good progress 👍

How about DirectionsSession exposes a callback like in #2455, but instead of calling it FaterRouteCallback, we call it AlternativeRouteObserver.
The session still maintains the timer and makes periodic requests that invoke the observers.

MapboxNavigation can subscribe to this event and based on the route progress determine whether the alternative route is actually faster. If it is, it notifies FaterRouteObservers that now live and are maintained in MapboxNavigation.

This way, we are decreasing the coupling between the 2 classes and simplifying the whole flow.

@LukasPaczos LukasPaczos requested a review from a team February 12, 2020 17:56
@abhishek1508
Copy link
Contributor Author

Good progress 👍

How about DirectionsSession exposes a callback like in #2455, but instead of calling it FaterRouteCallback, we call it AlternativeRouteObserver.
The session still maintains the timer and makes periodic requests that invoke the observers.

MapboxNavigation can subscribe to this event and based on the route progress determine whether the alternative route is actually faster. If it is, it notifies FaterRouteObservers that now live and are maintained in MapboxNavigation.

This way, we are decreasing the coupling between the 2 classes and simplifying the whole flow.

I had a great discussion with @Guardiola31337 last week on 2 different approaches to implement faster route detection. We explored the possibility of having the Faster Route Timer in DirectionsSession. The problem is to make a faster route request you use the same API as route request. The API needs RouteOptions which needs updated user current location. DirectionsSession doesn't have access to users current location. We don't want to expose methods to DirectionSession that maintains users current location or make DirectionsSession observe location updates. The architecture was implemented to make sure that MapboxNavigation will be the intermediary b/w Directions and Trips and any feature that needs access to properties from these 2 different modules will be handled in MapboxNavigation. Hence, the timer cannot live in DirectionsSession.

The implementation above is the first iteration towards FasterRoute. I plan to take out the implementation details from MapboxNavigation so that it is light in the next iteration. Also, I would rather not use the term AlternativeRouteObserver as I feel that may be confusing from client's perspective. I say this because there is already this feature where we allow users to specify if they want alternative routes. and draw them accordingly. We then have offRoute observers and callbacks that inform users about onRoutesChanged. Having specific terms for features makes it easy to understand what is one doing. Wdyt?

Copy link

@LukasPaczos LukasPaczos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The location samples are the tiebreaker here. If we don't want to push them to the directions session, which we shouldn't, the timer has to live in MapboxNavigation and exposing additional route request method might be the only way 👍

@abhishek1508
Copy link
Contributor Author

I don't see any other outstanding comments here.
@Guardiola31337 @LukasPaczos would be great if you could approve. I would like to merge this so that this code is then accessible in this ticket and it makes it easy for everyone to understand how is the entire faster route tied together

@LukasPaczos
Copy link

Capturing from multiple threads above:

  • I'm okay with exposing the states if you feel like it's the right thing to do now. I can see the value, we'll just need to be extra careful.
  • I still think that the faster route timer should run even if we are not in active guidance and leave the decision of whether or not to update the route to the user.

@abhishek1508
Copy link
Contributor Author

  • I'm okay with exposing the states if you feel like it's the right thing to do now. I can see the value, we'll just need to be extra careful.

@LukasPaczos I would like to give some time to think on what are the possible other ways to expose navigationState in general. I think this is good for first iteration. We should definitely have a broader discussion around this in a separate follow up ticket that is more targeted to NavigationState rather than faster route. Will create a ticket for it.

@LukasPaczos
Copy link

Sounds good, thanks @abhishek1508.

@abhishek1508 abhishek1508 force-pushed the feature/ak-#221_faster_route_current_location branch from 84477b6 to 4e2974e Compare February 13, 2020 18:57
@codecov-io
Copy link

codecov-io commented Feb 13, 2020

Codecov Report

Merging #2462 into master will not change coverage.
The diff coverage is n/a.

@@            Coverage Diff            @@
##             master    #2462   +/-   ##
=========================================
  Coverage     32.29%   32.29%           
  Complexity      621      621           
=========================================
  Files           143      143           
  Lines          5605     5605           
  Branches        434      434           
=========================================
  Hits           1810     1810           
  Misses         3595     3595           
  Partials        200      200

@Guardiola31337
Copy link
Contributor

Capturing from internal discussion with @abhishek1508 that we're going to try the following:

  • Move NavigationSession back to libnavigation-core (for now)
  • Remove unnecessary back and forth cycle between MapboxNavigation and DirectionsSession
  • Reuse RoutesRequestCallback
  • Run faster route timer independently of the NavigationSession.State
  • Link faster route timer lifecycle to observer register / unregister

cc @LukasPaczos

Copy link

@LukasPaczos LukasPaczos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Minor comments and should be good to merge (when tests are ready).

Copy link
Contributor

@Guardiola31337 Guardiola31337 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking pretty good, great work @abhishek1508

Adding to @LukasPaczos's comments I left some other minor ones.

@abhishek1508 abhishek1508 force-pushed the feature/ak-#221_faster_route_current_location branch from 50c9eeb to 7ffa36f Compare February 15, 2020 19:11
Copy link
Contributor

@Guardiola31337 Guardiola31337 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing the feedback @abhishek1508

Left some minor comments. Also it seems that we lost some tests (e.g. fasterRoute_timerStartedOnce and fasterRoute_canceledByNewRequest) 🤔 Not sure if covered by others, could you confirm?

Other than that, this looks good to me 🚀

}

@Test
fun fasterRoute_timerStarted() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor thing

Normally is good to structure the tests following the triple A 👀 https://speakerdeck.com/guardiola31337/elegant-unit-testing-mobilization-2016?slide=40 http://wiki.c2.com/?ArrangeActAssert
If the Arrange part gets too long we should create factory or builder methods.

This applies to the rest of the tests 👇

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT This is still valid

@abhishek1508
Copy link
Contributor Author

@Guardiola31337 fasterRoute_timerStartedOnce should not be concern of MapboxNavigation or MapboxDirectionSession. All they should do is call start on the timer and timer should be responsible to check if it is being started once or multiple times. MapboxTimerTest doesn't exist at the moment, hence I am going to cut a ticket for it.

@abhishek1508 abhishek1508 force-pushed the feature/ak-#221_faster_route_current_location branch from bae97ac to d4fd1ac Compare February 17, 2020 22:01
@abhishek1508 abhishek1508 force-pushed the feature/ak-#221_faster_route_current_location branch from d4fd1ac to b447eca Compare February 17, 2020 22:34
@Guardiola31337
Copy link
Contributor

👀 @cafesilencio @evabishchevich @JunDai this PR brings some insights and thoughts on what we were discussing today. Please read the threads comments when you have a chance.

Copy link
Contributor

@Guardiola31337 Guardiola31337 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's cut follow up tickets for https://github.com/mapbox/mapbox-navigation-android/pull/2462/files#r380339602 and #2462 (comment) and we should be good to go.

Thanks for addressing the feedback @abhishek1508 🚀

}

@Test
fun fasterRoute_timerStarted() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT This is still valid

@abhishek1508 abhishek1508 merged commit e961cb2 into master Feb 19, 2020
@abhishek1508 abhishek1508 deleted the feature/ak-#221_faster_route_current_location branch February 19, 2020 00:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants