Skip to content

Commit 0e2fab3

Browse files
Merge pull request #6846 from ibi-group/remove-repeated-stops
Remove GTFS "remove repeated stops" feature
2 parents 9409743 + cbedeab commit 0e2fab3

File tree

15 files changed

+8
-134
lines changed

15 files changed

+8
-134
lines changed

application/src/ext-test/java/org/opentripplanner/ext/flex/trip/ScheduledDeviatedTripIntegrationTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,13 @@ void flexTripInTransitMode() {
113113
assertEquals("yz85", leg.to().stop.getId().getId());
114114

115115
var intermediateStops = leg.listIntermediateStops();
116-
assertEquals(1, intermediateStops.size());
116+
assertEquals(2, intermediateStops.size());
117117
assertEquals("zone_1", intermediateStops.get(0).place.stop.getId().getId());
118118

119119
EncodedPolyline legGeometry = EncodedPolyline.encode(leg.legGeometry());
120120
assertThatPolylinesAreEqual(
121121
legGeometry.points(),
122-
"kfsmEjojcOa@eBRKfBfHR|ALjBBhVArMG|OCrEGx@OhAKj@a@tAe@hA]l@MPgAnAgw@nr@cDxCm@t@c@t@c@x@_@~@]pAyAdIoAhG}@lE{AzHWhAtt@t~Aj@tAb@~AXdBHn@FlBC`CKnA_@nC{CjOa@dCOlAEz@E|BRtUCbCQ~CWjD??qBvXBl@kBvWOzAc@dDOx@sHv]aIG?q@@c@ZaB\\mA"
122+
"kfsmEjojcOa@eBRKfBfHR|ALjBBhVArMG|OCrEGx@OhAKj@a@tAe@hA]l@MPgAnAgw@nr@cDxCm@t@c@t@c@x@_@~@]pAyAdIoAhG}@lE{AzHWhAtt@t~Aj@tAb@~AXdBHn@FlBC`CKnA_@nC{CjOa@dCOlAEz@E|BRtUCbCQ~CWjD??????qBvXBl@kBvWOzAc@dDOx@sHv]aIG?q@@c@ZaB\\mA"
123123
);
124124
}
125125

