Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'fix-realtime-headsign' into dev-2.x
Browse files Browse the repository at this point in the history
vesameskanen committed Feb 20, 2023
2 parents 4cd0239 + fb866cb commit 6e4bd2e
Showing 4 changed files with 84 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -401,12 +401,18 @@ public TripPattern getOriginalTripPattern() {
return originalTripPattern;
}

/**
* Returns trip headsign from the scheduled timetables or from the original pattern's scheduled
* timetables if this pattern is added by realtime and the stop sequence has not changed apart
* from pickup/dropoff values.
*
* @return trip headsign
*/
public I18NString getTripHeadsign() {
var tripTimes = scheduledTimetable.getRepresentativeTripTimes();
if (tripTimes == null) {
return null;
}
return tripTimes.getTrip().getHeadsign();
return tripTimes == null
? getTripHeadsignFromOriginalPattern()
: getTripHeadSignFromTripTimes(tripTimes);
}

public I18NString getStopHeadsign(int stopIndex) {
@@ -467,4 +473,30 @@ public boolean sameAs(@Nonnull TripPattern other) {
public TripPatternBuilder copy() {
return new TripPatternBuilder(this);
}

/**
* Checks if the stops in this trip pattern are the same as in the original pattern (if this trip
* is added through a realtime update. The pickup and dropoff values don't have to be the same.
*/
private boolean containsSameStopsAsOriginalPattern() {
return originalTripPattern != null && getStops().equals(originalTripPattern.getStops());
}

/**
* Helper method for getting the trip headsign from the {@link TripTimes}.
*/
private I18NString getTripHeadSignFromTripTimes(TripTimes tripTimes) {
return tripTimes != null ? tripTimes.getTripHeadsign() : null;
}

/**
* Returns trip headsign from the original pattern if one exists.
*/
private I18NString getTripHeadsignFromOriginalPattern() {
if (containsSameStopsAsOriginalPattern()) {
var tripTimes = originalTripPattern.getScheduledTimetable().getRepresentativeTripTimes();
return getTripHeadSignFromTripTimes(tripTimes);
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -212,6 +212,13 @@ public List<String> getHeadsignVias(final int stop) {
return List.of(headsignVias[stop]);
}

/**
* @return the whole trip's headsign. Individual stops can have different headsigns.
*/
public I18NString getTripHeadsign() {
return trip.getHeadsign();
}

/** @return the time in seconds after midnight that the vehicle arrives at the stop. */
public int getScheduledArrivalTime(final int stop) {
return scheduledArrivalTimes[stop] + timeShift;
Original file line number Diff line number Diff line change
@@ -34,6 +34,7 @@
import org.junit.jupiter.params.provider.Arguments;
import org.opentripplanner.ConstantsForTests;
import org.opentripplanner.TestOtpModel;
import org.opentripplanner.framework.i18n.NonLocalizedString;
import org.opentripplanner.framework.time.ServiceDateUtils;
import org.opentripplanner.model.PickDrop;
import org.opentripplanner.model.Timetable;
@@ -669,6 +670,12 @@ public void scheduledTripWithSkippedAndNoData() {
assertFalse(newTripPattern.canBoard(1));
assertTrue(newTripPattern.canBoard(2));

assertEquals(new NonLocalizedString("foo"), newTripPattern.getTripHeadsign());
assertEquals(
newTripPattern.getOriginalTripPattern().getTripHeadsign(),
newTripPattern.getTripHeadsign()
);

final int newTimetableForTodayModifiedTripIndex = newTimetableForToday.getTripIndex(
scheduledTripId
);
68 changes: 34 additions & 34 deletions src/test/resources/testagency/trips.txt
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
route_id,service_id,trip_id,shape_id,block_id,wheelchair_accessible,trip_bikes_allowed,direction_id
1,alldays,1.1,,,1,,
1,alldays,1.2,,,1,,
1,alldays,1.3,,,1,,
2,alldays,2.1,,,0,2,
2,alldays,2.2,,,0,2,
3,alldays,3.1,,,1,,
3,alldays,3.2,,,1,,
4,weekdays,4.1,4,,,,
4,weekdays,4.2,4,,,,
4,weekdays,4.3,4,,,,
5,alldays,5.1,5,,,,
6,alldays,6.1,,block.1,,,
7,alldays,7.1,,block.1,,,
6,alldays,6.2,,block.2,,,
7,alldays,7.2,,block.2,,,
8,alldays,8.1,,block.2,,,
9,alldays,9.1,,,,1,
10,alldays,10.1,,,,,
10,alldays,10.2,,,,,
10,alldays,10.3,,,,,
10,alldays,10.4,,,,,
10,alldays,10.5,,,,,
11,alldays,11.1,,,,,
12,alldays,12.1,,,,,
13,alldays,13.1,,,,,
14,alldays,14.1,,,,,
14,alldays,14.2,,,,,
15,alldays,15.1,5,,,,
16,alldays,16.1,,,,,
17,alldays,17.1,,,,,
18,alldays,18.1,,,,,N
18,alldays,18.1back,,,1,,S
18,alldays,18.bogus,,,,,
route_id,service_id,trip_id,shape_id,block_id,wheelchair_accessible,trip_bikes_allowed,direction_id,trip_headsign
1,alldays,1.1,,,1,,,foo
1,alldays,1.2,,,1,,,foo
1,alldays,1.3,,,1,,,foo
2,alldays,2.1,,,0,2,,foo
2,alldays,2.2,,,0,2,,foo
3,alldays,3.1,,,1,,,foo
3,alldays,3.2,,,1,,,foo
4,weekdays,4.1,4,,,,,foo
4,weekdays,4.2,4,,,,,foo
4,weekdays,4.3,4,,,,,foo
5,alldays,5.1,5,,,,,foo
6,alldays,6.1,,block.1,,,,foo
7,alldays,7.1,,block.1,,,,foo
6,alldays,6.2,,block.2,,,,foo
7,alldays,7.2,,block.2,,,,foo
8,alldays,8.1,,block.2,,,,foo
9,alldays,9.1,,,,1,,foo
10,alldays,10.1,,,,,,foo
10,alldays,10.2,,,,,,foo
10,alldays,10.3,,,,,,foo
10,alldays,10.4,,,,,,foo
10,alldays,10.5,,,,,,foo
11,alldays,11.1,,,,,,foo
12,alldays,12.1,,,,,,foo
13,alldays,13.1,,,,,,foo
14,alldays,14.1,,,,,,foo
14,alldays,14.2,,,,,,foo
15,alldays,15.1,5,,,,,foo
16,alldays,16.1,,,,,,foo
17,alldays,17.1,,,,,,foo
18,alldays,18.1,,,,,N,foo
18,alldays,18.1back,,,1,,S,foo
18,alldays,18.bogus,,,,,,foo

0 comments on commit 6e4bd2e

Please sign in to comment.