Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to #299 #308

Open
wants to merge 1 commit into
base: dev-1.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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