use of com.conveyal.gtfs.model.Fare in project graphhopper by graphhopper.
the class FareTest method canGoAllTheWayOnOneTicket.
@Theory
public void canGoAllTheWayOnOneTicket(Map<String, Fare> fares, Trip trip) throws IOException {
assumeThat("Only one fare.", fares.size(), equalTo(1));
Fare onlyFare = fares.values().iterator().next();
assumeThat("Fare allows the number of transfers we need for our trip.", onlyFare.fare_attribute.transfers, greaterThanOrEqualTo(trip.segments.size()));
assumeThat("Fare allows the time we need for our trip.", (long) onlyFare.fare_attribute.transfer_duration, greaterThanOrEqualTo(trip.segments.get(trip.segments.size() - 1).getStartTime() - trip.segments.get(0).getStartTime()));
Amount amount = Fares.cheapestFare(fares, trip).get();
Assert.assertEquals(BigDecimal.valueOf(onlyFare.fare_attribute.price), amount.getAmount());
}
use of com.conveyal.gtfs.model.Fare in project graphhopper by graphhopper.
the class GtfsStorage method fixFares.
private void fixFares(GTFSFeed feed, ZipFile zip) {
feed.fares.clear();
Map<String, Fare> fares = new HashMap<>();
try {
new FixedFareAttributeLoader(feed, fares).loadTable(zip);
new FareRule.Loader(feed, fares).loadTable(zip);
} catch (IOException e) {
throw new RuntimeException(e);
}
feed.fares.putAll(fares);
}
use of com.conveyal.gtfs.model.Fare in project graphhopper by graphhopper.
the class FareTest method parseFares.
private static Map<String, Fare> parseFares(String fareAttributes, String fareRules) {
GTFSFeed feed = new GTFSFeed();
HashMap<String, Fare> fares = new HashMap<>();
new FixedFareAttributeLoader(feed, fares) {
void load(String input) {
reader = new CsvReader(new StringReader(input));
reader.setHeaders(new String[] { "fare_id", "price", "currency_type", "payment_method", "transfers", "transfer_duration" });
try {
while (reader.readRecord()) {
loadOneRow();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}.load(fareAttributes);
new FareRule.Loader(feed, fares) {
void load(String input) {
reader = new CsvReader(new StringReader(input));
reader.setHeaders(new String[] { "fare_id", "route_id", "origin_id", "destination_id", "contains_id" });
try {
while (reader.readRecord()) {
loadOneRow();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}.load(fareRules);
return fares;
}
use of com.conveyal.gtfs.model.Fare in project graphhopper by graphhopper.
the class FareTest method buyMoreThanOneTicketIfTripIsLongerThanAllowedOnOne.
@Theory
public void buyMoreThanOneTicketIfTripIsLongerThanAllowedOnOne(Map<String, Fare> fares, Trip trip) throws IOException {
assumeThat("Only one fare.", fares.size(), equalTo(1));
Fare onlyFare = fares.values().iterator().next();
assumeThat("We have a transfer", trip.segments.size(), greaterThan(1));
assumeThat("Fare allows the number of transfers we need for our trip.", onlyFare.fare_attribute.transfers, greaterThanOrEqualTo(trip.segments.size()));
assumeThat("Fare does not allow the time we need for our trip.", (long) onlyFare.fare_attribute.transfer_duration, lessThan(trip.segments.get(trip.segments.size() - 1).getStartTime() - trip.segments.get(0).getStartTime()));
Amount amount = Fares.cheapestFare(fares, trip).get();
assertThat(amount.getAmount().doubleValue(), greaterThan(onlyFare.fare_attribute.price));
}
Aggregations