Search in sources :

Example 31 with TripPattern

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"))));
}
Also used : Trip(org.opentripplanner.model.Trip) Graph(org.opentripplanner.routing.graph.Graph) GtfsBundle(org.opentripplanner.graph_builder.model.GtfsBundle) MockGtfs(org.opentripplanner.gtfs.MockGtfs) FeedScopedId(org.opentripplanner.model.FeedScopedId) TripPattern(org.opentripplanner.model.TripPattern) Test(org.junit.Test)

Example 32 with TripPattern

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);
    }
}
Also used : Timetable(org.opentripplanner.model.Timetable) ServiceDay(org.opentripplanner.routing.core.ServiceDay) ArrayList(java.util.ArrayList) TripTimes(org.opentripplanner.routing.trippattern.TripTimes) TimetableSnapshot(org.opentripplanner.model.TimetableSnapshot) TripPattern(org.opentripplanner.model.TripPattern)

Example 33 with TripPattern

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));
}
Also used : Trip(org.opentripplanner.model.Trip) Stop(org.opentripplanner.model.Stop) TripTimes(org.opentripplanner.routing.trippattern.TripTimes) Deduplicator(org.opentripplanner.routing.trippattern.Deduplicator) TripPattern(org.opentripplanner.model.TripPattern) Test(org.junit.Test)

Example 34 with TripPattern

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());
}
Also used : StopTimeKey(org.opentripplanner.model.StopTimeKey) Trip(org.opentripplanner.model.Trip) MultiModalStation(org.opentripplanner.model.MultiModalStation) Multimap(com.google.common.collect.Multimap) OtpTransitServiceBuilder(org.opentripplanner.model.impl.OtpTransitServiceBuilder) ServiceDate(org.opentripplanner.model.calendar.ServiceDate) CalendarServiceData(org.opentripplanner.model.calendar.CalendarServiceData) ArrayList(java.util.ArrayList) TransitEntity(org.opentripplanner.model.TransitEntity) Map(java.util.Map) ConstantsForTests(org.opentripplanner.ConstantsForTests) DataImportIssueStore(org.opentripplanner.graph_builder.DataImportIssueStore) Assert.fail(org.junit.Assert.fail) NetexBundle(org.opentripplanner.netex.loader.NetexBundle) FeedScopedId(org.opentripplanner.model.FeedScopedId) Station(org.opentripplanner.model.Station) Operator(org.opentripplanner.model.Operator) TripPattern(org.opentripplanner.model.TripPattern) Stop(org.opentripplanner.model.Stop) Collection(java.util.Collection) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Notice(org.opentripplanner.model.Notice) Agency(org.opentripplanner.model.Agency) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) OtpTransitService(org.opentripplanner.model.OtpTransitService) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) Deduplicator(org.opentripplanner.routing.trippattern.Deduplicator) Assert.assertEquals(org.junit.Assert.assertEquals) FeedScopedId(org.opentripplanner.model.FeedScopedId) TripPattern(org.opentripplanner.model.TripPattern)

Example 35 with TripPattern

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);
}
Also used : ServiceCalendarDate(org.opentripplanner.model.calendar.ServiceCalendarDate) TripPattern(org.opentripplanner.model.TripPattern) Before(org.junit.Before)

Aggregations

TripPattern (org.opentripplanner.model.TripPattern)61 Trip (org.opentripplanner.model.Trip)26 FeedScopedId (org.opentripplanner.model.FeedScopedId)23 Stop (org.opentripplanner.model.Stop)23 ArrayList (java.util.ArrayList)19 TripTimes (org.opentripplanner.routing.trippattern.TripTimes)19 Timetable (org.opentripplanner.model.Timetable)13 ServiceDate (org.opentripplanner.model.calendar.ServiceDate)13 Route (org.opentripplanner.model.Route)12 Test (org.junit.Test)11 HashSet (java.util.HashSet)8 RoutingService (org.opentripplanner.routing.RoutingService)8 List (java.util.List)7 StopPattern (org.opentripplanner.model.StopPattern)7 TimetableSnapshot (org.opentripplanner.model.TimetableSnapshot)7 GET (javax.ws.rs.GET)6 Path (javax.ws.rs.Path)6 StopTime (org.opentripplanner.model.StopTime)5 TripUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate)4 StopTimeUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate)4