Skip to content

Commit 07b8395

Browse files
author
Jaime Ventura
committed
Make 'stoptimes' call return expected data, when using a GTFS file with frequencies. (Fixes HSLdevcom#299)
1 parent 74eff2e commit 07b8395

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

src/main/java/org/opentripplanner/index/IndexGraphQLSchema.java

+28-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package org.opentripplanner.index;
22

3+
import java.util.List;
4+
import com.beust.jcommander.internal.Lists;
5+
36
import com.google.transit.realtime.GtfsRealtime;
47
import com.vividsolutions.jts.geom.Coordinate;
58
import com.vividsolutions.jts.geom.Envelope;
@@ -37,6 +40,7 @@
3740
import org.opentripplanner.routing.graph.GraphIndex.PlaceAndDistance;
3841
import org.opentripplanner.routing.trippattern.RealTimeState;
3942
import org.opentripplanner.routing.trippattern.TripTimes;
43+
import org.opentripplanner.routing.trippattern.FrequencyEntry;
4044
import org.opentripplanner.routing.vertextype.TransitVertex;
4145
import org.opentripplanner.updater.GtfsRealtimeFuzzyTripMatcher;
4246
import org.opentripplanner.updater.stoptime.TimetableSnapshotSource;
@@ -1819,9 +1823,30 @@ public IndexGraphQLSchema(GraphIndex index) {
18191823
.name("stoptimes")
18201824
.description("List of times when this trip arrives to or departs from a stop")
18211825
.type(new GraphQLList(stoptimeType))
1822-
.dataFetcher(environment -> TripTimeShort.fromTripTimes(
1823-
index.patternForTrip.get((Trip) environment.getSource()).scheduledTimetable,
1824-
environment.getSource()))
1826+
.dataFetcher(environment ->{
1827+
Timetable timetable = index.patternForTrip.get((Trip) environment.getSource()).scheduledTimetable;
1828+
1829+
// If the Trip is frequency-based, there are no scheduled tripTimes (they must com from <FrequencyEntry>.tripTimes)
1830+
if (timetable.tripTimes.isEmpty()) {
1831+
1832+
// This should probably be encapsulated into a function named TripTimeShort.fromFrequencyTripTimes,
1833+
// since it does the same as existing function TripTimeShort.fromTripTimes, but for Frequency.
1834+
// Or, it could also be moved into TripTimeShort.fromTripTimes.
1835+
1836+
List<TripTimeShort> out = Lists.newArrayList();
1837+
1838+
for (FrequencyEntry freq : timetable.frequencyEntries) {
1839+
TripTimes times = freq.tripTimes;
1840+
// one per stop, not one per hop, thus the <= operator
1841+
for (int i = 0; i < times.getNumStops(); ++i) {
1842+
out.add(new TripTimeShort(times, i, timetable.pattern.getStop(i), null));
1843+
}
1844+
}
1845+
return out;
1846+
} else {
1847+
return TripTimeShort.fromTripTimes(timetable, environment.getSource());
1848+
}
1849+
})
18251850
.build())
18261851
.field(GraphQLFieldDefinition.newFieldDefinition()
18271852
.name("departureStoptime")

0 commit comments

Comments
 (0)