Search in sources :

Example 31 with FeedScopedId

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

the class NycFareServiceImpl method makeMtaStopList.

private static List<FeedScopedId> makeMtaStopList(String... stops) {
    ArrayList<FeedScopedId> out = new ArrayList<FeedScopedId>();
    for (String stop : stops) {
        out.add(new FeedScopedId("MTA NYCT", stop));
        out.add(new FeedScopedId("MTA NYCT", stop + "N"));
        out.add(new FeedScopedId("MTA NYCT", stop + "S"));
    }
    return out;
}
Also used : ArrayList(java.util.ArrayList) FeedScopedId(org.opentripplanner.model.FeedScopedId)

Example 32 with FeedScopedId

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

the class NycFareServiceImpl method getCost.

@Override
public Fare getCost(Path<TripSchedule> path, TransitLayer transitLayer) {
    // Use custom ride-categorizing method instead of the usual mapper from default fare service.
    List<Ride> rides = createRides(path, transitLayer);
    // 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) {
        FeedScopedId firstStopId = null;
        FeedScopedId 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(NycRideClassifier.WALK)) {
                // walking keeps you in init
                } else if (ride.classifier.equals(NycRideClassifier.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(NycRideClassifier.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(NycRideClassifier.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(NycRideClassifier.EXPRESS_BUS)) {
                    state = NycFareState.BUS_PRE_TRANSFER;
                    totalFare += EXPRESS_FARE;
                } else if (ride.classifier.equals(NycRideClassifier.EXPENSIVE_EXPRESS_BUS)) {
                    state = NycFareState.EXPENSIVE_EXPRESS_BUS;
                    totalFare += EXPENSIVE_EXPRESS_FARE;
                }
                break;
            case SUBWAY_PRE_TRANSFER_WALKED:
                if (ride.classifier.equals(NycRideClassifier.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(NycRideClassifier.WALK)) {
                    state = NycFareState.SUBWAY_PRE_TRANSFER_WALKED;
                } else if (ride.classifier.equals(NycRideClassifier.SIR)) {
                    state = NycFareState.SIR_POST_TRANSFER_FROM_SUBWAY;
                } else if (ride.classifier.equals(NycRideClassifier.LOCAL_BUS)) {
                    if (CANARSIE.contains(ride.firstStop.getId()) && canarsieFreeTransfer) {
                        state = NycFareState.BUS_PRE_TRANSFER;
                    } else {
                        state = NycFareState.INIT;
                    }
                } else if (ride.classifier.equals(NycRideClassifier.EXPRESS_BUS)) {
                    // need to pay the upgrade cost
                    totalFare += EXPRESS_FARE - ORDINARY_FARE;
                } else if (ride.classifier.equals(NycRideClassifier.EXPENSIVE_EXPRESS_BUS)) {
                    // no transfers to the
                    totalFare += EXPENSIVE_EXPRESS_FARE;
                // BxMM4C
                }
                break;
            case BUS_PRE_TRANSFER:
                if (ride.classifier.equals(NycRideClassifier.SUBWAY)) {
                    if (CANARSIE.contains(ride.firstStop.getId()) && canarsieFreeTransfer) {
                        state = NycFareState.SUBWAY_PRE_TRANSFER;
                    } else {
                        state = NycFareState.INIT;
                    }
                } else if (ride.classifier.equals(NycRideClassifier.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(NycRideClassifier.LOCAL_BUS)) {
                    state = NycFareState.INIT;
                } else if (ride.classifier.equals(NycRideClassifier.EXPRESS_BUS)) {
                    // need to pay the upgrade cost
                    totalFare += EXPRESS_FARE - ORDINARY_FARE;
                    state = NycFareState.INIT;
                } else if (ride.classifier.equals(NycRideClassifier.EXPENSIVE_EXPRESS_BUS)) {
                    totalFare += EXPENSIVE_EXPRESS_FARE;
                // no transfers to the BxMM4C
                }
                break;
            case SIR_PRE_TRANSFER:
                if (ride.classifier.equals(NycRideClassifier.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(NycRideClassifier.SIR)) {
                    /* should not happen, and unhandled */
                    LOG.warn("Should not transfer from SIR to SIR");
                } else if (ride.classifier.equals(NycRideClassifier.LOCAL_BUS)) {
                    if (!SIR_BONUS_ROUTES.contains(ride.route)) {
                        totalFare += ORDINARY_FARE;
                    }
                    state = NycFareState.BUS_PRE_TRANSFER;
                } else if (ride.classifier.equals(NycRideClassifier.EXPRESS_BUS)) {
                    totalFare += EXPRESS_FARE;
                    state = NycFareState.BUS_PRE_TRANSFER;
                } else if (ride.classifier.equals(NycRideClassifier.EXPENSIVE_EXPRESS_BUS)) {
                    totalFare += EXPENSIVE_EXPRESS_FARE;
                    state = NycFareState.BUS_PRE_TRANSFER;
                }
                break;
            case SIR_POST_TRANSFER_FROM_SUBWAY:
                if (ride.classifier.equals(NycRideClassifier.SUBWAY)) {
                    /* should not happen */
                    totalFare += ORDINARY_FARE;
                    state = NycFareState.SUBWAY_PRE_TRANSFER;
                } else if (ride.classifier.equals(NycRideClassifier.SIR)) {
                    /* should not happen, and unhandled */
                    LOG.warn("Should not transfer from SIR to SIR");
                } else if (ride.classifier.equals(NycRideClassifier.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(NycRideClassifier.EXPRESS_BUS)) {
                    // need to pay the full cost
                    totalFare += EXPRESS_FARE;
                    state = NycFareState.INIT;
                } else if (ride.classifier.equals(NycRideClassifier.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(NycRideClassifier.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(NycRideClassifier.SIR)) {
                    totalFare += ORDINARY_FARE;
                    state = NycFareState.SIR_PRE_TRANSFER;
                } else if (ride.classifier.equals(NycRideClassifier.LOCAL_BUS)) {
                    if (!(CANARSIE.contains(ride.firstStop.getId()) && canarsieFreeTransfer)) {
                        totalFare += ORDINARY_FARE;
                    }
                    state = NycFareState.INIT;
                } else if (ride.classifier.equals(NycRideClassifier.SUBWAY)) {
                    // walking transfer
                    totalFare += ORDINARY_FARE;
                    state = NycFareState.SUBWAY_PRE_TRANSFER;
                } else if (ride.classifier.equals(NycRideClassifier.EXPRESS_BUS)) {
                    totalFare += EXPRESS_FARE;
                    state = NycFareState.BUS_PRE_TRANSFER;
                } else if (ride.classifier.equals(NycRideClassifier.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 : Currency(java.util.Currency) WrappedCurrency(org.opentripplanner.routing.core.WrappedCurrency) FeedScopedId(org.opentripplanner.model.FeedScopedId) WrappedCurrency(org.opentripplanner.routing.core.WrappedCurrency) Fare(org.opentripplanner.routing.core.Fare)

Example 33 with FeedScopedId

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

the class SeattleFareServiceImpl method addFares.

@Override
protected float addFares(List<Ride> ride0, List<Ride> ride1, float cost0, float cost1) {
    String feedId = ride0.get(0).firstStop.getId().getFeedId();
    FeedScopedId agencyId = ride0.get(0).agency;
    if (KCM_FEED_ID.equals(feedId) && KCM_AGENCY_ID.equals(agencyId.getId())) {
        for (Ride r : Iterables.concat(ride0, ride1)) {
            if (!isCorrectAgency(r, feedId, agencyId)) {
                return cost0 + cost1;
            }
        }
        return Math.max(cost0, cost1);
    }
    return cost0 + cost1;
}
Also used : FeedScopedId(org.opentripplanner.model.FeedScopedId)

Example 34 with FeedScopedId

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

the class ToStringBuilderTest method addTransitEntity.

@Test
public void addTransitEntity() {
    Trip trip = new Trip();
    trip.setId(new FeedScopedId("F", "1"));
    assertEquals("ToStringBuilderTest{tripId: F:1}", subject().addEntityId("tripId", trip).toString());
}
Also used : Trip(org.opentripplanner.model.Trip) FeedScopedId(org.opentripplanner.model.FeedScopedId) Test(org.junit.Test)

Example 35 with FeedScopedId

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

the class CalendarServiceDataFactoryImplTest method createFareAttribute.

private static FareAttribute createFareAttribute(Agency agency) {
    FareAttribute fa = new FareAttribute();
    fa.setId(new FeedScopedId(FEED_ID, "FA"));
    return fa;
}
Also used : FareAttribute(org.opentripplanner.model.FareAttribute) FeedScopedId(org.opentripplanner.model.FeedScopedId)

Aggregations

FeedScopedId (org.opentripplanner.model.FeedScopedId)117 Trip (org.opentripplanner.model.Trip)32 Test (org.junit.Test)29 Stop (org.opentripplanner.model.Stop)25 TripPattern (org.opentripplanner.model.TripPattern)25 ServiceDate (org.opentripplanner.model.calendar.ServiceDate)21 ArrayList (java.util.ArrayList)20 Route (org.opentripplanner.model.Route)15 HashSet (java.util.HashSet)11 List (java.util.List)11 Agency (org.opentripplanner.model.Agency)11 Collection (java.util.Collection)9 Map (java.util.Map)9 Collectors (java.util.stream.Collectors)9 ZonedDateTime (java.time.ZonedDateTime)8 TransitEntity (org.opentripplanner.model.TransitEntity)8 RoutingService (org.opentripplanner.routing.RoutingService)8 TripTimes (org.opentripplanner.routing.trippattern.TripTimes)8 Notice (org.opentripplanner.model.Notice)7 Station (org.opentripplanner.model.Station)7