Skip to content

Commit

Permalink
MTA-99 support decreasing stop times in real-time
Browse files Browse the repository at this point in the history
  • Loading branch information
sheldonabrown committed Mar 9, 2024
1 parent ec78499 commit 4e02ad2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/main/java/org/opentripplanner/model/Timetable.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.opentripplanner.routing.trippattern.TripTimes;
import org.opentripplanner.updater.stoptime.TimetableSnapshotSource;
import org.opentripplanner.updater.stoptime.TimetableSnapshotSourceMetrics;
import org.opentripplanner.util.OTPFeature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -375,6 +376,9 @@ public TripTimes createUpdatedTripTimes(TimetableSnapshotSourceMetrics metrics,
return null;
}
}
if (OTPFeature.SmoothRealtime.isOn()) {
newTimes.smoothIncreasing();
}
if (!newTimes.timesIncreasing()) {
LOG.trace("TripTimes are non-increasing after applying GTFS-RT delay propagation to trip {}.", tripId);
metrics.addDecreasingTimes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -575,4 +575,29 @@ public HashCode semanticHash(final HashFunction hashFunction) {
}
return hasher.hash();
}

public boolean smoothIncreasing() {
final int nStops = scheduledArrivalTimes.length;
int prevDep = -1;
boolean correct = true;
for (int s = 0; s < nStops; s++) {
int arr = getArrivalTime(s);
int dep = getDepartureTime(s);

if (prevDep > arr) {
LOG.trace("Negative running time in TripTimes after stop index {}.", s);
updateArrivalTime(s, prevDep);
arr = prevDep;
correct = false;
}
if (dep < arr) {
LOG.trace("Negative dwell time in TripTimes at stop index {}.", s);
updateDepartureTime(s, arr);
dep = arr;
correct = false;
}
prevDep = dep;
}
return correct;
}
}
5 changes: 4 additions & 1 deletion src/main/java/org/opentripplanner/util/OTPFeature.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ public enum OTPFeature {
SandboxAPIParkAndRideApi(false),
TransferAnalyzer(false),
// graph scanning -- set to false for upstream merge
AutoScan(true);
AutoScan(true),
// make minor corrects to real-time arrivals and departures when
// applying to Timetable
SmoothRealtime(true);
private static final Logger LOG = LoggerFactory.getLogger(OTPFeature.class);

OTPFeature(boolean defaultEnabled) {
Expand Down

0 comments on commit 4e02ad2

Please sign in to comment.