@@ -136,7 +136,7 @@ void shouldNotInterpolateFlexTimes() {
136136
var feedId = timetableRepository.getFeedIds().iterator().next();
137137
var pattern = timetableRepository.getTripPatternForId(new FeedScopedId(feedId, "090z:0:01"));
138138

139-
assertEquals(3, pattern.numberOfStops());
139+
assertEquals(4, pattern.numberOfStops());
140140

141141
var tripTimes = pattern.getScheduledTimetable().getTripTimes().getFirst();
142142
var arrivalTime = tripTimes.getArrivalTime(1);

application/src/main/java/org/opentripplanner/graph_builder/module/ValidateAndInterpolateStopTimesForEachTrip.java

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package org.opentripplanner.graph_builder.module;
22

3-
import gnu.trove.list.TIntList;
4-
import gnu.trove.list.array.TIntArrayList;
53
import java.util.ArrayList;
6-
import java.util.Iterator;
74
import java.util.List;
85
import org.opentripplanner.ext.flex.trip.FlexTrip;
96
import org.opentripplanner.framework.application.OTPFeature;
@@ -16,7 +13,6 @@
1613
import org.opentripplanner.graph_builder.issues.HopZeroTime;
1714
import org.opentripplanner.graph_builder.issues.NegativeDwellTime;
1815
import org.opentripplanner.graph_builder.issues.NegativeHopTime;
19-
import org.opentripplanner.graph_builder.issues.RepeatedStops;
2016
import org.opentripplanner.model.StopTime;
2117
import org.opentripplanner.model.TripStopTimes;
2218
import org.opentripplanner.transit.model.basic.TransitMode;
@@ -41,18 +37,15 @@ public class ValidateAndInterpolateStopTimesForEachTrip {
4137

4238
private final TripStopTimes stopTimesByTrip;
4339
private final boolean interpolate;
44-
private final boolean removeRepeatedStops;
4540
private final DataImportIssueStore issueStore;
4641

4742
public ValidateAndInterpolateStopTimesForEachTrip(
4843
TripStopTimes stopTimesByTrip,
4944
boolean interpolate,
50-
boolean removeRepeatedStops,
5145
DataImportIssueStore issueStore
5246
) {
5347
this.stopTimesByTrip = stopTimesByTrip;
5448
this.interpolate = interpolate;
55-
this.removeRepeatedStops = removeRepeatedStops;
5649
this.issueStore = issueStore;
5750
}
5851

@@ -70,12 +63,7 @@ public void run() {
7063
if (OTPFeature.FlexRouting.isOff()) {
7164
stopTimes.removeIf(st -> !(st.getStop() instanceof RegularStop));
7265
}
73-
74-
// Stop times frequently contain duplicate, missing, or incorrect entries. Repair them.
75-
TIntList removedStopSequences = removeRepeatedStops(stopTimes);
76-
if (!removedStopSequences.isEmpty()) {
77-
issueStore.add(new RepeatedStops(trip, removedStopSequences));
78-
}
66+
// Stop times frequently contain missing, or incorrect entries. Repair them.
7967
if (!filterStopTimes(stopTimes)) {
8068
stopTimesByTrip.replace(trip, List.of());
8169
} else if (interpolate) {
@@ -93,47 +81,6 @@ public void run() {
9381
LOG.info(progress.completeMessage());
9482
}
9583

96-
/**
97-
* Filter out any series of stop times that refer to the same stop. This is very inefficient in an
98-
* array-backed list, but we are assuming that this is a rare occurrence. The alternative is to
99-
* copy every list of stop times during filtering.
100-
* <p>
101-
*
102-
* @return whether any repeated stops were filtered out.
103-
*/
104-
private TIntList removeRepeatedStops(List<StopTime> stopTimes) {
105-
StopTime prev = null;
106-
Iterator<StopTime> it = stopTimes.iterator();
107-
TIntList stopSequencesRemoved = new TIntArrayList();
108-
while (it.hasNext()) {
109-
StopTime st = it.next();
110-
if (prev != null) {
111-
if (prev.getStop().equals(st.getStop())) {
112-
if (removeRepeatedStops) {
113-
// Merge the two stop times, making sure we're not throwing out a stop time with times in
114-
// favor of an interpolated stop time. Keep the arrival time of the previous stop, unless
115-
// it didn't have an arrival time, in which case replace it with the arrival time of this
116-
// stop time. This is particularly important at the last stop in a route (see issue #2220)
117-
if (prev.getArrivalTime() == StopTime.MISSING_VALUE) {
118-
prev.setArrivalTime(st.getArrivalTime());
119-
}
120-
121-
// prefer to replace with the departure time of this stop time, unless this stop time has
122-
// no departure time
123-
if (st.getDepartureTime() != StopTime.MISSING_VALUE) {
124-
prev.setDepartureTime(st.getDepartureTime());
125-
}
126-
127-
it.remove();
128-
}
129-
stopSequencesRemoved.add(st.getStopSequence());
130-
}
131-
}
132-
prev = st;
133-
}
134-
return stopSequencesRemoved;
135-
}
136-
13784
/**
13885
* Scan through the given list, looking for clearly incorrect series of stop times. This includes
13986
* duplicate times (0-time hops), as well as negative, fast or slow hops. {@link DataImportIssue}s

application/src/main/java/org/opentripplanner/gtfs/config/GtfsDefaultParameters.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,28 @@
1111
*/
1212
public sealed class GtfsDefaultParameters permits GtfsFeedParameters {
1313

14-
private static final boolean DEFAULT_REMOVE_REPEATED_STOPS = true;
1514
private static final boolean DEFAULT_DISCARD_MIN_TRANSFER_TIMES = false;
1615
private static final boolean DEFAULT_BLOCK_BASED_INTERLINING = true;
1716
private static final int DEFAULT_MAX_INTERLINE_DISTANCE = 200;
1817

1918
public static final GtfsDefaultParameters DEFAULT = new GtfsDefaultParameters(
20-
DEFAULT_REMOVE_REPEATED_STOPS,
2119
StopTransferPriority.defaultValue(),
2220
DEFAULT_DISCARD_MIN_TRANSFER_TIMES,
2321
DEFAULT_BLOCK_BASED_INTERLINING,
2422
DEFAULT_MAX_INTERLINE_DISTANCE
2523
);
2624

27-
private final boolean removeRepeatedStops;
2825
private final StopTransferPriority stationTransferPreference;
2926
private final boolean discardMinTransferTimes;
3027
private final boolean blockBasedInterlining;
3128
private final int maxInterlineDistance;
3229

3330
protected GtfsDefaultParameters(
34-
boolean removeRepeatedStops,
3531
StopTransferPriority stationTransferPreference,
3632
boolean discardMinTransferTimes,
3733
boolean blockBasedInterlining,
3834
int maxInterlineDistance
3935
) {
40-
this.removeRepeatedStops = removeRepeatedStops;
4136
this.stationTransferPreference = Objects.requireNonNull(stationTransferPreference);
4237
this.discardMinTransferTimes = discardMinTransferTimes;
4338
this.blockBasedInterlining = blockBasedInterlining;
@@ -46,7 +41,6 @@ protected GtfsDefaultParameters(
4641

4742
GtfsDefaultParameters(GtfsDefaultParametersBuilder builder) {
4843
this(
49-
builder.removeRepeatedStops(),
5044
builder.stationTransferPreference(),
5145
builder.discardMinTransferTimes(),
5246
builder.blockBasedInterlining(),
@@ -65,10 +59,6 @@ public GtfsFeedParametersBuilder withFeedInfo() {
6559
return new GtfsFeedParametersBuilder(this);
6660
}
6761

68-
public boolean removeRepeatedStops() {
69-
return removeRepeatedStops;
70-
}
71-
7262
public StopTransferPriority stationTransferPreference() {
7363
return stationTransferPreference;
7464
}
@@ -106,7 +96,6 @@ public String toString() {
10696

10797
protected ToStringBuilder toStringAppend(ToStringBuilder builder) {
10898
return builder
109-
.addBool("removeRepeatedStops", removeRepeatedStops, DEFAULT_REMOVE_REPEATED_STOPS)
11099
.addEnum(
111100
"stationTransferPreference",
112101
stationTransferPreference,

application/src/main/java/org/opentripplanner/gtfs/config/GtfsDefaultParametersBuilder.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@
44

55
public class GtfsDefaultParametersBuilder {
66

7-
private boolean removeRepeatedStops;
87
private StopTransferPriority stationTransferPreference;
98
private boolean discardMinTransferTimes;
109
private boolean blockBasedInterlining;
1110
private int maxInterlineDistance;
1211

1312
public GtfsDefaultParametersBuilder(GtfsDefaultParameters original) {
14-
this.removeRepeatedStops = original.removeRepeatedStops();
1513
this.stationTransferPreference = original.stationTransferPreference();
1614
this.discardMinTransferTimes = original.discardMinTransferTimes();
1715
this.blockBasedInterlining = original.blockBasedInterlining();
@@ -29,15 +27,6 @@ StopTransferPriority stationTransferPreference() {
2927
return stationTransferPreference;
3028
}
3129

32-
public GtfsDefaultParametersBuilder withRemoveRepeatedStops(boolean value) {
33-
this.removeRepeatedStops = value;
34-
return this;
35-
}
36-
37-
boolean removeRepeatedStops() {
38-
return removeRepeatedStops;
39-
}
40-
4130
public GtfsDefaultParametersBuilder withDiscardMinTransferTimes(boolean value) {
4231
this.discardMinTransferTimes = value;
4332
return this;

application/src/main/java/org/opentripplanner/gtfs/config/GtfsFeedParameters.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,12 @@ public final class GtfsFeedParameters extends GtfsDefaultParameters implements D
2222
public GtfsFeedParameters(
2323
@Nullable String feedId,
2424
URI source,
25-
boolean removeRepeatedStops,
2625
StopTransferPriority stationTransferPreference,
2726
boolean discardMinTransferTimes,
2827
boolean blockBasedInterlining,
2928
int maxInterlineDistance
3029
) {
3130
super(
32-
removeRepeatedStops,
3331
stationTransferPreference,
3432
discardMinTransferTimes,
3533
blockBasedInterlining,

application/src/main/java/org/opentripplanner/gtfs/config/GtfsFeedParametersBuilder.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ public GtfsFeedParameters build() {
3838
return new GtfsFeedParameters(
3939
feedId,
4040
source,
41-
removeRepeatedStops(),
4241
stationTransferPreference(),
4342
discardMinTransferTimes(),
4443
blockBasedInterlining(),

application/src/main/java/org/opentripplanner/gtfs/graphbuilder/GtfsModule.java

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,7 @@ public void buildGraph() {
160160
builder.getFlexTripsById().addAll(FlexTripsMapper.createFlexTrips(builder, issueStore));
161161
}
162162

163-
validateAndInterpolateStopTimesForEachTrip(
164-
builder.getStopTimesSortedByTrip(),
165-
issueStore,
166-
gtfsBundle.parameters().removeRepeatedStops()
167-
);
163+
validateAndInterpolateStopTimesForEachTrip(builder.getStopTimesSortedByTrip(), issueStore);
168164

169165
// We need to run this after the cleaning of the data, as stop indices might have changed
170166
mapper.mapAndAddTransfersToBuilder(gtfsDao);
@@ -253,15 +249,9 @@ public void checkInputs() {
253249
*/
254250
private void validateAndInterpolateStopTimesForEachTrip(
255251
TripStopTimes stopTimesByTrip,
256-
DataImportIssueStore issueStore,
257-
boolean removeRepeatedStops
252+
DataImportIssueStore issueStore
258253
) {
259-
new ValidateAndInterpolateStopTimesForEachTrip(
260-
stopTimesByTrip,
261-
true,
262-
removeRepeatedStops,
263-
issueStore
264-
).run();
254+
new ValidateAndInterpolateStopTimesForEachTrip(stopTimesByTrip, true, issueStore).run();
265255
}
266256

267257
/**

application/src/main/java/org/opentripplanner/gtfs/mapping/AgencyAndIdMapper.java

Whitespace-only changes.

application/src/main/java/org/opentripplanner/netex/NetexModule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public void buildGraph() {
124124
}
125125

126126
private void validateStopTimesForEachTrip(TripStopTimes stopTimesByTrip) {
127-
new ValidateAndInterpolateStopTimesForEachTrip(stopTimesByTrip, false, false, issueStore).run();
127+
new ValidateAndInterpolateStopTimesForEachTrip(stopTimesByTrip, false, issueStore).run();
128128
}
129129

130130
@Override

application/src/main/java/org/opentripplanner/standalone/config/buildconfig/GtfsConfig.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,6 @@ private static GtfsDefaultParameters mapGenericParameters(
5454
var docDefaults = GtfsFeedParameters.DEFAULT;
5555
return defaults
5656
.copyOf()
57-
.withRemoveRepeatedStops(
58-
node
59-
.of("removeRepeatedStops")
60-
.since(V2_3)
61-
.summary(
62-
"Should consecutive identical stops be merged into one stop time entry." +
63-
documentationAddition
64-
)
65-
.docDefaultValue(docDefaults.removeRepeatedStops())
66-
.asBoolean(defaults.removeRepeatedStops())
67-
)
6857
.withStationTransferPreference(
6958
node
7059
.of("stationTransferPreference")

0 commit comments

Comments
 (0)