Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
import java.time.Duration;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
Expand All @@ -36,6 +38,7 @@
import org.opentripplanner.street.geometry.WgsCoordinate;
import org.opentripplanner.transit.model.network.TripPattern;
import org.opentripplanner.transit.model.site.StopLocation;
import org.opentripplanner.transit.model.timetable.FrequencyEntry;
import org.opentripplanner.transit.model.timetable.OccupancyStatus;
import org.opentripplanner.transit.model.timetable.Trip;
import org.opentripplanner.transit.model.timetable.TripTimes;
Expand Down Expand Up @@ -382,10 +385,30 @@ private PatternAndRealtimeVehicle toRealtimeVehicle(
throw UpdateException.of(scopedTripId, NO_SERVICE_ON_DATE);
}

var scheduledTimetable = getStaticPattern.apply(trip).getScheduledTimetable();
// the trip times are only used for mapping the GTFS-RT stop_sequence back to a stop.
// because new trips without trip times are created for realtime-updated ones, we explicitly
// look at the static trips for the stop_sequence->stop mapping
var staticTripTimes = getStaticPattern.apply(trip).getScheduledTimetable().getTripTimes(trip);
var staticTripTimes = scheduledTimetable.getTripTimes(trip);

if (
!scheduledTimetable.getFrequencyEntries().isEmpty() &&
vehiclePosition.getTrip().hasStartDate()
) {
var updateStartTime = LocalTime.parse(vehiclePosition.getTrip().getStartTime());
staticTripTimes = scheduledTimetable
.getFrequencyEntries()
.stream()
.map(FrequencyEntry::tripTimes)
.filter(e -> {
var start = e.getScheduledDepartureTime(0);
var startTime = LocalTime.ofSecondOfDay(start).truncatedTo(ChronoUnit.MINUTES);
return updateStartTime.equals(startTime);
})
.findFirst()
.orElse(null);
}

if (staticTripTimes == null) {
throw UpdateException.of(scopedTripId, TRIP_NOT_FOUND_IN_PATTERN);
}
Expand Down
Loading