Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add route refresh #2570

Merged
merged 1 commit into from
Mar 23, 2020
Merged

Add route refresh #2570

merged 1 commit into from
Mar 23, 2020

Conversation

kmadsen
Copy link
Contributor

@kmadsen kmadsen commented Mar 11, 2020

Description

Resolves https://github.com/mapbox/navigation-sdks/issues/222

Related refactors
Update route line #2581
Improve the MapboxTimer #2575
Modularize faster route #2577

Current status is, ready for review

  • 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

Keep traffic fresh while driving viewing a route, and/or navigating a route

Implementation

  1. Refresh the current route when the profile contains "traffic"
  2. Use the directions call to request for a traffic update MapboxDirectionsRefresh
  3. Update the LegAnnotations on the route (traffic data)

What changed from 0.43

  1. Automatic refresh with "traffic" profiles. 0.43 was manually configured during initialization
  2. Add refresh current route. 0.43 would only refresh during navigation
  3. Remove implementation configuration. 0.43 allowed clients to make unnecessarily fast refresh rates

Example of the LegAnnotation json

{"distance":[39.82088283734119,11.943930596414795,11.741113723722966,51.342100705424095,5.849113092832654,6.034403160338987,44.25323230168093,5.526209358359064,13.899091719402477,43.49430010119116,11.195125050833482,11.459495476013347,82.25052046354502,4.0959504357663175,10.490508411438704,13.257044629366959,85.21705182045457,10.552608042831702,12.569519488314297,28.62658627157395,15.634516768831888,29.59563279009562,34.59872514885146],"congestion":["low","low","heavy","heavy","heavy","heavy","heavy","heavy","heavy","heavy","heavy","heavy","heavy","heavy","heavy","low","low","low","moderate","moderate","moderate","moderate","moderate"]}

Screenshots or Gifs

Screen Shot 2020-03-10 at 5 43 53 PM

Video of route being refreshed. Notice that the route blinks.

output

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

cc: @abhishek1508 @Guardiola31337 @olegzil

@kmadsen kmadsen added the feature New feature request. label Mar 11, 2020
@kmadsen kmadsen mentioned this pull request Mar 11, 2020
10 tasks
@kmadsen kmadsen force-pushed the km-route-refresh branch 2 times, most recently from 9fcd7d9 to b3292ce Compare March 12, 2020 01:43
@@ -27,7 +27,6 @@ internal object RouteBuilderProvider {
.accessToken(accessToken)
.voiceInstructions(true)
.bannerInstructions(true)
.enableRefresh(false)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a pain to find. I had to ask in #directions to figure it out
https://mapbox.slack.com/archives/C03KW1JQD/p1583881618015100

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updating this feature to be enabled automatically with traffic profiles because that's the only place it's supported.
https://mapbox.slack.com/archives/C03KW1JQD/p1583883018020600?thread_ts=1583881618.015100&cid=C03KW1JQD

@kmadsen kmadsen force-pushed the km-route-refresh branch 9 times, most recently from 3f3c665 to 0f828c2 Compare March 16, 2020 19:49
@kmadsen kmadsen marked this pull request as ready for review March 16, 2020 19:53
@kmadsen kmadsen force-pushed the km-route-refresh branch 2 times, most recently from 9cf1aa6 to 1093e96 Compare March 16, 2020 23:05
@codecov-io
Copy link

codecov-io commented Mar 16, 2020

Codecov Report

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

@@            Coverage Diff            @@
##             master    #2570   +/-   ##
=========================================
  Coverage     29.04%   29.04%           
  Complexity     1062     1062           
=========================================
  Files           281      281           
  Lines         10832    10832           
  Branches        881      881           
=========================================
  Hits           3146     3146           
  Misses         7340     7340           
  Partials        346      346

@kmadsen kmadsen force-pushed the km-route-refresh branch 5 times, most recently from 531b0a0 to a164785 Compare March 18, 2020 20:53
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 good so far @kmadsen

I've left some comments / questions to discuss before merging here.

Also, it'd be 💯 if we can add an example under the Navigation Core SDK examples showcasing the integration and the client options available and how can customize those (although it seems as it's enabled by default internally there are none 😬 - see my comments below).

