Skip to content

Commit

Permalink
Merge pull request #6329 from ibi-group/wsf-fares-calculation
Browse files Browse the repository at this point in the history
WSF calculate fares from GTFS
  • Loading branch information
leonardehrenfried authored Dec 11, 2024
2 parents cd254bf + 4141ce9 commit b5d5d54
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ public class OrcaFareServiceTest {

private static final Money ONE_DOLLAR = usDollars(1f);
private static final Money TWO_DOLLARS = usDollars(2);
private static final Money FERRY_FARE = usDollars(6.50f);
private static final Money HALF_FERRY_FARE = usDollars(3.25f);
private static final Money HALF_FERRY_FARE = usDollars(1.75f);
private static final Money ORCA_SPECIAL_FARE = usDollars(1.00f);
public static final Money VASHON_WATER_TAXI_CASH_FARE = usDollars(6.75f);
public static final Money WEST_SEATTLE_WATER_TAXI_CASH_FARE = usDollars(5.75f);
Expand Down Expand Up @@ -219,24 +218,24 @@ void calculateFareThatIncludesNoFreeTransfers() {
getLeg(KITSAP_TRANSIT_AGENCY_ID, 121),
getLeg(WASHINGTON_STATE_FERRIES_AGENCY_ID, 150, "Fauntleroy-VashonIsland")
);
calculateFare(rides, regular, DEFAULT_TEST_RIDE_PRICE.times(3).plus(FERRY_FARE));
calculateFare(rides, regular, DEFAULT_TEST_RIDE_PRICE.times(5));
calculateFare(
rides,
FareType.senior,
ONE_DOLLAR.plus(ONE_DOLLAR).plus(HALF_FERRY_FARE).plus(usDollars(0.5f))
ONE_DOLLAR.plus(ONE_DOLLAR).plus(HALF_FERRY_FARE.times(2)).plus(usDollars(0.5f))
);
calculateFare(rides, FareType.youth, Money.ZERO_USD);
// We don't get any fares for the skagit transit leg below here because they don't accept ORCA (electronic)
calculateFare(rides, FareType.electronicSpecial, ONE_DOLLAR.plus(ONE_DOLLAR).plus(FERRY_FARE));
calculateFare(rides, FareType.electronicSpecial, ONE_DOLLAR.plus(ONE_DOLLAR).plus(DEFAULT_TEST_RIDE_PRICE.times(2)));
calculateFare(
rides,
FareType.electronicRegular,
DEFAULT_TEST_RIDE_PRICE.times(2).plus(FERRY_FARE)
DEFAULT_TEST_RIDE_PRICE.times(4)
);
calculateFare(
rides,
FareType.electronicSenior,
ONE_DOLLAR.plus(ONE_DOLLAR).plus(HALF_FERRY_FARE)
ONE_DOLLAR.plus(ONE_DOLLAR).plus(HALF_FERRY_FARE.times(2))
);
calculateFare(rides, FareType.electronicYouth, ZERO_USD);
}
Expand Down Expand Up @@ -326,11 +325,11 @@ void calculateFareForWSFPtToTahlequah() {
List<Leg> rides = List.of(
getLeg(WASHINGTON_STATE_FERRIES_AGENCY_ID, 0, "Point Defiance - Tahlequah")
);
calculateFare(rides, regular, FERRY_FARE);
calculateFare(rides, regular, DEFAULT_TEST_RIDE_PRICE);
calculateFare(rides, FareType.senior, HALF_FERRY_FARE);
calculateFare(rides, FareType.youth, Money.ZERO_USD);
calculateFare(rides, FareType.electronicSpecial, FERRY_FARE);
calculateFare(rides, FareType.electronicRegular, FERRY_FARE);
calculateFare(rides, FareType.electronicSpecial, DEFAULT_TEST_RIDE_PRICE);
calculateFare(rides, FareType.electronicRegular, DEFAULT_TEST_RIDE_PRICE);
calculateFare(rides, FareType.electronicSenior, HALF_FERRY_FARE);
calculateFare(rides, FareType.electronicYouth, Money.ZERO_USD);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.opentripplanner.transit.model.basic.Money;
import org.opentripplanner.transit.model.framework.FeedScopedId;
import org.opentripplanner.transit.model.network.Route;
import org.opentripplanner.transit.model.organization.Agency;

public class OrcaFareService extends DefaultFareService {

Expand All @@ -39,7 +38,7 @@ public class OrcaFareService extends DefaultFareService {
public static final String PIERCE_COUNTY_TRANSIT_AGENCY_ID = "3";
public static final String SKAGIT_TRANSIT_AGENCY_ID = "e0e4541a-2714-487b-b30c-f5c6cb4a310f";
public static final String SEATTLE_STREET_CAR_AGENCY_ID = "23";
public static final String WASHINGTON_STATE_FERRIES_AGENCY_ID = "WSF";
public static final String WASHINGTON_STATE_FERRIES_AGENCY_ID = "95";
public static final String KITSAP_TRANSIT_AGENCY_ID = "kt";
public static final String WHATCOM_AGENCY_ID = "14";
public static final int ROUTE_TYPE_FERRY = 4;
Expand Down Expand Up @@ -398,28 +397,11 @@ private Money getWashingtonStateFerriesFare(
return defaultFare;
}

var longName = routeLongName.toString().replaceAll(" ", "");

Map<FareType, Money> fares = OrcaFaresData.washingtonStateFerriesFares.get(longName);
// WSF doesn't support transfers so we only care about cash fares.
FareType wsfFareType;
if (fareType == FareType.electronicRegular) {
wsfFareType = FareType.regular;
} else if (fareType == FareType.electronicSenior) {
wsfFareType = FareType.senior;
} else if (fareType == FareType.electronicYouth) {
wsfFareType = FareType.youth;
} else if (fareType == FareType.electronicSpecial) {
wsfFareType = FareType.regular;
} else {
wsfFareType = fareType;
}
// WSF is free in one direction on each route
// If a fare is not found in the map, we can assume it's free.
// Route long name is reversed for the reverse direction on a single WSF route
return (fares != null && fares.get(wsfFareType) != null)
? fares.get(wsfFareType)
: Money.ZERO_USD;
return switch (fareType) {
case youth, electronicYouth -> Money.ZERO_USD;
case regular, electronicRegular, electronicSpecial -> defaultFare;
case senior, electronicSenior -> defaultFare.half().roundDownToNearestFiveMinorUnits();
};
}

/**
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@ public Money half() {
return new Money(currency, IntUtils.round(amount / 2f));
}

/**
* Returns the instance rounded down to the nearest multiple of 5 cents
* So $0.14 becomes $0.10
*/
public Money roundDownToNearestFiveMinorUnits() {
int rounded = (this.minorUnitAmount() / 5) * 5;
return new Money(currency, rounded);
}

/**
* Multiplies the amount with the multiplicator.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ void half() {
assertEquals(Money.usDollars(0.38f), Money.usDollars(0.75f).half());
}

@Test
void roundDownToNearestFiveMinorUnits() {
assertEquals(Money.usDollars(0.1f), Money.usDollars(0.11f).roundDownToNearestFiveMinorUnits());
assertEquals(Money.usDollars(0.5f), Money.usDollars(0.54f).roundDownToNearestFiveMinorUnits());
}

@Test
void greaterThan() {
assertTrue(twoDollars.greaterThan(oneDollar));
Expand Down

0 comments on commit b5d5d54

Please sign in to comment.