Search in sources :

Example 36 with StopTime

use of org.onebusaway.gtfs.model.StopTime in project onebusaway-gtfs-modules by OneBusAway.

the class GtfsReaderTest method testTestAgency.

@Test
public void testTestAgency() throws IOException {
    String agencyId = "agency";
    GtfsRelationalDao dao = processFeed(GtfsTestData.getTestAgencyGtfs(), agencyId, false);
    Agency agency = dao.getAgencyForId(agencyId);
    assertEquals(agencyId, agency.getId());
    assertEquals("Fake Agency", agency.getName());
    assertEquals("http://fake.example.com", agency.getUrl());
    assertEquals("America/New_York", agency.getTimezone());
    assertNull(agency.getPhone());
    Stop stopA = dao.getStopForId(new AgencyAndId(agencyId, "A"));
    assertEquals(1, stopA.getWheelchairBoarding());
    Stop stopC = dao.getStopForId(new AgencyAndId(agencyId, "C"));
    assertEquals(0, stopC.getWheelchairBoarding());
    Stop stopF = dao.getStopForId(new AgencyAndId(agencyId, "C"));
    assertEquals(0, stopF.getWheelchairBoarding());
    Trip tripA = dao.getTripForId(new AgencyAndId(agencyId, "1.1"));
    assertEquals(1, tripA.getWheelchairAccessible());
    Trip tripB = dao.getTripForId(new AgencyAndId(agencyId, "2.1"));
    assertEquals(0, tripB.getWheelchairAccessible());
    Trip tripC = dao.getTripForId(new AgencyAndId(agencyId, "4.1"));
    assertEquals(0, tripC.getWheelchairAccessible());
    Trip trip12 = dao.getTripForId(new AgencyAndId(agencyId, "1.2"));
    List<StopTime> stopTimes = dao.getStopTimesForTrip(trip12);
    assertEquals(3, stopTimes.size());
    StopTime stopTimeA = stopTimes.get(0);
    assertTrue(stopTimeA.isArrivalTimeSet());
    assertTrue(stopTimeA.isDepartureTimeSet());
    assertEquals(20 * 60, stopTimeA.getArrivalTime());
    assertEquals(20 * 60, stopTimeA.getDepartureTime());
    assertEquals(0, stopTimeA.getDropOffType());
    assertEquals(0, stopTimeA.getPickupType());
    assertNull(stopTimeA.getRouteShortName());
    assertEquals(0, stopTimeA.getShapeDistTraveled(), 0.0);
    assertEquals(new AgencyAndId(agencyId, "A"), stopTimeA.getStop().getId());
    assertNull(stopTimeA.getStopHeadsign());
    assertEquals(1, stopTimeA.getStopSequence());
    assertEquals(trip12, stopTimeA.getTrip());
    StopTime stopTimeB = stopTimes.get(1);
    assertFalse(stopTimeB.isArrivalTimeSet());
    assertFalse(stopTimeB.isDepartureTimeSet());
    assertEquals(2, stopTimeB.getDropOffType());
    assertEquals(3, stopTimeB.getPickupType());
    assertNull(stopTimeB.getRouteShortName());
    assertFalse(stopTimeB.isShapeDistTraveledSet());
    assertEquals(new AgencyAndId(agencyId, "B"), stopTimeB.getStop().getId());
    assertNull(stopTimeB.getStopHeadsign());
    assertEquals(2, stopTimeB.getStopSequence());
    assertEquals(trip12, stopTimeB.getTrip());
    StopTime stopTimeC = stopTimes.get(2);
    assertTrue(stopTimeC.isArrivalTimeSet());
    assertTrue(stopTimeC.isDepartureTimeSet());
    assertEquals(40 * 60, stopTimeC.getArrivalTime());
    assertEquals(40 * 60, stopTimeC.getDepartureTime());
    assertEquals(0, stopTimeC.getDropOffType());
    assertEquals(0, stopTimeC.getPickupType());
    assertEquals(52.1, stopTimeC.getShapeDistTraveled(), 0.0);
    assertEquals(new AgencyAndId(agencyId, "C"), stopTimeC.getStop().getId());
    assertNull(stopTimeC.getStopHeadsign());
    assertEquals(3, stopTimeC.getStopSequence());
    assertEquals(trip12, stopTimeC.getTrip());
}
Also used : GtfsRelationalDao(org.onebusaway.gtfs.services.GtfsRelationalDao) Trip(org.onebusaway.gtfs.model.Trip) Agency(org.onebusaway.gtfs.model.Agency) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) StopTime(org.onebusaway.gtfs.model.StopTime) Test(org.junit.Test)

