Skip to content

Commit

Permalink
Make 'stoptimes' call return expected data, when using a GTFS file wi…
Browse files Browse the repository at this point in the history
…th frequencies. (Fixes HSLdevcom#299)
  • Loading branch information
Jaime Ventura committed May 15, 2019
1 parent 74eff2e commit 07b8395
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions src/main/java/org/opentripplanner/index/IndexGraphQLSchema.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.opentripplanner.index;

import java.util.List;
import com.beust.jcommander.internal.Lists;

import com.google.transit.realtime.GtfsRealtime;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Envelope;
Expand Down Expand Up @@ -37,6 +40,7 @@
import org.opentripplanner.routing.graph.GraphIndex.PlaceAndDistance;
import org.opentripplanner.routing.trippattern.RealTimeState;
import org.opentripplanner.routing.trippattern.TripTimes;
import org.opentripplanner.routing.trippattern.FrequencyEntry;
import org.opentripplanner.routing.vertextype.TransitVertex;
import org.opentripplanner.updater.GtfsRealtimeFuzzyTripMatcher;
import org.opentripplanner.updater.stoptime.TimetableSnapshotSource;
Expand Down Expand Up @@ -1819,9 +1823,30 @@ public IndexGraphQLSchema(GraphIndex index) {
.name("stoptimes")
.description("List of times when this trip arrives to or departs from a stop")
.type(new GraphQLList(stoptimeType))
.dataFetcher(environment -> TripTimeShort.fromTripTimes(
index.patternForTrip.get((Trip) environment.getSource()).scheduledTimetable,
environment.getSource()))
.dataFetcher(environment ->{
Timetable timetable = index.patternForTrip.get((Trip) environment.getSource()).scheduledTimetable;

// If the Trip is frequency-based, there are no scheduled tripTimes (they must com from <FrequencyEntry>.tripTimes)
if (timetable.tripTimes.isEmpty()) {

// This should probably be encapsulated into a function named TripTimeShort.fromFrequencyTripTimes,
// since it does the same as existing function TripTimeShort.fromTripTimes, but for Frequency.
// Or, it could also be moved into TripTimeShort.fromTripTimes.

List<TripTimeShort> out = Lists.newArrayList();

for (FrequencyEntry freq : timetable.frequencyEntries) {
TripTimes times = freq.tripTimes;
// one per stop, not one per hop, thus the <= operator
for (int i = 0; i < times.getNumStops(); ++i) {
out.add(new TripTimeShort(times, i, timetable.pattern.getStop(i), null));
}
}
return out;
} else {
return TripTimeShort.fromTripTimes(timetable, environment.getSource());
}
})
.build())
.field(GraphQLFieldDefinition.newFieldDefinition()
.name("departureStoptime")
Expand Down

0 comments on commit 07b8395

Please sign in to comment.