Search in sources :

Example 6 with SessionState

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();
    }
}
Also used : SessionState(com.mapbox.services.android.navigation.v5.navigation.metrics.SessionState) Date(java.util.Date)

Example 7 with SessionState

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);
}
Also used : SessionState(com.mapbox.services.android.navigation.v5.navigation.metrics.SessionState)

Aggregations

SessionState (com.mapbox.services.android.navigation.v5.navigation.metrics.SessionState)6 Date (java.util.Date)3 Location (android.location.Location)2 MetricsLocation (com.mapbox.services.android.navigation.v5.location.MetricsLocation)2 NonNull (android.support.annotation.NonNull)1 FeedbackEvent (com.mapbox.services.android.navigation.v5.navigation.metrics.FeedbackEvent)1 RerouteEvent (com.mapbox.services.android.navigation.v5.navigation.metrics.RerouteEvent)1 MetricsRouteProgress (com.mapbox.services.android.navigation.v5.routeprogress.MetricsRouteProgress)1