Search in sources :

Example 1 with RerouteEvent

use of com.mapbox.services.android.navigation.v5.navigation.metrics.RerouteEvent in project mapbox-navigation-android by mapbox.

the class NavigationTelemetry method checkRerouteQueue.

private void checkRerouteQueue() {
    Iterator<RerouteEvent> iterator = queuedRerouteEvents.listIterator();
    while (iterator.hasNext()) {
        RerouteEvent rerouteEvent = iterator.next();
        if (shouldSendEvent(rerouteEvent.getSessionState())) {
            sendRerouteEvent(rerouteEvent);
            iterator.remove();
        }
    }
}
Also used : RerouteEvent(com.mapbox.services.android.navigation.v5.navigation.metrics.RerouteEvent)

Example 2 with RerouteEvent

use of com.mapbox.services.android.navigation.v5.navigation.metrics.RerouteEvent in project mapbox-navigation-android by mapbox.

the class NavigationTelemetry method queueRerouteEvent.

private void queueRerouteEvent() {
    updateLifecyclePercentages();
    // Create a new session state given the current navigation session
    Date eventDate = new Date();
    SessionState rerouteEventSessionState = navigationSessionState.toBuilder().eventDate(eventDate).eventRouteProgress(metricProgress).eventLocation(metricLocation.getLocation()).secondsSinceLastReroute(getSecondsSinceLastReroute(eventDate)).mockLocation(metricLocation.getLocation().getProvider().equals(MOCK_PROVIDER)).build();
    RerouteEvent rerouteEvent = new RerouteEvent(rerouteEventSessionState);
    queuedRerouteEvents.add(rerouteEvent);
}
Also used : SessionState(com.mapbox.services.android.navigation.v5.navigation.metrics.SessionState) Date(java.util.Date) RerouteEvent(com.mapbox.services.android.navigation.v5.navigation.metrics.RerouteEvent)

Example 3 with RerouteEvent

use of com.mapbox.services.android.navigation.v5.navigation.metrics.RerouteEvent in project mapbox-navigation-android by mapbox.

the class NavigationTelemetry method sendRerouteEvent.

private void sendRerouteEvent(RerouteEvent rerouteEvent) {
    // If there isn't an updated geometry, don't send
    if (rerouteEvent.getNewRouteGeometry() == null || rerouteEvent.getSessionState().startTimestamp() == null) {
        return;
    }
    // Create arrays with locations from before / after the reroute occurred
    List<Location> beforeLocations = createLocationListBeforeEvent(rerouteEvent.getSessionState().eventDate());
    List<Location> afterLocations = createLocationListAfterEvent(rerouteEvent.getSessionState().eventDate());
    // Update session state with locations after feedback
    SessionState rerouteSessionState = rerouteEvent.getSessionState().toBuilder().beforeEventLocations(beforeLocations).afterEventLocations(afterLocations).build();
    // Set the updated session state
    rerouteEvent.setRerouteSessionState(rerouteSessionState);
    NavigationMetricsWrapper.rerouteEvent(rerouteEvent, metricProgress, rerouteEvent.getSessionState().eventLocation());
}
Also used : SessionState(com.mapbox.services.android.navigation.v5.navigation.metrics.SessionState) MetricsLocation(com.mapbox.services.android.navigation.v5.location.MetricsLocation) Location(android.location.Location)

Example 4 with RerouteEvent

use of com.mapbox.services.android.navigation.v5.navigation.metrics.RerouteEvent in project mapbox-navigation-android by mapbox.

the class NavigationTelemetry method updateLastRerouteEvent.

private void updateLastRerouteEvent(DirectionsRoute newDirectionsRoute) {
    if (!queuedRerouteEvents.isEmpty()) {
        RerouteEvent rerouteEvent = queuedRerouteEvents.get(queuedRerouteEvents.size() - 1);
        List<Point> geometryPositions = PolylineUtils.decode(newDirectionsRoute.geometry(), Constants.PRECISION_6);
        PolylineUtils.encode(geometryPositions, Constants.PRECISION_5);
        rerouteEvent.setNewRouteGeometry(PolylineUtils.encode(geometryPositions, Constants.PRECISION_5));
        int newDistanceRemaining = newDirectionsRoute.distance() == null ? 0 : newDirectionsRoute.distance().intValue();
        rerouteEvent.setNewDistanceRemaining(newDistanceRemaining);
        int newDurationRemaining = newDirectionsRoute.duration() == null ? 0 : newDirectionsRoute.duration().intValue();
        rerouteEvent.setNewDurationRemaining(newDurationRemaining);
    }
}
Also used : Point(com.mapbox.geojson.Point) Point(com.mapbox.geojson.Point) RerouteEvent(com.mapbox.services.android.navigation.v5.navigation.metrics.RerouteEvent)

Example 5 with RerouteEvent

use of com.mapbox.services.android.navigation.v5.navigation.metrics.RerouteEvent 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

RerouteEvent (com.mapbox.services.android.navigation.v5.navigation.metrics.RerouteEvent)3 SessionState (com.mapbox.services.android.navigation.v5.navigation.metrics.SessionState)3 Location (android.location.Location)1 Point (com.mapbox.geojson.Point)1 MetricsLocation (com.mapbox.services.android.navigation.v5.location.MetricsLocation)1 Date (java.util.Date)1