Skip to content

Commit

Permalink
feat(TrackingLocation): Add fields for deviation + loc accuracy.
Browse files Browse the repository at this point in the history
  • Loading branch information
binh-dam-ibigroup committed Oct 3, 2024
1 parent 2a87ce7 commit 65b62db
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ private static TrackingResponse doUpdateTracking(Request request, TripTrackingDa
);
TripStatus tripStatus = TripStatus.getTripStatus(travelerPosition);
trackedJourney.lastLocation().tripStatus = tripStatus;
trackedJourney.lastLocation().deviationMeters = travelerPosition.getDeviationMeters();

if (create) {
Persistence.trackedJourneys.create(trackedJourney);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,15 @@ public class TrackingLocation {

public Date timestamp;

/** Deviation or on-time status computed for this location. */
public TripStatus tripStatus;

/** FIXME: Device location accuracy, reported by the device in a unit TBD. For reporting only. */
public Double locationAccuracy;

/** Perpendicular deviation, computed in meters, to the path closest to this location. */
public Double deviationMeters;

public TrackingLocation() {
// Needed for deserializing objects.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import static org.opentripplanner.middleware.triptracker.ManageLegTraversal.getExpectedLeg;
import static org.opentripplanner.middleware.triptracker.ManageLegTraversal.getNextLeg;
import static org.opentripplanner.middleware.triptracker.ManageLegTraversal.getSegmentFromPosition;
import static org.opentripplanner.middleware.utils.GeometryUtils.getDistanceFromLine;

public class TravelerPosition {

Expand Down Expand Up @@ -81,4 +82,9 @@ public TravelerPosition(Leg nextLeg, Instant currentTime) {
this.nextLeg = nextLeg;
this.currentTime = currentTime;
}

/** Computes the current deviation in meters from the expected itinerary. */
public double getDeviationMeters() {
return getDistanceFromLine(legSegmentFromPosition.start, legSegmentFromPosition.end, currentPosition);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,7 @@ public static Instant getSegmentStartTime(TravelerPosition travelerPosition) {
* Checks if the traveler's position is with an acceptable distance of the mode type.
*/
private static boolean isWithinModeRadius(TravelerPosition travelerPosition) {
double distanceFromExpected = getDistanceFromLine(
travelerPosition.legSegmentFromPosition.start,
travelerPosition.legSegmentFromPosition.end,
travelerPosition.currentPosition
);
double distanceFromExpected = travelerPosition.getDeviationMeters();
double modeBoundary = getModeRadius(travelerPosition.legSegmentFromPosition.mode);
return distanceFromExpected <= modeBoundary;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static double getDistance(Coordinates start, Coordinates end) {
}

/**
* Get the distance between a line and point.
* Get the distance in meters between a line and point.
*/
public static double getDistanceFromLine(Coordinates start, Coordinates end, Coordinates traveler) {
double[] startXY = convertLatLonToXY(start.lat, start.lon);
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/latest-spark-swagger-output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2772,6 +2772,12 @@ definitions:
- "AHEAD_OF_SCHEDULE"
- "ENDED"
- "DEVIATED"
locationAccuracy:
type: "number"
format: "double"
deviationMeters:
type: "number"
format: "double"
TrackingResponse:
type: "object"
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,11 @@ void canStartThenUpdateOngoingJourney(Coordinates coords, String instruction, St
assertNotNull(trackResponse.journeyId);
trackedJourney = Persistence.trackedJourneys.getById(trackResponse.journeyId);

// Check that deviation fields get computed and recorded.
Double deviationMeters = trackedJourney.lastLocation().deviationMeters;
assertNotNull(deviationMeters);
assertNotEquals(0, deviationMeters);

// Second request to update a journey
response = makeRequest(
TRACK_TRIP_PATH,
Expand Down

0 comments on commit 65b62db

Please sign in to comment.