Skip to content

Commit

Permalink
[WIP] merge and refactor 5476d10 (#857) changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Guardiola31337 committed Apr 16, 2018
1 parent 4219abe commit b6ca9ff
Showing 1 changed file with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ static void disable() {
}

static void arriveEvent(SessionState sessionState, RouteProgress routeProgress, Location location) {
NavigationEventFactory factory = new NavigationEventFactory();
Date startTimestamp = obtainStartTimestamp(sessionState);
// TODO We should generate the Nav event spec version somehow. Should be managed and generated by the Events
// library?
int hardcodedEventVersion = 7;
MetricsRouteProgress metricsRouteProgress = new MetricsRouteProgress(routeProgress);
int absoluteDistanceToDestination = DistanceUtils.calculateAbsoluteDistance(location, metricsRouteProgress);
NavigationMetadata metadata = new NavigationMetadata(
sessionState.startTimestamp(),
startTimestamp,
(int) (sessionState.eventRouteDistanceCompleted() + routeProgress.distanceTraveled()),
(int) routeProgress.distanceRemaining(),
(int) routeProgress.durationRemaining(),
Expand Down Expand Up @@ -90,17 +90,19 @@ static void arriveEvent(SessionState sessionState, RouteProgress routeProgress,
metadata.setPercentTimeInForeground(sessionState.percentInForeground());
metadata.setPercentTimeInPortrait(sessionState.percentInPortrait());
NavigationState state = new NavigationState(metadata);
NavigationEventFactory factory = new NavigationEventFactory();
Event arriveEvent = factory.createNavigationEvent(Event.Type.NAV_ARRIVE, state);
mapboxTelemetry.push(arriveEvent);
}

static void cancelEvent(SessionState sessionState, MetricsRouteProgress metricProgress, Location location) {
Date startTimestamp = obtainStartTimestamp(sessionState);
// TODO We should generate the Nav event spec version somehow. Should be managed and generated by the Events
// library?
int hardcodedEventVersion = 7;
int absoluteDistanceToDestination = DistanceUtils.calculateAbsoluteDistance(location, metricProgress);
NavigationMetadata metadata = new NavigationMetadata(
sessionState.startTimestamp(),
startTimestamp,
(int) (sessionState.eventRouteDistanceCompleted() + metricProgress.getDistanceTraveled()),
metricProgress.getDistanceRemaining(),
metricProgress.getDurationRemaining(),
Expand Down Expand Up @@ -141,13 +143,13 @@ static void cancelEvent(SessionState sessionState, MetricsRouteProgress metricPr
}

static void departEvent(SessionState sessionState, MetricsRouteProgress metricProgress, Location location) {
NavigationEventFactory factory = new NavigationEventFactory();
Date startTimestamp = obtainStartTimestamp(sessionState);
// TODO We should generate the Nav event spec version somehow. Should be managed and generated by the Events
// library?
int hardcodedEventVersion = 7;
int absoluteDistanceToDestination = DistanceUtils.calculateAbsoluteDistance(location, metricProgress);
NavigationMetadata metadata = new NavigationMetadata(
sessionState.startTimestamp(),
startTimestamp,
metricProgress.getDistanceTraveled(),
metricProgress.getDistanceRemaining(),
metricProgress.getDurationRemaining(),
Expand Down Expand Up @@ -176,20 +178,21 @@ static void departEvent(SessionState sessionState, MetricsRouteProgress metricPr
metadata.setPercentTimeInForeground(sessionState.percentInForeground());
metadata.setPercentTimeInPortrait(sessionState.percentInPortrait());
NavigationState state = new NavigationState(metadata);
NavigationEventFactory factory = new NavigationEventFactory();
Event departEvent = factory.createNavigationEvent(Event.Type.NAV_DEPART, state);
mapboxTelemetry.push(departEvent);
}

static void rerouteEvent(RerouteEvent rerouteEvent, MetricsRouteProgress metricProgress,
Location location) {

SessionState sessionState = rerouteEvent.getSessionState();
Date startTimestamp = obtainStartTimestamp(sessionState);
// TODO We should generate the Nav event spec version somehow. Should be managed and generated by the Events
// library?
int hardcodedEventVersion = 7;
int absoluteDistanceToDestination = DistanceUtils.calculateAbsoluteDistance(location, metricProgress);
NavigationMetadata metadata = new NavigationMetadata(
sessionState.startTimestamp(),
startTimestamp,
(int) sessionState.eventRouteDistanceCompleted(),
sessionState.eventRouteProgress().getDistanceRemaining(),
sessionState.eventRouteProgress().getDurationRemaining(),
Expand Down Expand Up @@ -260,12 +263,13 @@ static void rerouteEvent(RerouteEvent rerouteEvent, MetricsRouteProgress metricP

static void feedbackEvent(SessionState sessionState, MetricsRouteProgress metricProgress, Location location,
String description, String feedbackType, String screenshot, String feedbackSource) {
Date startTimestamp = obtainStartTimestamp(sessionState);
// TODO We should generate the Nav event spec version somehow. Should be managed and generated by the Events
// library?
int hardcodedEventVersion = 7;
int absoluteDistanceToDestination = DistanceUtils.calculateAbsoluteDistance(location, metricProgress);
NavigationMetadata metadata = new NavigationMetadata(
sessionState.startTimestamp(),
startTimestamp,
(int) sessionState.eventRouteDistanceCompleted(),
sessionState.eventRouteProgress().getDistanceRemaining(),
sessionState.eventRouteProgress().getDurationRemaining(),
Expand Down Expand Up @@ -335,6 +339,13 @@ static Event turnstileEvent() {
return navTurnstileEvent;
}

private static Date obtainStartTimestamp(SessionState sessionState) {
if (sessionState.startTimestamp() == null) {
return new Date();
}
return sessionState.startTimestamp();
}

private static void updateRouteProgressSessionData(MetricsRouteProgress routeProgress) {
upcomingName = routeProgress.getUpcomingStepName();
upcomingInstruction = routeProgress.getUpcomingStepInstruction();
Expand Down

0 comments on commit b6ca9ff

Please sign in to comment.