Search in sources :

Example 91 with Trip

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

the class OnBoardDepartServiceImplTest method testOnBoardDepartureTime.

@Test
public final void testOnBoardDepartureTime() {
    Coordinate[] coordinates = new Coordinate[5];
    coordinates[0] = new Coordinate(0.0, 0.0);
    coordinates[1] = new Coordinate(0.0, 1.0);
    coordinates[2] = new Coordinate(2.0, 1.0);
    coordinates[3] = new Coordinate(5.0, 1.0);
    coordinates[4] = new Coordinate(5.0, 5.0);
    PatternDepartVertex depart = mock(PatternDepartVertex.class);
    PatternArriveVertex dwell = mock(PatternArriveVertex.class);
    PatternArriveVertex arrive = mock(PatternArriveVertex.class);
    Graph graph = mock(Graph.class);
    RoutingRequest routingRequest = mock(RoutingRequest.class);
    ServiceDay serviceDay = mock(ServiceDay.class);
    // You're probably not supposed to do this to mocks (access their fields directly)
    // But I know of no other way to do this since the mock object has only action-free stub methods.
    routingRequest.modes = new TraverseModeSet("WALK,TRANSIT");
    when(graph.getTimeZone()).thenReturn(TimeZone.getTimeZone("GMT"));
    GeometryFactory geometryFactory = GeometryUtils.getGeometryFactory();
    CoordinateSequenceFactory coordinateSequenceFactory = geometryFactory.getCoordinateSequenceFactory();
    CoordinateSequence coordinateSequence = coordinateSequenceFactory.create(coordinates);
    LineString geometry = new LineString(coordinateSequence, geometryFactory);
    ArrayList<Edge> hops = new ArrayList<Edge>(2);
    RoutingContext routingContext = new RoutingContext(routingRequest, graph, null, arrive);
    AgencyAndId agencyAndId = new AgencyAndId("Agency", "ID");
    Agency agency = new Agency();
    Route route = new Route();
    ArrayList<StopTime> stopTimes = new ArrayList<StopTime>(3);
    StopTime stopDepartTime = new StopTime();
    StopTime stopDwellTime = new StopTime();
    StopTime stopArriveTime = new StopTime();
    Stop stopDepart = new Stop();
    Stop stopDwell = new Stop();
    Stop stopArrive = new Stop();
    Trip trip = new Trip();
    routingContext.serviceDays = new ArrayList<ServiceDay>(Collections.singletonList(serviceDay));
    agency.setId(agencyAndId.getAgencyId());
    route.setId(agencyAndId);
    route.setAgency(agency);
    stopDepart.setId(agencyAndId);
    stopDwell.setId(agencyAndId);
    stopArrive.setId(agencyAndId);
    stopDepartTime.setStop(stopDepart);
    stopDepartTime.setDepartureTime(0);
    stopDwellTime.setArrivalTime(20);
    stopDwellTime.setStop(stopDwell);
    stopDwellTime.setDepartureTime(40);
    stopArriveTime.setArrivalTime(60);
    stopArriveTime.setStop(stopArrive);
    stopTimes.add(stopDepartTime);
    stopTimes.add(stopDwellTime);
    stopTimes.add(stopArriveTime);
    trip.setId(agencyAndId);
    trip.setTripHeadsign("The right");
    trip.setRoute(route);
    TripTimes tripTimes = new TripTimes(trip, stopTimes, new Deduplicator());
    StopPattern stopPattern = new StopPattern(stopTimes);
    TripPattern tripPattern = new TripPattern(route, stopPattern);
    TripPattern.generateUniqueIds(Arrays.asList(tripPattern));
    when(depart.getTripPattern()).thenReturn(tripPattern);
    when(dwell.getTripPattern()).thenReturn(tripPattern);
    PatternHop patternHop0 = new PatternHop(depart, dwell, stopDepart, stopDwell, 0);
    PatternHop patternHop1 = new PatternHop(dwell, arrive, stopDwell, stopArrive, 1);
    hops.add(patternHop0);
    hops.add(patternHop1);
    when(graph.getEdges()).thenReturn(hops);
    when(depart.getCoordinate()).thenReturn(new Coordinate(0, 0));
    when(dwell.getCoordinate()).thenReturn(new Coordinate(0, 0));
    when(arrive.getCoordinate()).thenReturn(new Coordinate(0, 0));
    routingRequest.from = new GenericLocation();
    routingRequest.startingTransitTripId = agencyAndId;
    when(serviceDay.secondsSinceMidnight(anyInt())).thenReturn(9);
    patternHop0.setGeometry(geometry);
    tripPattern.add(tripTimes);
    graph.index = new GraphIndex(graph);
    coordinates = new Coordinate[3];
    coordinates[0] = new Coordinate(3.5, 1.0);
    coordinates[1] = new Coordinate(5.0, 1.0);
    coordinates[2] = new Coordinate(5.0, 5.0);
    coordinateSequence = coordinateSequenceFactory.create(coordinates);
    geometry = new LineString(coordinateSequence, geometryFactory);
    Vertex vertex = onBoardDepartServiceImpl.setupDepartOnBoard(routingContext);
    Edge edge = vertex.getOutgoing().toArray(new Edge[1])[0];
    assertEquals(vertex, edge.getFromVertex());
    assertEquals(dwell, edge.getToVertex());
    assertEquals("The right", edge.getDirection());
    assertEquals(geometry, edge.getGeometry());
    assertEquals(coordinates[0].x, vertex.getX(), 0.0);
    assertEquals(coordinates[0].y, vertex.getY(), 0.0);
}
Also used : CoordinateSequence(com.vividsolutions.jts.geom.CoordinateSequence) Vertex(org.opentripplanner.routing.graph.Vertex) PatternDepartVertex(org.opentripplanner.routing.vertextype.PatternDepartVertex) PatternArriveVertex(org.opentripplanner.routing.vertextype.PatternArriveVertex) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) ServiceDay(org.opentripplanner.routing.core.ServiceDay) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Stop(org.onebusaway.gtfs.model.Stop) ArrayList(java.util.ArrayList) Deduplicator(org.opentripplanner.routing.trippattern.Deduplicator) RoutingContext(org.opentripplanner.routing.core.RoutingContext) GraphIndex(org.opentripplanner.routing.graph.GraphIndex) PatternDepartVertex(org.opentripplanner.routing.vertextype.PatternDepartVertex) TripTimes(org.opentripplanner.routing.trippattern.TripTimes) GenericLocation(org.opentripplanner.common.model.GenericLocation) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) Route(org.onebusaway.gtfs.model.Route) StopTime(org.onebusaway.gtfs.model.StopTime) StopPattern(org.opentripplanner.model.StopPattern) Trip(org.onebusaway.gtfs.model.Trip) Agency(org.onebusaway.gtfs.model.Agency) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) TripPattern(org.opentripplanner.routing.edgetype.TripPattern) Graph(org.opentripplanner.routing.graph.Graph) Coordinate(com.vividsolutions.jts.geom.Coordinate) LineString(com.vividsolutions.jts.geom.LineString) CoordinateSequenceFactory(com.vividsolutions.jts.geom.CoordinateSequenceFactory) PatternHop(org.opentripplanner.routing.edgetype.PatternHop) PatternArriveVertex(org.opentripplanner.routing.vertextype.PatternArriveVertex) Edge(org.opentripplanner.routing.graph.Edge) Test(org.junit.Test)

Example 92 with Trip

use of org.onebusaway.gtfs.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 = new Stop();
    Stop stop1 = new Stop();
    Stop stop2 = new Stop();
    stop0.setId(stops[0]);
    stop1.setId(stops[1]);
    stop2.setId(stops[2]);
    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.onebusaway.gtfs.model.Trip) Stop(org.onebusaway.gtfs.model.Stop) LinkedList(java.util.LinkedList) StopTime(org.onebusaway.gtfs.model.StopTime) Test(org.junit.Test)

Example 93 with Trip

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

the class TestStopTransfer method testStopTransfer.

/**
 * Test different stop transfers
 */
public void testStopTransfer() {
    // Setup from trip with route
    Route fromRoute = new Route();
    fromRoute.setId(new AgencyAndId("A1", "R1"));
    Trip fromTrip = new Trip();
    fromTrip.setId(new AgencyAndId("A1", "T1"));
    fromTrip.setRoute(fromRoute);
    // Setup to trip with route
    Route toRoute = new Route();
    toRoute.setId(new AgencyAndId("A1", "R2"));
    Trip toTrip = new Trip();
    toTrip.setId(new AgencyAndId("A1", "T2"));
    toTrip.setRoute(toRoute);
    // Setup second to trip with route
    Route toRoute2 = new Route();
    toRoute2.setId(new AgencyAndId("A1", "R3"));
    Trip toTrip2 = new Trip();
    toTrip2.setId(new AgencyAndId("A1", "T3"));
    toTrip2.setRoute(toRoute2);
    // Create StopTransfer
    StopTransfer transfer = new StopTransfer();
    assertEquals(StopTransfer.UNKNOWN_TRANSFER, transfer.getTransferTime(fromTrip, toTrip));
    assertEquals(StopTransfer.UNKNOWN_TRANSFER, transfer.getTransferTime(fromTrip, toTrip2));
    // Add empty SpecificTransfer, specificity 0
    transfer.addSpecificTransfer(new SpecificTransfer((AgencyAndId) null, null, null, null, StopTransfer.FORBIDDEN_TRANSFER));
    assertEquals(StopTransfer.FORBIDDEN_TRANSFER, transfer.getTransferTime(fromTrip, toTrip));
    assertEquals(StopTransfer.FORBIDDEN_TRANSFER, transfer.getTransferTime(fromTrip, toTrip2));
    // Add SpecificTransfer one route, specificity 1
    transfer.addSpecificTransfer(new SpecificTransfer(null, toRoute2.getId(), null, null, StopTransfer.PREFERRED_TRANSFER));
    assertEquals(StopTransfer.FORBIDDEN_TRANSFER, transfer.getTransferTime(fromTrip, toTrip));
    assertEquals(StopTransfer.PREFERRED_TRANSFER, transfer.getTransferTime(fromTrip, toTrip2));
    // Add SpecificTransfer one trip (and one ignored route), specificity 2
    transfer.addSpecificTransfer(new SpecificTransfer(null, toRoute2.getId(), null, toTrip2.getId(), StopTransfer.TIMED_TRANSFER));
    assertEquals(StopTransfer.FORBIDDEN_TRANSFER, transfer.getTransferTime(fromTrip, toTrip));
    assertEquals(StopTransfer.TIMED_TRANSFER, transfer.getTransferTime(fromTrip, toTrip2));
    // Add SpecificTransfer one trip and one route, specificity 3
    transfer.addSpecificTransfer(new SpecificTransfer(fromRoute.getId(), toRoute2.getId(), fromTrip.getId(), null, StopTransfer.UNKNOWN_TRANSFER));
    assertEquals(StopTransfer.FORBIDDEN_TRANSFER, transfer.getTransferTime(fromTrip, toTrip));
    assertEquals(StopTransfer.UNKNOWN_TRANSFER, transfer.getTransferTime(fromTrip, toTrip2));
    // Add SpecificTransfer one route, specificity 1
    transfer.addSpecificTransfer(new SpecificTransfer(fromRoute.getId(), null, null, null, 3));
    assertEquals(3, transfer.getTransferTime(fromTrip, toTrip));
    assertEquals(StopTransfer.UNKNOWN_TRANSFER, transfer.getTransferTime(fromTrip, toTrip2));
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Route(org.onebusaway.gtfs.model.Route)

Example 94 with Trip

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

the class TimetableSnapshotTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    context = GtfsLibrary.readGtfs(new File(ConstantsForTests.FAKE_GTFS));
    graph = new Graph();
    GTFSPatternHopFactory factory = new GTFSPatternHopFactory(context);
    factory.run(graph);
    graph.putService(CalendarServiceData.class, GtfsLibrary.createCalendarServiceData(context.getDao()));
    patternIndex = new HashMap<AgencyAndId, TripPattern>();
    for (TransitStopDepart tsd : Iterables.filter(graph.getVertices(), TransitStopDepart.class)) {
        for (TransitBoardAlight tba : Iterables.filter(tsd.getOutgoing(), TransitBoardAlight.class)) {
            if (!tba.boarding)
                continue;
            TripPattern pattern = tba.getPattern();
            for (Trip trip : pattern.getTrips()) {
                patternIndex.put(trip.getId(), pattern);
            }
        }
    }
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) Graph(org.opentripplanner.routing.graph.Graph) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) GTFSPatternHopFactory(org.opentripplanner.routing.edgetype.factory.GTFSPatternHopFactory) File(java.io.File) TransitStopDepart(org.opentripplanner.routing.vertextype.TransitStopDepart) BeforeClass(org.junit.BeforeClass)

Example 95 with Trip

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

the class NycFareServiceImpl method getCost.

@Override
public Fare getCost(GraphPath path) {
    final List<AgencyAndId> SIR_PAID_STOPS = makeMtaStopList("S31", "S30");
    final List<AgencyAndId> SUBWAY_FREE_TRANSFER_STOPS = makeMtaStopList("R11", "B08", "629");
    final List<AgencyAndId> SIR_BONUS_STOPS = makeMtaStopList("140", "420", "419", "418", "M22", "M23", "R27", "R26");
    final List<AgencyAndId> SIR_BONUS_ROUTES = makeMtaStopList("M5", "M20", "M15-SBS");
    final List<AgencyAndId> CANARSIE = makeMtaStopList("L29", "303345");
    // List of NYC agencies to set fares for
    final List<String> AGENCIES = new ArrayList<>();
    AGENCIES.add("MTABC");
    AGENCIES.add("MTA NYCT");
    LinkedList<State> states = path.states;
    // create rides
    List<Ride> rides = new ArrayList<Ride>();
    Ride newRide = null;
    final int SUBWAY = 1;
    final int SIR = 2;
    final int LOCAL_BUS = 3;
    final int EXPRESS_BUS = 30;
    final int EXPENSIVE_EXPRESS_BUS = 34;
    final int WALK = -1;
    for (State state : states) {
        Edge backEdge = state.getBackEdge();
        if (backEdge instanceof StreetEdge) {
            if (newRide == null || !newRide.classifier.equals(WALK)) {
                if (rides.size() == 0 || !rides.get(rides.size() - 1).classifier.equals(WALK)) {
                    newRide = new Ride();
                    newRide.classifier = WALK;
                    rides.add(newRide);
                }
            }
            continue;
        }
        // dwells do not affect fare.
        if (backEdge instanceof DwellEdge)
            continue;
        if (!(backEdge instanceof HopEdge)) {
            newRide = null;
            continue;
        }
        AgencyAndId routeId = state.getRoute();
        String agencyId = state.getBackTrip().getRoute().getAgency().getId();
        if (!AGENCIES.contains(agencyId)) {
            continue;
        }
        if (routeId == null) {
            newRide = null;
        } else {
            if (newRide == null || !routeId.equals(newRide.route)) {
                newRide = new Ride();
                rides.add(newRide);
                newRide.firstStop = ((HopEdge) backEdge).getBeginStop();
                newRide.route = routeId;
                Trip trip = state.getBackTrip();
                Route route = trip.getRoute();
                int type = route.getType();
                newRide.classifier = type;
                String shortName = route.getShortName();
                if (shortName == null) {
                    newRide.classifier = SUBWAY;
                } else if (shortName.equals("BxM4C")) {
                    newRide.classifier = EXPENSIVE_EXPRESS_BUS;
                } else if (shortName.startsWith("X") || shortName.startsWith("BxM") || shortName.startsWith("QM") || shortName.startsWith("BM")) {
                    // Express bus
                    newRide.classifier = EXPRESS_BUS;
                }
                newRide.startTime = state.getTimeSeconds();
            }
            newRide.lastStop = ((HopEdge) backEdge).getBeginStop();
        }
    }
    // There are no rides, so there's no fare.
    if (rides.size() == 0) {
        return null;
    }
    NycFareState state = NycFareState.INIT;
    boolean lexFreeTransfer = false;
    boolean canarsieFreeTransfer = false;
    boolean siLocalBus = false;
    boolean sirBonusTransfer = false;
    float totalFare = 0;
    for (Ride ride : rides) {
        AgencyAndId firstStopId = null;
        AgencyAndId lastStopId = null;
        if (ride.firstStop != null) {
            firstStopId = ride.firstStop.getId();
            lastStopId = ride.lastStop.getId();
        }
        switch(state) {
            case INIT:
                lexFreeTransfer = siLocalBus = canarsieFreeTransfer = false;
                if (ride.classifier.equals(WALK)) {
                // walking keeps you in init
                } else if (ride.classifier.equals(SUBWAY)) {
                    state = NycFareState.SUBWAY_PRE_TRANSFER;
                    totalFare += ORDINARY_FARE;
                    if (SUBWAY_FREE_TRANSFER_STOPS.contains(ride.lastStop.getId())) {
                        lexFreeTransfer = true;
                    }
                    if (CANARSIE.contains(ride.lastStop.getId())) {
                        canarsieFreeTransfer = true;
                    }
                } else if (ride.classifier.equals(SIR)) {
                    state = NycFareState.SIR_PRE_TRANSFER;
                    if (SIR_PAID_STOPS.contains(firstStopId) || SIR_PAID_STOPS.contains(lastStopId)) {
                        totalFare += ORDINARY_FARE;
                    }
                } else if (ride.classifier.equals(LOCAL_BUS)) {
                    state = NycFareState.BUS_PRE_TRANSFER;
                    totalFare += ORDINARY_FARE;
                    if (CANARSIE.contains(ride.lastStop.getId())) {
                        canarsieFreeTransfer = true;
                    }
                    siLocalBus = ride.route.getId().startsWith("S");
                } else if (ride.classifier.equals(EXPRESS_BUS)) {
                    state = NycFareState.BUS_PRE_TRANSFER;
                    totalFare += EXPRESS_FARE;
                } else if (ride.classifier.equals(EXPENSIVE_EXPRESS_BUS)) {
                    state = NycFareState.EXPENSIVE_EXPRESS_BUS;
                    totalFare += EXPENSIVE_EXPRESS_FARE;
                }
                break;
            case SUBWAY_PRE_TRANSFER_WALKED:
                if (ride.classifier.equals(SUBWAY)) {
                    // lex and 59/63
                    if (!(lexFreeTransfer && SUBWAY_FREE_TRANSFER_STOPS.contains(ride.firstStop.getId()))) {
                        totalFare += ORDINARY_FARE;
                    }
                    lexFreeTransfer = canarsieFreeTransfer = false;
                    if (SUBWAY_FREE_TRANSFER_STOPS.contains(ride.lastStop.getId())) {
                        lexFreeTransfer = true;
                    }
                    if (CANARSIE.contains(ride.lastStop.getId())) {
                        canarsieFreeTransfer = true;
                    }
                }
            /* FALL THROUGH */
            case SUBWAY_PRE_TRANSFER:
                // hours (if only just)
                if (ride.classifier.equals(WALK)) {
                    state = NycFareState.SUBWAY_PRE_TRANSFER_WALKED;
                } else if (ride.classifier.equals(SIR)) {
                    state = NycFareState.SIR_POST_TRANSFER_FROM_SUBWAY;
                } else if (ride.classifier.equals(LOCAL_BUS)) {
                    if (CANARSIE.contains(ride.firstStop.getId()) && canarsieFreeTransfer) {
                        state = NycFareState.BUS_PRE_TRANSFER;
                    } else {
                        state = NycFareState.INIT;
                    }
                } else if (ride.classifier.equals(EXPRESS_BUS)) {
                    // need to pay the upgrade cost
                    totalFare += EXPRESS_FARE - ORDINARY_FARE;
                } else if (ride.classifier.equals(EXPENSIVE_EXPRESS_BUS)) {
                    // no transfers to the
                    totalFare += EXPENSIVE_EXPRESS_FARE;
                // BxMM4C
                }
                break;
            case BUS_PRE_TRANSFER:
                if (ride.classifier.equals(SUBWAY)) {
                    if (CANARSIE.contains(ride.firstStop.getId()) && canarsieFreeTransfer) {
                        state = NycFareState.SUBWAY_PRE_TRANSFER;
                    } else {
                        state = NycFareState.INIT;
                    }
                } else if (ride.classifier.equals(SIR)) {
                    if (siLocalBus) {
                        // SI local bus to SIR, so it is as if we started on the
                        // SIR (except that when we enter the bus or subway system we need to do
                        // so at certain places)
                        sirBonusTransfer = true;
                        state = NycFareState.SIR_PRE_TRANSFER;
                    } else {
                        // transfers exhausted
                        state = NycFareState.INIT;
                    }
                } else if (ride.classifier.equals(LOCAL_BUS)) {
                    state = NycFareState.INIT;
                } else if (ride.classifier.equals(EXPRESS_BUS)) {
                    // need to pay the upgrade cost
                    totalFare += EXPRESS_FARE - ORDINARY_FARE;
                    state = NycFareState.INIT;
                } else if (ride.classifier.equals(EXPENSIVE_EXPRESS_BUS)) {
                    totalFare += EXPENSIVE_EXPRESS_FARE;
                // no transfers to the BxMM4C
                }
                break;
            case SIR_PRE_TRANSFER:
                if (ride.classifier.equals(SUBWAY)) {
                    if (sirBonusTransfer && !SIR_BONUS_STOPS.contains(ride.firstStop.getId())) {
                        // we were relying on the bonus transfer to be in the "pre-transfer state",
                        // but the bonus transfer does not apply here
                        totalFare += ORDINARY_FARE;
                    }
                    if (CANARSIE.contains(ride.lastStop.getId())) {
                        canarsieFreeTransfer = true;
                    }
                    state = NycFareState.SUBWAY_POST_TRANSFER;
                } else if (ride.classifier.equals(SIR)) {
                    /* should not happen, and unhandled */
                    LOG.warn("Should not transfer from SIR to SIR");
                } else if (ride.classifier.equals(LOCAL_BUS)) {
                    if (!SIR_BONUS_ROUTES.contains(ride.route)) {
                        totalFare += ORDINARY_FARE;
                    }
                    state = NycFareState.BUS_PRE_TRANSFER;
                } else if (ride.classifier.equals(EXPRESS_BUS)) {
                    totalFare += EXPRESS_BUS;
                    state = NycFareState.BUS_PRE_TRANSFER;
                } else if (ride.classifier.equals(EXPENSIVE_EXPRESS_BUS)) {
                    totalFare += EXPENSIVE_EXPRESS_BUS;
                    state = NycFareState.BUS_PRE_TRANSFER;
                }
                break;
            case SIR_POST_TRANSFER_FROM_SUBWAY:
                if (ride.classifier.equals(SUBWAY)) {
                    /* should not happen */
                    totalFare += ORDINARY_FARE;
                    state = NycFareState.SUBWAY_PRE_TRANSFER;
                } else if (ride.classifier.equals(SIR)) {
                    /* should not happen, and unhandled */
                    LOG.warn("Should not transfer from SIR to SIR");
                } else if (ride.classifier.equals(LOCAL_BUS)) {
                    if (!ride.route.getId().startsWith("S")) {
                        totalFare += ORDINARY_FARE;
                        state = NycFareState.BUS_PRE_TRANSFER;
                    } else {
                        state = NycFareState.INIT;
                    }
                } else if (ride.classifier.equals(EXPRESS_BUS)) {
                    // need to pay the full cost
                    totalFare += EXPRESS_FARE;
                    state = NycFareState.INIT;
                } else if (ride.classifier.equals(EXPENSIVE_EXPRESS_BUS)) {
                    /* should not happen */
                    // no transfers to the BxMM4C
                    totalFare += EXPENSIVE_EXPRESS_FARE;
                    state = NycFareState.BUS_PRE_TRANSFER;
                }
                break;
            case SUBWAY_POST_TRANSFER:
                if (ride.classifier.equals(WALK)) {
                    if (!canarsieFreeTransfer) {
                        /* note: if we end up walking to another subway after alighting
			    		 * at Canarsie, we will mistakenly not be charged, but nobody
			    		 * would ever do this */
                        state = NycFareState.INIT;
                    }
                } else if (ride.classifier.equals(SIR)) {
                    totalFare += ORDINARY_FARE;
                    state = NycFareState.SIR_PRE_TRANSFER;
                } else if (ride.classifier.equals(LOCAL_BUS)) {
                    if (!(CANARSIE.contains(ride.firstStop.getId()) && canarsieFreeTransfer)) {
                        totalFare += ORDINARY_FARE;
                    }
                    state = NycFareState.INIT;
                } else if (ride.classifier.equals(SUBWAY)) {
                    // walking transfer
                    totalFare += ORDINARY_FARE;
                    state = NycFareState.SUBWAY_PRE_TRANSFER;
                } else if (ride.classifier.equals(EXPRESS_BUS)) {
                    totalFare += EXPRESS_FARE;
                    state = NycFareState.BUS_PRE_TRANSFER;
                } else if (ride.classifier.equals(EXPENSIVE_EXPRESS_BUS)) {
                    totalFare += EXPENSIVE_EXPRESS_FARE;
                    state = NycFareState.BUS_PRE_TRANSFER;
                }
        }
    }
    Currency currency = Currency.getInstance("USD");
    Fare fare = new Fare();
    fare.addFare(FareType.regular, new WrappedCurrency(currency), (int) Math.round(totalFare * Math.pow(10, currency.getDefaultFractionDigits())));
    return fare;
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) DwellEdge(org.opentripplanner.routing.edgetype.DwellEdge) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ArrayList(java.util.ArrayList) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) WrappedCurrency(org.opentripplanner.routing.core.WrappedCurrency) Fare(org.opentripplanner.routing.core.Fare) HopEdge(org.opentripplanner.routing.edgetype.HopEdge) State(org.opentripplanner.routing.core.State) Currency(java.util.Currency) WrappedCurrency(org.opentripplanner.routing.core.WrappedCurrency) HopEdge(org.opentripplanner.routing.edgetype.HopEdge) DwellEdge(org.opentripplanner.routing.edgetype.DwellEdge) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge) Route(org.onebusaway.gtfs.model.Route)

Aggregations

Trip (org.onebusaway.gtfs.model.Trip)166 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)89 Test (org.junit.Test)56 StopTime (org.onebusaway.gtfs.model.StopTime)52 Route (org.onebusaway.gtfs.model.Route)51 Stop (org.onebusaway.gtfs.model.Stop)40 ArrayList (java.util.ArrayList)34 List (java.util.List)23 GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)21 TripPattern (org.opentripplanner.routing.edgetype.TripPattern)20 Agency (org.onebusaway.gtfs.model.Agency)19 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)19 HashMap (java.util.HashMap)14 ServiceCalendar (org.onebusaway.gtfs.model.ServiceCalendar)13 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)13 HashSet (java.util.HashSet)12 Vertex (org.opentripplanner.routing.graph.Vertex)12 FactoryMap (org.onebusaway.collections.FactoryMap)10 ServiceCalendarDate (org.onebusaway.gtfs.model.ServiceCalendarDate)10 ShapePoint (org.onebusaway.gtfs.model.ShapePoint)10