Example 37 with StopTime

use of org.onebusaway.gtfs.model.StopTime in project onebusaway-gtfs-modules by OneBusAway.

the class GtfsReaderTest method testAllFields.

@Test
public void testAllFields() throws IOException {
    MockGtfs gtfs = MockGtfs.create();
    gtfs.putLines("block.txt", "block_seq_num,block_var_num,block_route_num,block_run_num", "4237385,1,599,1");
    gtfs.putLines("agency.txt", "agency_id,agency_name,agency_url,agency_timezone,agency_lang,agency_phone,agency_fare_url", "1,Agency,http://agency.gov/,America/Los_Angeles,en,555-1234,http://agency.gov/fares");
    gtfs.putLines("stops.txt", "stop_id,stop_name,stop_lat,stop_lon,stop_desc,stop_code,stop_direction,location_type,parent_station," + "stop_url,wheelchair_boarding,zone_id,stop_timezone,vehicle_type,platform_code", "S1,Stop,47.0,-122.0,description,123,N,1,1234,http://agency.gov/stop,1,Z,America/New_York,2,9 3/4");
    gtfs.putLines("routes.txt", "agency_id,route_id,route_short_name,route_long_name,route_type,route_desc,route_color,route_text_color," + "route_bikes_allowed,bikes_allowed,route_url,route_sort_order", "1,R1,10,The Ten,3,route desc,FF0000,0000FF,1,2,http://agency.gov/route,100");
    gtfs.putLines("trips.txt", "route_id,service_id,trip_id,trip_headsign,trip_short_name,direction_id,block_id,shape_id,route_short_name," + "trip_bikes_allowed,bikes_allowed,wheelchair_accessible", "R1,WEEK,T1,head-sign,short-name,1,B1,SHP1,10X,1,2,1");
    gtfs.putLines("stop_times.txt", "trip_id,arrival_time,departure_time,stop_id,stop_sequence,stop_headsign,pickup_type,drop_off_type," + "shape_dist_traveled,route_short_name,timepoint", "T1,09:01:30,10:20:02,S1,2,head-sign,1,2,23.1,10X,1");
    gtfs.putLines("calendar.txt", "service_id,start_date,end_date,monday,tuesday,wednesday,thursday,friday,saturday,sunday", "WEEK,20120105,20120215,1,1,1,1,1,1,1");
    gtfs.putLines("calendar_dates.txt", "service_id,date,exception_type", "WEEK,20120304,2");
    gtfs.putLines("fare_attributes.txt", "fare_id,price,currency_type,payment_method,transfers,transfer_duration,journey_duration", "FA1,2.0,USD,1,2,60,61");
    gtfs.putLines("fare_rules.txt", "fare_id,route_id,origin_id,destination_id,contains_id", "FA1,R1,Z1,Z2,Z3");
    gtfs.putLines("shapes.txt", "shape_id,shape_pt_sequence,shape_pt_lat,shape_pt_lon,shape_dist_traveled", "SHP1,2,47.0,-122.0,123.4");
    gtfs.putLines("frequencies.txt", "trip_id,start_time,end_time,headway_secs,exact_times,label_only", "T1,09:01:30,10:20:02,300,1,1");
    gtfs.putLines("transfers.txt", "from_stop_id,from_route_id,from_trip_id,to_stop_id,to_route_id,to_trip_id,transfer_type,min_transfer_time", "S1,R1,T1,S1,R1,T1,2,60");
    gtfs.putLines("feed_info.txt", "feed_publisher_name,feed_publisher_url,feed_lang,feed_start_date,feed_end_date,feed_version", "Test,http://agency.gov/,en,20120110,20120217,2.0");
    gtfs.putLines("pathways.txt", "pathway_id,pathway_type,from_stop_id,to_stop_id,traversal_time,wheelchair_traversal_time", "P1,1,S1,S1,60,61");
    GtfsRelationalDao dao = processFeed(gtfs.getPath(), "1", false);
    Agency agency = dao.getAgencyForId("1");
    assertEquals("1", agency.getId());
    assertEquals("Agency", agency.getName());
    assertEquals("http://agency.gov/", agency.getUrl());
    assertEquals("America/Los_Angeles", agency.getTimezone());
    assertEquals("en", agency.getLang());
    assertEquals("555-1234", agency.getPhone());
    assertEquals("http://agency.gov/fares", agency.getFareUrl());
    Block block = dao.getBlockForId(1);
    assertNotNull(block);
    assertEquals(4237385, block.getBlockSequence());
    assertEquals(1, block.getBlockVariable());
    assertEquals(599, block.getBlockRoute());
    assertEquals(1, block.getBlockRun());
    Stop stop = dao.getStopForId(new AgencyAndId("1", "S1"));
    assertEquals(new AgencyAndId("1", "S1"), stop.getId());
    assertEquals("Stop", stop.getName());
    assertEquals(47.0, stop.getLat(), 0.0);
    assertEquals(-122.0, stop.getLon(), 0.0);
    assertEquals("description", stop.getDesc());
    assertEquals("123", stop.getCode());
    assertEquals("N", stop.getDirection());
    assertEquals(1, stop.getLocationType());
    assertEquals("1234", stop.getParentStation());
    assertEquals("http://agency.gov/stop", stop.getUrl());
    assertEquals(1, stop.getWheelchairBoarding());
    assertEquals("Z", stop.getZoneId());
    assertEquals("America/New_York", stop.getTimezone());
    assertEquals(2, stop.getVehicleType());
    assertEquals("9 3/4", stop.getPlatformCode());
    Route route = dao.getRouteForId(new AgencyAndId("1", "R1"));
    assertEquals(new AgencyAndId("1", "R1"), route.getId());
    assertEquals(agency, route.getAgency());
    assertEquals("10", route.getShortName());
    assertEquals("The Ten", route.getLongName());
    assertEquals(3, route.getType());
    assertEquals("route desc", route.getDesc());
    assertEquals("FF0000", route.getColor());
    assertEquals("0000FF", route.getTextColor());
    assertEquals(1, route.getRouteBikesAllowed());
    assertEquals(2, route.getBikesAllowed());
    assertEquals("http://agency.gov/route", route.getUrl());
    assertEquals(100, route.getSortOrder());
    Trip trip = dao.getTripForId(new AgencyAndId("1", "T1"));
    assertEquals(new AgencyAndId("1", "T1"), trip.getId());
    assertEquals(route, trip.getRoute());
    assertEquals(new AgencyAndId("1", "WEEK"), trip.getServiceId());
    assertEquals("head-sign", trip.getTripHeadsign());
    assertEquals("short-name", trip.getTripShortName());
    assertEquals("1", trip.getDirectionId());
    assertEquals("B1", trip.getBlockId());
    assertEquals(new AgencyAndId("1", "SHP1"), trip.getShapeId());
    assertEquals("10X", trip.getRouteShortName());
    assertEquals(1, trip.getTripBikesAllowed());
    assertEquals(2, trip.getBikesAllowed());
    assertEquals(1, trip.getWheelchairAccessible());
    List<StopTime> stopTimes = dao.getStopTimesForTrip(trip);
    StopTime stopTime = stopTimes.get(0);
    assertEquals(trip, stopTime.getTrip());
    assertEquals(stop, stopTime.getStop());
    assertEquals((9 * 60 + 1) * 60 + 30, stopTime.getArrivalTime());
    assertEquals((10 * 60 + 20) * 60 + 2, stopTime.getDepartureTime());
    assertEquals(2, stopTime.getStopSequence());
    assertEquals("head-sign", stopTime.getStopHeadsign());
    assertEquals(1, stopTime.getPickupType());
    assertEquals(2, stopTime.getDropOffType());
    assertEquals(23.1, stopTime.getShapeDistTraveled(), 0.0);
    assertEquals("10X", stopTime.getRouteShortName());
    assertEquals(1, stopTime.getTimepoint());
    ServiceCalendar calendar = dao.getCalendarForServiceId(new AgencyAndId("1", "WEEK"));
    assertEquals(new AgencyAndId("1", "WEEK"), calendar.getServiceId());
    assertEquals(new ServiceDate(2012, 01, 05), calendar.getStartDate());
    assertEquals(new ServiceDate(2012, 02, 15), calendar.getEndDate());
    assertEquals(1, calendar.getMonday());
    assertEquals(1, calendar.getTuesday());
    assertEquals(1, calendar.getWednesday());
    assertEquals(1, calendar.getThursday());
    assertEquals(1, calendar.getFriday());
    assertEquals(1, calendar.getSaturday());
    assertEquals(1, calendar.getSunday());
    List<ServiceCalendarDate> calendarDates = dao.getCalendarDatesForServiceId(new AgencyAndId("1", "WEEK"));
    ServiceCalendarDate calendarDate = calendarDates.get(0);
    assertEquals(new AgencyAndId("1", "WEEK"), calendarDate.getServiceId());
    assertEquals(new ServiceDate(2012, 03, 04), calendarDate.getDate());
    assertEquals(2, calendarDate.getExceptionType());
    FareAttribute fareAttribute = dao.getFareAttributeForId(new AgencyAndId("1", "FA1"));
    assertEquals(new AgencyAndId("1", "FA1"), fareAttribute.getId());
    assertEquals(2.0, fareAttribute.getPrice(), 1.0);
    assertEquals("USD", fareAttribute.getCurrencyType());
    assertEquals(1, fareAttribute.getPaymentMethod());
    assertEquals(2, fareAttribute.getTransfers());
    assertEquals(60, fareAttribute.getTransferDuration());
    assertEquals(61, fareAttribute.getJourneyDuration());
    List<FareRule> rules = dao.getFareRulesForFareAttribute(fareAttribute);
    FareRule fareRule = rules.get(0);
    assertEquals(fareAttribute, fareRule.getFare());
    assertEquals(route, fareRule.getRoute());
    assertEquals("Z1", fareRule.getOriginId());
    assertEquals("Z2", fareRule.getDestinationId());
    assertEquals("Z3", fareRule.getContainsId());
    List<ShapePoint> shapePoints = dao.getShapePointsForShapeId(new AgencyAndId("1", "SHP1"));
    ShapePoint shapePoint = shapePoints.get(0);
    assertEquals(new AgencyAndId("1", "SHP1"), shapePoint.getShapeId());
    assertEquals(2, shapePoint.getSequence());
    assertEquals(47.0, shapePoint.getLat(), 0.0);
    assertEquals(-122.0, shapePoint.getLon(), 0.0);
    assertEquals(123.4, shapePoint.getDistTraveled(), 0.0);
    List<Frequency> frequencies = dao.getFrequenciesForTrip(trip);
    Frequency frequency = frequencies.get(0);
    assertEquals(trip, frequency.getTrip());
    assertEquals((9 * 60 + 1) * 60 + 30, frequency.getStartTime());
    assertEquals((10 * 60 + 20) * 60 + 2, frequency.getEndTime());
    assertEquals(300, frequency.getHeadwaySecs());
    assertEquals(1, frequency.getExactTimes());
    assertEquals(1, frequency.getLabelOnly());
    Transfer transfer = dao.getAllTransfers().iterator().next();
    assertEquals(stop, transfer.getFromStop());
    assertEquals(route, transfer.getFromRoute());
    assertEquals(trip, transfer.getFromTrip());
    assertEquals(stop, transfer.getToStop());
    assertEquals(route, transfer.getToRoute());
    assertEquals(trip, transfer.getToTrip());
    assertEquals(2, transfer.getTransferType(), 1);
    assertEquals(60, transfer.getMinTransferTime());
    FeedInfo feedInfo = dao.getAllFeedInfos().iterator().next();
    assertEquals("Test", feedInfo.getPublisherName());
    assertEquals("http://agency.gov/", feedInfo.getPublisherUrl());
    assertEquals("en", feedInfo.getLang());
    assertEquals(new ServiceDate(2012, 1, 10), feedInfo.getStartDate());
    assertEquals(new ServiceDate(2012, 2, 17), feedInfo.getEndDate());
    assertEquals("2.0", feedInfo.getVersion());
    Pathway pathway = dao.getAllPathways().iterator().next();
    assertEquals(new AgencyAndId("1", "P1"), pathway.getId());
    assertEquals(1, pathway.getPathwayType());
    assertEquals(stop, pathway.getFromStop());
    assertEquals(stop, pathway.getToStop());
    assertEquals(60, pathway.getTraversalTime());
    assertEquals(61, pathway.getWheelchairTraversalTime());
}
Also used : ServiceCalendarDate(org.onebusaway.gtfs.model.ServiceCalendarDate) FareAttribute(org.onebusaway.gtfs.model.FareAttribute) GtfsRelationalDao(org.onebusaway.gtfs.services.GtfsRelationalDao) Trip(org.onebusaway.gtfs.model.Trip) Agency(org.onebusaway.gtfs.model.Agency) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) Pathway(org.onebusaway.gtfs.model.Pathway) MockGtfs(org.onebusaway.gtfs.services.MockGtfs) FareRule(org.onebusaway.gtfs.model.FareRule) FeedInfo(org.onebusaway.gtfs.model.FeedInfo) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) ShapePoint(org.onebusaway.gtfs.model.ShapePoint) Transfer(org.onebusaway.gtfs.model.Transfer) Block(org.onebusaway.gtfs.model.Block) Frequency(org.onebusaway.gtfs.model.Frequency) Route(org.onebusaway.gtfs.model.Route) StopTime(org.onebusaway.gtfs.model.StopTime) ServiceCalendar(org.onebusaway.gtfs.model.ServiceCalendar) Test(org.junit.Test)

Aggregations

StopTime (org.onebusaway.gtfs.model.StopTime)37 Trip (org.onebusaway.gtfs.model.Trip)22 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)15 Test (org.junit.Test)12 Stop (org.onebusaway.gtfs.model.Stop)11 ShapePoint (org.onebusaway.gtfs.model.ShapePoint)8 ArrayList (java.util.ArrayList)7 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)7 List (java.util.List)6 Agency (org.onebusaway.gtfs.model.Agency)6 ServiceCalendar (org.onebusaway.gtfs.model.ServiceCalendar)5 GtfsRelationalDao (org.onebusaway.gtfs.services.GtfsRelationalDao)5 HashSet (java.util.HashSet)4 Frequency (org.onebusaway.gtfs.model.Frequency)4 Route (org.onebusaway.gtfs.model.Route)4 ServiceCalendarDate (org.onebusaway.gtfs.model.ServiceCalendarDate)4 HashMap (java.util.HashMap)3 FareAttribute (org.onebusaway.gtfs.model.FareAttribute)3 FareRule (org.onebusaway.gtfs.model.FareRule)3 GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)3