Search in sources :

Example 36 with Trip

use of org.opentripplanner.model.Trip in project OpenTripPlanner by opentripplanner.

the class TripMapperTest method mapTrip.

@Test
public void mapTrip() {
    OtpTransitServiceBuilder transitBuilder = new OtpTransitServiceBuilder();
    Route route = new Route();
    route.setId(ID_FACTORY.createId(ROUTE_ID));
    transitBuilder.getRoutes().add(route);
    TripMapper tripMapper = new TripMapper(ID_FACTORY, transitBuilder.getRoutes(), new HierarchicalMapById<>(), new HierarchicalMapById<>(), Collections.emptySet());
    ServiceJourney serviceJourney = createExampleServiceJourney();
    serviceJourney.setLineRef(LINE_REF);
    Trip trip = tripMapper.mapServiceJourney(serviceJourney);
    assertEquals(trip.getId(), ID_FACTORY.createId(SERVICE_JOURNEY_ID));
}
Also used : OtpTransitServiceBuilder(org.opentripplanner.model.impl.OtpTransitServiceBuilder) ServiceJourney(org.rutebanken.netex.model.ServiceJourney) Trip(org.opentripplanner.model.Trip) Route(org.opentripplanner.model.Route) Test(org.junit.Test)

Example 37 with Trip

use of org.opentripplanner.model.Trip 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 38 with Trip

use of org.opentripplanner.model.Trip in project OpenTripPlanner by opentripplanner.

the class GtfsGraphBuilderModuleTest method testNoBikesByDefault.

@Test
public void testNoBikesByDefault() throws IOException {
    // We configure two trip: one with unknown bikes_allowed and the second with bikes
    // allowed.
    MockGtfs gtfs = getSimpleGtfs();
    gtfs.putTrips(2, "r0", "sid0", "bikes_allowed=0,1");
    gtfs.putStopTimes("t0,t1", "s0,s1");
    List<GtfsBundle> bundleList = getGtfsAsBundleList(gtfs);
    bundleList.get(0).setDefaultBikesAllowed(false);
    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.UNKNOWN, BikeAccess.fromTrip(withId(trips, new FeedScopedId(feedId.getId(), "t0"))));
    assertEquals(BikeAccess.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 39 with Trip

use of org.opentripplanner.model.Trip in project OpenTripPlanner by opentripplanner.

the class RoutingServiceTest method testPatternsCoherent.

/**
 * Check that bidirectional relationships between TripPatterns and Trips, Routes, and Stops are coherent.
 */
public void testPatternsCoherent() {
    for (Trip trip : graph.index.getTripForId().values()) {
        TripPattern pattern = graph.index.getPatternForTrip().get(trip);
        assertTrue(pattern.getTrips().contains(trip));
    }
    /* This one depends on a feed where each TripPattern appears on only one route. */
    for (Route route : graph.index.getAllRoutes()) {
        for (TripPattern pattern : graph.index.getPatternsForRoute().get(route)) {
            assertEquals(pattern.route, route);
        }
    }
    for (Stop stop : graph.index.getAllStops()) {
        for (TripPattern pattern : graph.index.getPatternsForStop(stop)) {
            assertTrue(pattern.stopPattern.containsStop(stop.getId().toString()));
        }
    }
}
Also used : Trip(org.opentripplanner.model.Trip) Stop(org.opentripplanner.model.Stop) TripPattern(org.opentripplanner.model.TripPattern) Route(org.opentripplanner.model.Route)

Example 40 with Trip

use of org.opentripplanner.model.Trip in project OpenTripPlanner by opentripplanner.

the class TripTimesTest method testApply.

@Test
public void testApply() {
    Trip trip = new Trip();
    trip.setId(tripId);
    List<StopTime> stopTimes = new LinkedList<StopTime>();
    StopTime stopTime0 = new StopTime();
    StopTime stopTime1 = new StopTime();
    StopTime stopTime2 = new StopTime();
    Stop stop0 = Stop.stopForTest(stops[0].getId(), 0.0, 0.0);
    Stop stop1 = Stop.stopForTest(stops[1].getId(), 0.0, 0.0);
    Stop stop2 = Stop.stopForTest(stops[2].getId(), 0.0, 0.0);
    stopTime0.setStop(stop0);
    stopTime0.setDepartureTime(0);
    stopTime0.setStopSequence(0);
    stopTime1.setStop(stop1);
    stopTime1.setArrivalTime(30);
    stopTime1.setDepartureTime(60);
    stopTime1.setStopSequence(1);
    stopTime2.setStop(stop2);
    stopTime2.setArrivalTime(90);
    stopTime2.setStopSequence(2);
    stopTimes.add(stopTime0);
    stopTimes.add(stopTime1);
    stopTimes.add(stopTime2);
    TripTimes differingTripTimes = new TripTimes(trip, stopTimes, new Deduplicator());
    TripTimes updatedTripTimesA = new TripTimes(differingTripTimes);
    updatedTripTimesA.updateArrivalTime(1, 89);
    updatedTripTimesA.updateDepartureTime(1, 98);
    assertFalse(updatedTripTimesA.timesIncreasing());
}
Also used : Trip(org.opentripplanner.model.Trip) Stop(org.opentripplanner.model.Stop) LinkedList(java.util.LinkedList) StopTime(org.opentripplanner.model.StopTime) Test(org.junit.Test)

Aggregations

Trip (org.opentripplanner.model.Trip)58 FeedScopedId (org.opentripplanner.model.FeedScopedId)29 TripPattern (org.opentripplanner.model.TripPattern)28 Stop (org.opentripplanner.model.Stop)20 Test (org.junit.Test)19 Route (org.opentripplanner.model.Route)15 ArrayList (java.util.ArrayList)13 ServiceDate (org.opentripplanner.model.calendar.ServiceDate)13 StopTime (org.opentripplanner.model.StopTime)10 TripTimes (org.opentripplanner.routing.trippattern.TripTimes)9 ZonedDateTime (java.time.ZonedDateTime)7 HashSet (java.util.HashSet)7 List (java.util.List)6 Agency (org.opentripplanner.model.Agency)6 Timetable (org.opentripplanner.model.Timetable)6 RoutingService (org.opentripplanner.routing.RoutingService)5 Map (java.util.Map)4 Collectors (java.util.stream.Collectors)4 Station (org.opentripplanner.model.Station)4 TimetableSnapshot (org.opentripplanner.model.TimetableSnapshot)4