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

graphQL/stoptimes call returns 500, when using a GTFS file with frequencies #299

Open
jaimeventura opened this issue Apr 10, 2019 · 2 comments · May be fixed by #308
Open

graphQL/stoptimes call returns 500, when using a GTFS file with frequencies #299

jaimeventura opened this issue Apr 10, 2019 · 2 comments · May be fixed by #308

Comments

@jaimeventura
Copy link

jaimeventura commented Apr 10, 2019

We realized that after adding a new gtfs file to our OTP instance, with trips with frequencies (besides scheduled times), the calls to graphQL "stoptimes" were returning 500.
To be sure of this, we removed the frequencies.txt file and the issue disappeared (of course we didn’t had results for the period where frequencies were applied).

We tried this on both “prod” and “latest” docker images.

Another thing we noticed, whilst using the file with frequencies, was that:

  • When using OTP builtin webinterface, we were able to see results
  • When using digitransit (whose requests go through graphql) we were not

With further debug, it was found that the call to get stoptimes would work only with scheduledTimetable:

@@ -1800,9 +1804,30 @@
                         .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,  # HERE!
                                environment.getSource()))

In this situation, OTP throws the following:

otp_1          | 18:40:40.356 WARN (ExecutionStrategy.java:70) Exception while fetching data
otp_1          | java.lang.ArrayIndexOutOfBoundsException: null
otp_1          | 18:40:40.357 WARN (FieldErrorInstrumentation.java:174) Exception while fetching field
otp_1          | java.lang.ArrayIndexOutOfBoundsException: null
otp_1          | 18:40:40.409 WARN (ExecutionStrategy.java:70) Exception while fetching data
otp_1          | java.lang.ArrayIndexOutOfBoundsException: null
otp_1          | 18:40:40.411 WARN (FieldErrorInstrumentation.java:174) Exception while fetching field
otp_1          | java.lang.ArrayIndexOutOfBoundsException: null
otp_1          | 18:40:40.429 WARN (FieldErrorInstrumentation.java:133) Errors executing query

That's because the Trip didn't had a "scheduledTimetable".
So we've implement a fix. Its been working for some time an we believe its ok:

                         .name("stoptimes")
                         .description("List of times when this trip arrives to or departs from a stop")
                         .type(new GraphQLList(stoptimeType))
                        .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;
                                               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())
```

We're grad to share it via patch or pull request.
@optionsome
Copy link
Member

Thank you for the information. Go ahead and create a pull request. We will take a better look at the fix then.

jaimeventura pushed a commit to jaimeventura/OpenTripPlanner that referenced this issue May 15, 2019
@jaimeventura jaimeventura linked a pull request May 16, 2019 that will close this issue
@jaimeventura
Copy link
Author

jaimeventura commented May 28, 2019

Hey @optionsome, i believe the commit in this PR is not perfect for merge, but i would kindly appreciate some comments on the PR itself or the issue.
Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants