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

Fix "SetRoutesReason" when alternative route is chosen as a primary. #7464

Merged
merged 1 commit into from
Sep 22, 2023

Conversation

DzmitryFomchyn
Copy link
Contributor

Description

This PR fixes SetRoutesReason when alternative route is chosen as a primary.

@DzmitryFomchyn DzmitryFomchyn added the bug Defect to be fixed. label Aug 14, 2023
@DzmitryFomchyn DzmitryFomchyn requested a review from a team as a code owner August 14, 2023 09:49
@github-actions
Copy link

github-actions bot commented Aug 14, 2023

Changelog

Features

Bug fixes and improvements

  • Improved navigation positioning in tunnels. [#7514](https://github.com/mapbox/mapbox-navigation-android/pull/7514)

Known issues ⚠️

Other changes

Android Auto Changelog

Features

Bug fixes and improvements

  • The app is now considered as the one in active navigation only when an active route is set to MapboxNavigation. Previously it was always considered active. [#7366](https://github.com/mapbox/mapbox-navigation-android/pull/7366)
  • When Android Auto host tells the app to stop active navigation because another app starts navigating, now SDK will enter FreeDrive mode instead of stopping trip session completely. [#7366](https://github.com/mapbox/mapbox-navigation-android/pull/7366)

@DzmitryFomchyn DzmitryFomchyn removed the bug Defect to be fixed. label Aug 14, 2023
@codecov
Copy link

codecov bot commented Aug 14, 2023

Codecov Report

Merging #7464 (c600232) into main (285009e) will decrease coverage by 0.01%.
The diff coverage is 64.28%.

Impacted file tree graph

@@             Coverage Diff              @@
##               main    #7464      +/-   ##
============================================
- Coverage     74.13%   74.12%   -0.01%     
- Complexity     6141     6143       +2     
============================================
  Files           829      829              
  Lines         32883    32894      +11     
  Branches       3916     3921       +5     
============================================
+ Hits          24377    24383       +6     
- Misses         6973     6977       +4     
- Partials       1533     1534       +1     
Files Changed Coverage Δ
.../navigation/core/trip/session/MapboxTripSession.kt 84.53% <0.00%> (-1.07%) ⬇️
...ava/com/mapbox/navigation/core/MapboxNavigation.kt 71.32% <100.00%> (+0.12%) ⬆️
.../main/java/com/mapbox/navigation/core/SetRoutes.kt 100.00% <100.00%> (ø)
...pbox/navigation/core/internal/utils/SetRoutesEx.kt 100.00% <100.00%> (ø)

routes.first() == directionsSession.routes.firstOrNull() -> {
SetRoutes.Alternatives(initialLegIndex, isPrimaryRouteChanged = false)
}
routes.map { it.id }.sorted() == directionsSession.routes.map { it.id }.sorted() -> {
Copy link
Contributor

Choose a reason for hiding this comment

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

That's not reason "alternatives". This reason is not only used when setting routes to Native Navigator, but also:

  1. In telemetry;
  2. As reason in RoutesUpdatedResult (public API);
  3. In some internal logic (but looks like it is adjusted).

But now you're trying to set reason alternatives where from our perspective it's not actually "alternatives". The main problem is the misunderstanding between us and NN, do we know where that came from?
Anyway, even if we leave this misalignment, I'd suggest introducing a new internal reason (like "Reorder"). And it would get mapped to native "alternative" and our "new" reasons correspondingly.

BTW, what if we had routes [A, B, C] and now we have [B, A]? For us it's reason "new". What about NN? What do they expect?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As reason in RoutesUpdatedResult (public API)

It affects only mapping to RoutesUpdatedResult.RoutesUpdateReason (we haven't introduced any new value for RoutesUpdateReason), public api is not broken.

The main problem is the misunderstanding between us and NN, do we know where that came from?

This behavior is expected by the NN, and now it's consistent with the iOS Navigation SDK (I'll send you a link to a discussion).

Anyway, even if we leave this misalignment, I'd suggest introducing a new internal reason (like "Reorder"). And it would get mapped to native "alternative" and our "new" reasons correspondingly.

Makes sense, thank you!. I've updated the PR.

BTW, what if we had routes [A, B, C] and now we have [B, A]? For us it's reason "new". What about NN? What do they expect?

It's seems that the reason new is expected, but we can make sure with the NN team.

@DzmitryFomchyn DzmitryFomchyn force-pushed the NAVAND-1338-route-set-reason-fix branch from 40b3bed to cb78522 Compare August 21, 2023 07:28
/**
* Triggered when routes list remain the same but **alternative route has been chosen as a primary**.
*/
internal data class Reorder(val legIndex: Int) : SetRoutes()
Copy link
Contributor

Choose a reason for hiding this comment

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

[NIT] As I understood it's an internal name which will be mapped to a different name for NN and SDK users. Maybe we can change it to be the same as comments above says:

Suggested change
internal data class Reorder(val legIndex: Int) : SetRoutes()
internal data class SwitchToAlternativeRoute(val legIndex: Int) : SetRoutes()

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After new discussion with NN team, this type is used when primary route changed and previous primary became alternative. As for me, both names Reorder and SwitchToAlternativeRoute can be used here, but the second option sounds very similar to Alternatives. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Reorder doesn't reflect the fact that primary route changed. You could have had [A, B, C] and then [A, C, B]. That sounds like a reorder to me, but it's not.
So IMO SwitchToAlternative suits better here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, let's leave it as is for now in order not to wait for PR checks before release. I'll fix it as a follow-up PR

@DzmitryFomchyn DzmitryFomchyn force-pushed the NAVAND-1338-route-set-reason-fix branch 2 times, most recently from 187b365 to 7a2e956 Compare September 18, 2023 12:46
@DzmitryFomchyn DzmitryFomchyn added the skip changelog Should not be added into version changelog. label Sep 18, 2023
@DzmitryFomchyn DzmitryFomchyn force-pushed the NAVAND-1338-route-set-reason-fix branch from 7a2e956 to c600232 Compare September 18, 2023 16:54
SetRoutes.Alternatives(initialLegIndex)
}
directionsSession.routes.map { it.id }.contains(routes.first().id) -> {
Copy link
Contributor

Choose a reason for hiding this comment

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

The result of execution of this branch relies on the fact that if it's just the alternatives being reordered, we won't go to this branch (because we'll stop on the previous one).
I'm not a fan of this approach, because the result here depends on the branch order, and here it's not super obvious that the order matters. With if-else it's more clear than with when, although that could be just a personal preference.
Anyway, if anyone else from you finds this point valid, let's maybe make it more explicit here. @DzmitryFomchyn @VysotskiVadim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip changelog Should not be added into version changelog.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants