use of com.mapbox.services.android.navigation.v5.navigation.metrics.SessionState in project mapbox-navigation-android by mapbox.
the class NavigationTelemetry method updateSessionRoute.
/**
* Called when a new {@link DirectionsRoute} is given in
* {@link MapboxNavigation#startNavigation(DirectionsRoute)}.
* <p>
* At this point, navigation has already begun and the {@link SessionState}
* needs to be updated.
*
* @param directionsRoute new route passed to {@link MapboxNavigation}
*/
void updateSessionRoute(DirectionsRoute directionsRoute) {
SessionState.Builder navigationBuilder = navigationSessionState.toBuilder();
navigationBuilder.currentDirectionRoute(directionsRoute);
if (isOffRoute) {
// If we are off-route, update the reroute count
navigationBuilder.rerouteCount(navigationSessionState.rerouteCount() + 1);
boolean hasRouteOptions = directionsRoute.routeOptions() != null;
navigationBuilder.requestIdentifier(hasRouteOptions ? directionsRoute.routeOptions().requestUuid() : null);
navigationSessionState = navigationBuilder.build();
updateLastRerouteEvent(directionsRoute);
lastRerouteDate = new Date();
isOffRoute = false;
} else {
// Not current off-route - just update the session
navigationSessionState = navigationBuilder.build();
}
}
use of com.mapbox.services.android.navigation.v5.navigation.metrics.SessionState in project mapbox-navigation-android by mapbox.
the class NavigationMetricsWrapper method rerouteEvent.
static void rerouteEvent(RerouteEvent rerouteEvent, MetricsRouteProgress metricProgress, Location location) {
SessionState sessionState = rerouteEvent.getSessionState();
updateRouteProgressSessionData(metricProgress);
Hashtable<String, Object> navRerouteEvent = MapboxNavigationEvent.buildRerouteEvent(sdkIdentifier, BuildConfig.MAPBOX_NAVIGATION_VERSION_NAME, sessionState.sessionIdentifier(), location.getLatitude(), location.getLongitude(), sessionState.currentGeometry(), metricProgress.getDirectionsRouteProfile(), metricProgress.getDirectionsRouteDistance(), metricProgress.getDirectionsRouteDuration(), sessionState.rerouteCount(), sessionState.startTimestamp(), convertToArray(sessionState.beforeEventLocations()), convertToArray(sessionState.afterEventLocations()), // distanceCompleted
(int) sessionState.eventRouteDistanceCompleted(), // distanceRemaining
sessionState.eventRouteProgress().getDistanceRemaining(), // durationRemaining
sessionState.eventRouteProgress().getDurationRemaining(), // new distanceRemaining
rerouteEvent.getNewDistanceRemaining(), // new durationRemaining
rerouteEvent.getNewDurationRemaining(), sessionState.secondsSinceLastReroute(), TelemetryUtils.buildUUID(), rerouteEvent.getNewRouteGeometry(), sessionState.mockLocation(), sessionState.originalRequestIdentifier(), sessionState.requestIdentifier(), sessionState.originalGeometry(), sessionState.originalDistance(), sessionState.originalDuration(), null, upcomingInstruction, upcomingType, upcomingModifier, upcomingName, previousInstruction, previousType, previousModifier, previousName, metricProgress.getCurrentStepDistance(), metricProgress.getCurrentStepDuration(), metricProgress.getCurrentStepDistanceRemaining(), metricProgress.getCurrentStepDurationRemaining(), sessionState.currentStepCount(), sessionState.originalStepCount());
navRerouteEvent.put(MapboxNavigationEvent.KEY_CREATED, TelemetryUtils.generateCreateDate(location));
int absoluteDistance = DistanceUtils.calculateAbsoluteDistance(location, metricProgress);
MapboxTelemetry.getInstance().addPercentTimeInForeground(sessionState.percentInForeground(), navRerouteEvent);
MapboxTelemetry.getInstance().addPercentTimeInPortrait(sessionState.percentInPortrait(), navRerouteEvent);
MapboxTelemetry.getInstance().addAbsoluteDistanceToDestination(absoluteDistance, navRerouteEvent);
MapboxTelemetry.getInstance().addLocationEngineName(sessionState.locationEngineName(), navRerouteEvent);
MapboxTelemetry.getInstance().pushEvent(navRerouteEvent);
MapboxTelemetry.getInstance().flushEventsQueueImmediately(false);
}
Aggregations