|
1 | 1 | package org.opentripplanner.index;
|
2 | 2 |
|
| 3 | +import java.util.List; |
| 4 | +import com.beust.jcommander.internal.Lists; |
| 5 | + |
3 | 6 | import com.google.transit.realtime.GtfsRealtime;
|
4 | 7 | import com.vividsolutions.jts.geom.Coordinate;
|
5 | 8 | import com.vividsolutions.jts.geom.Envelope;
|
|
37 | 40 | import org.opentripplanner.routing.graph.GraphIndex.PlaceAndDistance;
|
38 | 41 | import org.opentripplanner.routing.trippattern.RealTimeState;
|
39 | 42 | import org.opentripplanner.routing.trippattern.TripTimes;
|
| 43 | +import org.opentripplanner.routing.trippattern.FrequencyEntry; |
40 | 44 | import org.opentripplanner.routing.vertextype.TransitVertex;
|
41 | 45 | import org.opentripplanner.updater.GtfsRealtimeFuzzyTripMatcher;
|
42 | 46 | import org.opentripplanner.updater.stoptime.TimetableSnapshotSource;
|
@@ -1819,9 +1823,30 @@ public IndexGraphQLSchema(GraphIndex index) {
|
1819 | 1823 | .name("stoptimes")
|
1820 | 1824 | .description("List of times when this trip arrives to or departs from a stop")
|
1821 | 1825 | .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 | + }) |
1825 | 1850 | .build())
|
1826 | 1851 | .field(GraphQLFieldDefinition.newFieldDefinition()
|
1827 | 1852 | .name("departureStoptime")
|
|
0 commit comments