use of org.opentripplanner.model.TripPattern in project OpenTripPlanner by opentripplanner.
the class GtfsGraphBuilderModuleTest method testBikesByDefault.
@Test
public void testBikesByDefault() throws IOException {
// We configure two trip: one with unknown bikes_allowed and the second with no bikes
// allowed.
MockGtfs gtfs = getSimpleGtfs();
gtfs.putTrips(2, "r0", "sid0", "bikes_allowed=0,2");
gtfs.putStopTimes("t0,t1", "s0,s1");
List<GtfsBundle> bundleList = getGtfsAsBundleList(gtfs);
bundleList.get(0).setDefaultBikesAllowed(true);
builder = new GtfsModule(bundleList, ServiceDateInterval.unbounded());
Graph graph = new Graph();
builder.buildGraph(graph, _extra);
graph.index();
// Feed id is used instead of the agency id for OBA entities.
GtfsBundle gtfsBundle = bundleList.get(0);
GtfsFeedId feedId = gtfsBundle.getFeedId();
Trip trip = graph.index.getTripForId().get(new FeedScopedId(feedId.getId(), "t0"));
TripPattern pattern = graph.index.getPatternForTrip().get(trip);
List<Trip> trips = pattern.getTrips();
assertEquals(BikeAccess.ALLOWED, BikeAccess.fromTrip(withId(trips, new FeedScopedId(feedId.getId(), "t0"))));
assertEquals(BikeAccess.NOT_ALLOWED, BikeAccess.fromTrip(withId(trips, new FeedScopedId(feedId.getId(), "t1"))));
}
use of org.opentripplanner.model.TripPattern in project OpenTripPlanner by opentripplanner.
the class TripTimesShortHelper method getTripTimesShort.
public static List<TripTimeShort> getTripTimesShort(RoutingService routingService, Trip trip, ServiceDate serviceDate) {
final ServiceDay serviceDay = new ServiceDay(routingService.getServiceCodes(), serviceDate, routingService.getCalendarService(), trip.getRoute().getAgency().getId());
Timetable timetable = null;
TimetableSnapshot timetableSnapshot = routingService.getTimetableSnapshot();
if (timetableSnapshot != null) {
// Check if realtime-data is available for trip
TripPattern pattern = timetableSnapshot.getLastAddedTripPattern(trip.getId(), serviceDate);
if (pattern == null) {
pattern = routingService.getPatternForTrip().get(trip);
}
timetable = timetableSnapshot.resolve(pattern, serviceDate);
}
if (timetable == null) {
timetable = routingService.getPatternForTrip().get(trip).scheduledTimetable;
}
// This check is made here to avoid changing TripTimeShort.fromTripTimes
TripTimes times = timetable.getTripTimes(timetable.getTripIndex(trip.getId()));
if (!serviceDay.serviceRunning(times.serviceCode)) {
return new ArrayList<>();
} else {
return TripTimeShort.fromTripTimes(timetable, trip, serviceDay);
}
}
use of org.opentripplanner.model.TripPattern in project OpenTripPlanner by opentripplanner.
the class TripPatternMapperTest method testMapTripPattern.
@Test
public void testMapTripPattern() {
NetexTestDataSample sample = new NetexTestDataSample();
TripPatternMapper tripPatternMapper = new TripPatternMapper(MappingSupport.ID_FACTORY, sample.getStopsById(), sample.getOtpRouteByid(), Collections.emptySet(), sample.getRouteById(), sample.getJourneyPatternById(), sample.getQuayIdByStopPointRef(), new HierarchicalMapById<>(), sample.getServiceJourneyByPatternId(), new Deduplicator());
TripPatternMapper.Result r = tripPatternMapper.mapTripPattern(sample.getJourneyPattern());
assertEquals(1, r.tripPatterns.size());
TripPattern tripPattern = r.tripPatterns.get(0);
assertEquals(4, tripPattern.getStops().size());
assertEquals(1, tripPattern.getTrips().size());
List<Stop> stops = tripPattern.getStops();
Trip trip = tripPattern.getTrips().get(0);
assertEquals("RUT:ServiceJourney:1", trip.getId().getId());
assertEquals("NSR:Quay:1", stops.get(0).getId().getId());
assertEquals("NSR:Quay:2", stops.get(1).getId().getId());
assertEquals("NSR:Quay:3", stops.get(2).getId().getId());
assertEquals("NSR:Quay:4", stops.get(3).getId().getId());
assertEquals(1, tripPattern.scheduledTimetable.tripTimes.size());
TripTimes tripTimes = tripPattern.scheduledTimetable.tripTimes.get(0);
assertEquals(4, tripTimes.getNumStops());
assertEquals(18000, tripTimes.getDepartureTime(0));
assertEquals(18240, tripTimes.getDepartureTime(1));
assertEquals(18600, tripTimes.getDepartureTime(2));
assertEquals(18900, tripTimes.getDepartureTime(3));
}
use of org.opentripplanner.model.TripPattern in project OpenTripPlanner by opentripplanner.
the class NetexLoaderSmokeTest method assertTripPatterns.
private void assertTripPatterns(Collection<TripPattern> patterns) {
Map<FeedScopedId, TripPattern> map = patterns.stream().collect(Collectors.toMap(TripPattern::getId, s -> s));
TripPattern p = map.get(fId("RUT:JourneyPattern:12-1"));
assertEquals("Jernbanetorget", p.getDirection());
assertEquals("RB", p.getFeedId());
assertEquals("[<Stop RB:NSR:Quay:7203>, <Stop RB:NSR:Quay:8027>]", p.getStops().toString());
assertEquals("[<Trip RB:RUT:ServiceJourney:12-101375-1000>]", p.getTrips().toString());
// TODO OTP2 - Why?
assertNull(p.getServices());
assertEquals(4, patterns.size());
}
use of org.opentripplanner.model.TripPattern in project OpenTripPlanner by opentripplanner.
the class OtpTransitServiceBuilderLimitPeriodTest method setUp.
@Before
public void setUp() {
subject = new OtpTransitServiceBuilder();
// Add a service calendar that overlap with the period limit
subject.getCalendars().add(createServiceCalendar(SERVICE_C_IN, D1, D3));
// Add a service calendar that is outside the period limit, expected deleted later
subject.getCalendars().add(createServiceCalendar(SERVICE_C_OUT, D0, D1));
// Add a service calendar date that is within the period limit
subject.getCalendarDates().add(new ServiceCalendarDate(SERVICE_D_IN, D2, 1));
// Add a service calendar date that is OUTSIDE the period limit, expected deleted later
subject.getCalendarDates().add(new ServiceCalendarDate(SERVICE_D_OUT, D1, 1));
// Add 2 stops
subject.getStops().add(STOP_1);
subject.getStops().add(STOP_2);
// Add Route
route.setId(newId());
route.setType(3);
route.setMode(TransitMode.BUS);
subject.getRoutes().add(route);
// Add trips; one for each day and calendar
subject.getTripsById().addAll(List.of(tripCSIn, tripCSOut, tripCSDIn, tripCSDOut));
// Pattern with trips that is partially deleted later
patternInT1 = createTripPattern(List.of(tripCSIn, tripCSOut));
// Pattern with trip that is inside period
patternInT2 = createTripPattern(List.of(tripCSDIn));
// Pattern with trip outside limiting period - pattern is deleted later
TripPattern patternOut = createTripPattern(List.of(tripCSDOut));
subject.getTripPatterns().put(STOP_PATTERN, patternInT1);
subject.getTripPatterns().put(STOP_PATTERN, patternInT2);
subject.getTripPatterns().put(STOP_PATTERN, patternOut);
}
Aggregations