Search in sources :

Example 6 with Fare

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());
}
Also used : Fare(com.conveyal.gtfs.model.Fare) Theory(org.junit.experimental.theories.Theory)

Example 7 with Fare

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);
}
Also used : FixedFareAttributeLoader(com.graphhopper.gtfs.fare.FixedFareAttributeLoader) FareRule(com.conveyal.gtfs.model.FareRule) Fare(com.conveyal.gtfs.model.Fare)

Example 8 with Fare

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;
}
Also used : CsvReader(com.csvreader.CsvReader) FareRule(com.conveyal.gtfs.model.FareRule) StringReader(java.io.StringReader) IOException(java.io.IOException) GTFSFeed(com.conveyal.gtfs.GTFSFeed) Fare(com.conveyal.gtfs.model.Fare)

Example 9 with Fare

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));
}
Also used : Fare(com.conveyal.gtfs.model.Fare) Theory(org.junit.experimental.theories.Theory)

Aggregations

Fare (com.conveyal.gtfs.model.Fare)9 FareRule (com.conveyal.gtfs.model.FareRule)3 Theory (org.junit.experimental.theories.Theory)3 GTFSFeed (com.conveyal.gtfs.GTFSFeed)2 Collectors (java.util.stream.Collectors)2 Collectors.toList (java.util.stream.Collectors.toList)2 IntHashSet (com.carrotsearch.hppc.IntHashSet)1 IntIntHashMap (com.carrotsearch.hppc.IntIntHashMap)1 IntLongHashMap (com.carrotsearch.hppc.IntLongHashMap)1 Agency (com.conveyal.gtfs.model.Agency)1 StopTime (com.conveyal.gtfs.model.StopTime)1 Trip (com.conveyal.gtfs.model.Trip)1 CsvReader (com.csvreader.CsvReader)1 GtfsRealtime (com.google.transit.realtime.GtfsRealtime)1 NO_DATA (com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.NO_DATA)1 SKIPPED (com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SKIPPED)1 FixedFareAttributeLoader (com.graphhopper.gtfs.fare.FixedFareAttributeLoader)1 VirtualEdgeIteratorState (com.graphhopper.routing.VirtualEdgeIteratorState)1 AllEdgesIterator (com.graphhopper.routing.util.AllEdgesIterator)1 EdgeFilter (com.graphhopper.routing.util.EdgeFilter)1