libnavigation-core/build.gradle Outdated Show resolved Hide resolved
@@ -39,6 +39,7 @@ class MapboxOffboardRouter(
) {
mapboxDirections = RouteBuilderProvider.getBuilder(accessToken, context, skuTokenProvider)
.routeOptions(routeOptions)
.enableRefresh(routeOptions.isRefreshEnabled())
Copy link
Contributor

Choose a reason for hiding this comment

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

We're enabling refresh by default, is that a good idea? How a client can disable it? Currently (in the legacy) this can be customized

/**
* This enables / disables refresh route. If not specified, it's enabled by default.
*
* @param enableRefreshRoute whether or not to enable route refresh
* @return this builder for chaining options together
*/
fun enableRefreshRoute(enableRefreshRoute: Boolean) =
apply { this.enableRefreshRoute = enableRefreshRoute }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but those other options enable or disable route_refresh even if it's not supported

Copy link
Contributor Author

@kmadsen kmadsen Mar 20, 2020

Choose a reason for hiding this comment

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

this way only enables route refresh if it's supported. the approaches have their pros/cons so I think the issue is picking one

private val routeRefreshRetrofit = RouteRefreshRetrofit()
private val routeRefreshApi = RouteRefreshApi(routeRefreshRetrofit)

var intervalSeconds: Long = TimeUnit.MILLISECONDS.toSeconds(routerRefreshTimer.restartAfterMillis)
Copy link
Contributor

Choose a reason for hiding this comment

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

We're not setting the interval anywhere which means that we're using the default value from MapboxTimer

i.e. 1 minute. Currently (in the legacy) by default we try to refresh every 5 minutes (that's supposedly the optimal interval in which we can make sure the data is going to be fresh) https://github.com/mapbox/mapbox-navigation-android/blob/master/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/navigation/NavigationConstants.kt#L140 although both can be customized from MapboxNavigationOptions
/**
* This sets the route refresh interval. If not specified, the interval is 5 minutes by default.
*
* @param intervalInMilliseconds for route refresh
* @return this builder for chaining options together
*/
fun refreshIntervalInMilliseconds(intervalInMilliseconds: Long) =
apply { this.refreshIntervalInMilliseconds = intervalInMilliseconds }
Also, how can a client can pass in an interval?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

was considering options here still. but this class can stay the same with each option

  • add a function to MapboxNavigation to update the value
  • add an option to NavigationOptions
  • get the refresh rate from DirectionsResponse

Copy link
Contributor

Choose a reason for hiding this comment

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

get the refresh rate from DirectionsResponse

Do we have this available? Is the plan to have it eventually? cc @mapbox/navigation-api


override fun onRefresh(directionsRoute: DirectionsRoute) {
Log.i("RouteRefresh", "Successful refresh")
tripSession.route = directionsRoute
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a good idea? Wondering if we should implement something similar to faster route in which we expose the route to the client and it's up to them to use it or not, instead of us always doing it internally 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we update the MapboxDirectionsSession#routes[0] too 🤔? Actually, updating the MapboxDirectionsSession#routes will end up updating MapboxTripSession#route 👀

private fun createInternalRoutesObserver() = object : RoutesObserver {
override fun onRoutesChanged(routes: List<DirectionsRoute>) {
if (routes.isNotEmpty()) {
tripSession.route = routes[0]
} else {
tripSession.route = null
}
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Also noticed that we're updating the whole route in NN

instead of only the annotations as we do in the legacy 👀 RouteHandler. Do you know if this has a performance impact? Probably yes because it's not the same to serialize the whole route rather than only updating the annotations of the current route.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

looking into update the annotations only now, i did try before but that was early on.

considered performance impacts and considered it minor since it's per minutes (opposed to per seconds)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Nah, that's not correct 👀

} else {
route.legs()?.let { routeLegs ->
for (i in routeLegs.indices) {
routeLegs[i].annotation()?.toJson()?.let { annotationJson ->
mapboxNavigator.updateAnnotations(annotationJson, INDEX_FIRST_ROUTE, i)
}
}
}
}
if it's not a NEW_ROUTE we're only updating the annotations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah discussed offline, now see how fresh_route causes the condition in RouteHandler

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When attempting to only update annotations in NN, it didn't update the the traffic on the map.

@kmadsen kmadsen force-pushed the km-route-refresh branch 8 times, most recently from ee15527 to f3f9fc2 Compare March 23, 2020 18:18
@kmadsen kmadsen force-pushed the km-route-refresh branch 2 times, most recently from 11dd0bb to e7037a0 Compare March 23, 2020 19:17
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 @kmadsen

We should still think about how clients will enable / disable route refresh feature and how they can tune the refresh interval but we can work on that in a separate PR.

Great work 🍍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants