Skip to content

Commit 6e4bd2e

Browse files
committed
Merge branch 'fix-realtime-headsign' into dev-2.x
2 parents 4cd0239 + fb866cb commit 6e4bd2e

4 files changed

Lines changed: 84 additions & 38 deletions

File tree

src/main/java/org/opentripplanner/transit/model/network/TripPattern.java

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,12 +401,18 @@ public TripPattern getOriginalTripPattern() {
401401
return originalTripPattern;
402402
}
403403

404+
/**
405+
* Returns trip headsign from the scheduled timetables or from the original pattern's scheduled
406+
* timetables if this pattern is added by realtime and the stop sequence has not changed apart
407+
* from pickup/dropoff values.
408+
*
409+
* @return trip headsign
410+
*/
404411
public I18NString getTripHeadsign() {
405412
var tripTimes = scheduledTimetable.getRepresentativeTripTimes();
406-
if (tripTimes == null) {
407-
return null;
408-
}
409-
return tripTimes.getTrip().getHeadsign();
413+
return tripTimes == null
414+
? getTripHeadsignFromOriginalPattern()
415+
: getTripHeadSignFromTripTimes(tripTimes);
410416
}
411417

412418
public I18NString getStopHeadsign(int stopIndex) {
@@ -467,4 +473,30 @@ public boolean sameAs(@Nonnull TripPattern other) {
467473
public TripPatternBuilder copy() {
468474
return new TripPatternBuilder(this);
469475
}
476+
477+
/**
478+
* Checks if the stops in this trip pattern are the same as in the original pattern (if this trip
479+
* is added through a realtime update. The pickup and dropoff values don't have to be the same.
480+
*/
481+
private boolean containsSameStopsAsOriginalPattern() {
482+
return originalTripPattern != null && getStops().equals(originalTripPattern.getStops());
483+
}
484+
485+
/**
486+
* Helper method for getting the trip headsign from the {@link TripTimes}.
487+
*/
488+
private I18NString getTripHeadSignFromTripTimes(TripTimes tripTimes) {
489+
return tripTimes != null ? tripTimes.getTripHeadsign() : null;
490+
}
491+
492+
/**
493+
* Returns trip headsign from the original pattern if one exists.
494+
*/
495+
private I18NString getTripHeadsignFromOriginalPattern() {
496+
if (containsSameStopsAsOriginalPattern()) {
497+
var tripTimes = originalTripPattern.getScheduledTimetable().getRepresentativeTripTimes();
498+
return getTripHeadSignFromTripTimes(tripTimes);
499+
}
500+
return null;
501+
}
470502
}

src/main/java/org/opentripplanner/transit/model/timetable/TripTimes.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,13 @@ public List<String> getHeadsignVias(final int stop) {
212212
return List.of(headsignVias[stop]);
213213
}
214214

215+
/**
216+
* @return the whole trip's headsign. Individual stops can have different headsigns.
217+
*/
218+
public I18NString getTripHeadsign() {
219+
return trip.getHeadsign();
220+
}
221+
215222
/** @return the time in seconds after midnight that the vehicle arrives at the stop. */
216223
public int getScheduledArrivalTime(final int stop) {
217224
return scheduledArrivalTimes[stop] + timeShift;

src/test/java/org/opentripplanner/updater/trip/TimetableSnapshotSourceTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.junit.jupiter.params.provider.Arguments;
3535
import org.opentripplanner.ConstantsForTests;
3636
import org.opentripplanner.TestOtpModel;
37+
import org.opentripplanner.framework.i18n.NonLocalizedString;
3738
import org.opentripplanner.framework.time.ServiceDateUtils;
3839
import org.opentripplanner.model.PickDrop;
3940
import org.opentripplanner.model.Timetable;
@@ -669,6 +670,12 @@ public void scheduledTripWithSkippedAndNoData() {
669670
assertFalse(newTripPattern.canBoard(1));
670671
assertTrue(newTripPattern.canBoard(2));
671672

673+
assertEquals(new NonLocalizedString("foo"), newTripPattern.getTripHeadsign());
674+
assertEquals(
675+
newTripPattern.getOriginalTripPattern().getTripHeadsign(),
676+
newTripPattern.getTripHeadsign()
677+
);
678+
672679
final int newTimetableForTodayModifiedTripIndex = newTimetableForToday.getTripIndex(
673680
scheduledTripId
674681
);
Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
route_id,service_id,trip_id,shape_id,block_id,wheelchair_accessible,trip_bikes_allowed,direction_id
2-
1,alldays,1.1,,,1,,
3-
1,alldays,1.2,,,1,,
4-
1,alldays,1.3,,,1,,
5-
2,alldays,2.1,,,0,2,
6-
2,alldays,2.2,,,0,2,
7-
3,alldays,3.1,,,1,,
8-
3,alldays,3.2,,,1,,
9-
4,weekdays,4.1,4,,,,
10-
4,weekdays,4.2,4,,,,
11-
4,weekdays,4.3,4,,,,
12-
5,alldays,5.1,5,,,,
13-
6,alldays,6.1,,block.1,,,
14-
7,alldays,7.1,,block.1,,,
15-
6,alldays,6.2,,block.2,,,
16-
7,alldays,7.2,,block.2,,,
17-
8,alldays,8.1,,block.2,,,
18-
9,alldays,9.1,,,,1,
19-
10,alldays,10.1,,,,,
20-
10,alldays,10.2,,,,,
21-
10,alldays,10.3,,,,,
22-
10,alldays,10.4,,,,,
23-
10,alldays,10.5,,,,,
24-
11,alldays,11.1,,,,,
25-
12,alldays,12.1,,,,,
26-
13,alldays,13.1,,,,,
27-
14,alldays,14.1,,,,,
28-
14,alldays,14.2,,,,,
29-
15,alldays,15.1,5,,,,
30-
16,alldays,16.1,,,,,
31-
17,alldays,17.1,,,,,
32-
18,alldays,18.1,,,,,N
33-
18,alldays,18.1back,,,1,,S
34-
18,alldays,18.bogus,,,,,
1+
route_id,service_id,trip_id,shape_id,block_id,wheelchair_accessible,trip_bikes_allowed,direction_id,trip_headsign
2+
1,alldays,1.1,,,1,,,foo
3+
1,alldays,1.2,,,1,,,foo
4+
1,alldays,1.3,,,1,,,foo
5+
2,alldays,2.1,,,0,2,,foo
6+
2,alldays,2.2,,,0,2,,foo
7+
3,alldays,3.1,,,1,,,foo
8+
3,alldays,3.2,,,1,,,foo
9+
4,weekdays,4.1,4,,,,,foo
10+
4,weekdays,4.2,4,,,,,foo
11+
4,weekdays,4.3,4,,,,,foo
12+
5,alldays,5.1,5,,,,,foo
13+
6,alldays,6.1,,block.1,,,,foo
14+
7,alldays,7.1,,block.1,,,,foo
15+
6,alldays,6.2,,block.2,,,,foo
16+
7,alldays,7.2,,block.2,,,,foo
17+
8,alldays,8.1,,block.2,,,,foo
18+
9,alldays,9.1,,,,1,,foo
19+
10,alldays,10.1,,,,,,foo
20+
10,alldays,10.2,,,,,,foo
21+
10,alldays,10.3,,,,,,foo
22+
10,alldays,10.4,,,,,,foo
23+
10,alldays,10.5,,,,,,foo
24+
11,alldays,11.1,,,,,,foo
25+
12,alldays,12.1,,,,,,foo
26+
13,alldays,13.1,,,,,,foo
27+
14,alldays,14.1,,,,,,foo
28+
14,alldays,14.2,,,,,,foo
29+
15,alldays,15.1,5,,,,,foo
30+
16,alldays,16.1,,,,,,foo
31+
17,alldays,17.1,,,,,,foo
32+
18,alldays,18.1,,,,,N,foo
33+
18,alldays,18.1back,,,1,,S,foo
34+
18,alldays,18.bogus,,,,,,foo

0 commit comments

Comments
 (0)