Search in sources :

Example 21 with ServiceCalendar

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

the class GtfsDaoImplTest method testBart.

@Test
public void testBart() throws IOException {
    GtfsDaoImpl dao = new GtfsDaoImpl();
    GtfsTestData.readGtfs(dao, GtfsTestData.getBartGtfs(), "BART");
    Collection<Agency> agencies = dao.getAllAgencies();
    assertEquals(2, agencies.size());
    Agency agency = dao.getAgencyForId("BART");
    assertEquals("BART", agency.getId());
    Collection<ServiceCalendarDate> calendarDates = dao.getAllCalendarDates();
    assertEquals(32, calendarDates.size());
    ServiceCalendarDate calendarDate = dao.getCalendarDateForId(1);
    assertEquals(new AgencyAndId("BART", "SUN"), calendarDate.getServiceId());
    assertEquals(new ServiceDate(2009, 1, 1), calendarDate.getDate());
    assertEquals(1, calendarDate.getExceptionType());
    Collection<ServiceCalendar> calendars = dao.getAllCalendars();
    assertEquals(5, calendars.size());
    ServiceCalendar calendar = dao.getCalendarForId(1);
    assertEquals(new AgencyAndId("BART", "WKDY"), calendar.getServiceId());
    assertEquals(new ServiceDate(2007, 1, 1), calendar.getStartDate());
    assertEquals(new ServiceDate(2010, 12, 31), calendar.getEndDate());
    assertEquals(1, calendar.getMonday());
    assertEquals(1, calendar.getTuesday());
    assertEquals(1, calendar.getWednesday());
    assertEquals(1, calendar.getThursday());
    assertEquals(1, calendar.getFriday());
    assertEquals(0, calendar.getSaturday());
    assertEquals(0, calendar.getSunday());
    Collection<FareAttribute> fareAttributes = dao.getAllFareAttributes();
    assertEquals(106, fareAttributes.size());
    FareAttribute fareAttribute = dao.getFareAttributeForId(new AgencyAndId("BART", "30"));
    assertEquals(new AgencyAndId("BART", "30"), fareAttribute.getId());
    Collection<FareRule> fareRules = dao.getAllFareRules();
    assertEquals(1849, fareRules.size());
    FareRule fareRule = dao.getFareRuleForId(1);
    assertEquals(new AgencyAndId("BART", "98"), fareRule.getFare().getId());
    Collection<Frequency> frequencies = dao.getAllFrequencies();
    assertEquals(6, frequencies.size());
    Frequency frequency = dao.getFrequencyForId(1);
    assertEquals(new AgencyAndId("AirBART", "M-FSAT1DN"), frequency.getTrip().getId());
    Collection<Route> routes = dao.getAllRoutes();
    assertEquals(11, routes.size());
    Route route = dao.getRouteForId(new AgencyAndId("BART", "01"));
    assertEquals(new AgencyAndId("BART", "01"), route.getId());
    Collection<ShapePoint> shapePoints = dao.getAllShapePoints();
    assertEquals(105, shapePoints.size());
    ShapePoint shapePoint = dao.getShapePointForId(1);
    assertEquals(new AgencyAndId("BART", "airbart-dn.csv"), shapePoint.getShapeId());
    Collection<Stop> stops = dao.getAllStops();
    assertEquals(46, stops.size());
    Stop stop = dao.getStopForId(new AgencyAndId("BART", "DBRK"));
    assertEquals("Downtown Berkeley BART", stop.getName());
    Collection<StopTime> stopTimes = dao.getAllStopTimes();
    assertEquals(33270, stopTimes.size());
    StopTime stopTime = stopTimes.iterator().next();
    assertEquals(18000, stopTime.getArrivalTime());
    Collection<Transfer> transfers = dao.getAllTransfers();
    assertEquals(4, transfers.size());
    Transfer transfer = dao.getTransferForId(1);
    assertEquals(1, transfer.getTransferType());
    Collection<Trip> trips = dao.getAllTrips();
    assertEquals(1620, trips.size());
    Trip trip = dao.getTripForId(new AgencyAndId("BART", "15PB1"));
    assertEquals(new AgencyAndId("BART", "WKDY"), trip.getServiceId());
}
Also used : FareAttribute(org.onebusaway.gtfs.model.FareAttribute) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) ShapePoint(org.onebusaway.gtfs.model.ShapePoint) Route(org.onebusaway.gtfs.model.Route) StopTime(org.onebusaway.gtfs.model.StopTime) ServiceCalendarDate(org.onebusaway.gtfs.model.ServiceCalendarDate) Trip(org.onebusaway.gtfs.model.Trip) Agency(org.onebusaway.gtfs.model.Agency) FareRule(org.onebusaway.gtfs.model.FareRule) Transfer(org.onebusaway.gtfs.model.Transfer) Frequency(org.onebusaway.gtfs.model.Frequency) ServiceCalendar(org.onebusaway.gtfs.model.ServiceCalendar) Test(org.junit.Test)

Example 22 with ServiceCalendar

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

the class CalendarServiceDataFactoryImplSyntheticTest method testDaylightSavingTime.

@Test
public void testDaylightSavingTime() {
    CalendarServiceDataFactoryImpl factory = new CalendarServiceDataFactoryImpl();
    Agency agencyA = agency("A", "America/Los_Angeles");
    AgencyAndId serviceId = new AgencyAndId("A", "2");
    ServiceDate dStart = new ServiceDate(2012, 3, 1);
    ServiceDate dEnd = new ServiceDate(2012, 3, 31);
    ServiceCalendar c = calendar(serviceId, dStart, dEnd, "1111111");
    GtfsRelationalDaoImpl dao = new GtfsRelationalDaoImpl();
    factory.setGtfsDao(dao);
    saveEntities(dao, agencyA);
    saveEntities(dao, c);
    CalendarServiceData data = factory.createData();
    List<ServiceDate> serviceDates = data.getServiceDatesForServiceId(serviceId);
    assertTrue(serviceDates.contains(new ServiceDate(2012, 3, 11)));
}
Also used : CalendarServiceData(org.onebusaway.gtfs.model.calendar.CalendarServiceData) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) Agency(org.onebusaway.gtfs.model.Agency) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) GtfsRelationalDaoImpl(org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl) ServiceCalendar(org.onebusaway.gtfs.model.ServiceCalendar) Test(org.junit.Test)

Example 23 with ServiceCalendar

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

the class CalendarServiceDataFactoryImplSyntheticTest method test.

@Test
public void test() {
    CalendarServiceDataFactoryImpl factory = new CalendarServiceDataFactoryImpl();
    Agency agencyA = agency("A", "America/Los_Angeles");
    Agency agencyB = agency("B", "America/Denver");
    AgencyAndId serviceIdA1 = new AgencyAndId("A", "1");
    AgencyAndId serviceIdA2 = new AgencyAndId("A", "2");
    AgencyAndId serviceIdB1 = new AgencyAndId("B", "1");
    ServiceDate dStart = new ServiceDate(2010, 2, 10);
    ServiceDate dEnd = new ServiceDate(2010, 2, 24);
    ServiceCalendar c1 = calendar(serviceIdA1, dStart, dEnd, "1111100");
    ServiceCalendar c2 = calendar(serviceIdA2, dStart, dEnd, "1111111");
    ServiceCalendar c3 = calendar(serviceIdB1, dStart, dEnd, "0000011");
    ServiceCalendarDate cd1 = calendarDate(serviceIdA2, new ServiceDate(2010, 2, 15), ServiceCalendarDate.EXCEPTION_TYPE_REMOVE);
    ServiceCalendarDate cd2 = calendarDate(serviceIdA2, new ServiceDate(2010, 2, 26), ServiceCalendarDate.EXCEPTION_TYPE_ADD);
    Trip t1 = trip("A", "1", serviceIdA1);
    Trip t2 = trip("A", "2", serviceIdA1);
    Trip t3 = trip("A", "3", serviceIdA2);
    Trip t4 = trip("B", "4", serviceIdA2);
    Trip t5 = trip("B", "5", serviceIdB1);
    Trip t6 = trip("B", "6", serviceIdB1);
    GtfsRelationalDaoImpl dao = new GtfsRelationalDaoImpl();
    factory.setGtfsDao(dao);
    saveEntities(dao, agencyA, agencyB);
    saveEntities(dao, c1, c2, c3);
    saveEntities(dao, cd1, cd2);
    saveEntities(dao, t1, t2, t3, t4, t5, t6);
    CalendarServiceData data = factory.createData();
    TimeZone tzA = TimeZone.getTimeZone("America/Los_Angeles");
    TimeZone tzB = TimeZone.getTimeZone("America/Denver");
    assertEquals(tzA, data.getTimeZoneForAgencyId("A"));
    assertEquals(tzB, data.getTimeZoneForAgencyId("B"));
    assertNull(data.getTimeZoneForAgencyId("DNE"));
    Set<AgencyAndId> serviceIds = data.getServiceIds();
    assertEquals(3, serviceIds.size());
    assertTrue(serviceIds.contains(serviceIdA1));
    assertTrue(serviceIds.contains(serviceIdA2));
    assertTrue(serviceIds.contains(serviceIdB1));
    // M-F only for this service id
    List<ServiceDate> serviceDates = data.getServiceDatesForServiceId(serviceIdA1);
    assertEquals(11, serviceDates.size());
    assertEquals(dStart, serviceDates.get(0));
    assertEquals(new ServiceDate(2010, 2, 16), serviceDates.get(4));
    assertEquals(dEnd, serviceDates.get(10));
    // 7-days a week, with some calendar modifications for this service id
    serviceDates = data.getServiceDatesForServiceId(serviceIdA2);
    assertEquals(15, serviceDates.size());
    assertEquals(dStart, serviceDates.get(0));
    assertEquals(new ServiceDate(2010, 2, 14), serviceDates.get(4));
    // 2010-02-15 should be excluded
    assertEquals(new ServiceDate(2010, 2, 16), serviceDates.get(5));
    // 2010-02-26 should be added
    assertEquals(new ServiceDate(2010, 2, 26), serviceDates.get(14));
    // Just weekends for this service id
    serviceDates = data.getServiceDatesForServiceId(serviceIdB1);
    assertEquals(4, serviceDates.size());
    assertEquals(new ServiceDate(2010, 2, 13), serviceDates.get(0));
    assertEquals(new ServiceDate(2010, 2, 14), serviceDates.get(1));
    assertEquals(new ServiceDate(2010, 2, 20), serviceDates.get(2));
    assertEquals(new ServiceDate(2010, 2, 21), serviceDates.get(3));
    // Service id does not exist
    serviceDates = data.getServiceDatesForServiceId(new AgencyAndId("DNE", "DNE"));
    assertNull(serviceDates);
    // Service ids for dates
    Set<AgencyAndId> serviceIdsForDate = data.getServiceIdsForDate(new ServiceDate(2010, 2, 10));
    assertEquals(2, serviceIdsForDate.size());
    assertTrue(serviceIdsForDate.contains(serviceIdA1));
    assertTrue(serviceIdsForDate.contains(serviceIdA2));
    serviceIdsForDate = data.getServiceIdsForDate(new ServiceDate(2010, 2, 13));
    assertEquals(2, serviceIdsForDate.size());
    assertTrue(serviceIdsForDate.contains(serviceIdA2));
    assertTrue(serviceIdsForDate.contains(serviceIdB1));
    serviceIdsForDate = data.getServiceIdsForDate(new ServiceDate(2010, 2, 2));
    assertEquals(0, serviceIdsForDate.size());
    // Localized service dates
    List<Date> dates = data.getDatesForLocalizedServiceId(new LocalizedServiceId(serviceIdA1, tzA));
    assertEquals(11, dates.size());
    assertEquals(DateSupport.date("2010-02-10 00:00 Pacific Standard Time"), dates.get(0));
    assertEquals(DateSupport.date("2010-02-24 00:00 Pacific Standard Time"), dates.get(10));
    dates = data.getDatesForLocalizedServiceId(new LocalizedServiceId(serviceIdA1, tzB));
    assertNull(dates);
    dates = data.getDatesForLocalizedServiceId(new LocalizedServiceId(serviceIdA2, tzA));
    assertEquals(15, dates.size());
    assertEquals(DateSupport.date("2010-02-10 00:00 Pacific Standard Time"), dates.get(0));
    assertEquals(DateSupport.date("2010-02-26 00:00 Pacific Standard Time"), dates.get(14));
    dates = data.getDatesForLocalizedServiceId(new LocalizedServiceId(serviceIdA2, tzB));
    assertEquals(15, dates.size());
    assertEquals(DateSupport.date("2010-02-10 00:00 Mountain Standard Time"), dates.get(0));
    assertEquals(DateSupport.date("2010-02-26 00:00 Mountain Standard Time"), dates.get(14));
    dates = data.getDatesForLocalizedServiceId(new LocalizedServiceId(serviceIdB1, tzA));
    assertNull(dates);
    dates = data.getDatesForLocalizedServiceId(new LocalizedServiceId(serviceIdB1, tzB));
    assertEquals(4, dates.size());
    assertEquals(DateSupport.date("2010-02-13 00:00 Mountain Standard Time"), dates.get(0));
    assertEquals(DateSupport.date("2010-02-21 00:00 Mountain Standard Time"), dates.get(3));
}
Also used : ServiceCalendarDate(org.onebusaway.gtfs.model.ServiceCalendarDate) Trip(org.onebusaway.gtfs.model.Trip) Agency(org.onebusaway.gtfs.model.Agency) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) Date(java.util.Date) ServiceCalendarDate(org.onebusaway.gtfs.model.ServiceCalendarDate) CalendarServiceData(org.onebusaway.gtfs.model.calendar.CalendarServiceData) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) TimeZone(java.util.TimeZone) LocalizedServiceId(org.onebusaway.gtfs.model.calendar.LocalizedServiceId) GtfsRelationalDaoImpl(org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl) ServiceCalendar(org.onebusaway.gtfs.model.ServiceCalendar) Test(org.junit.Test)

Example 24 with ServiceCalendar

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

the class ShiftNegativeStopTimesUpdateStrategyTest method test.

@Test
public void test() throws IOException {
    _gtfs.putAgencies(1);
    _gtfs.putStops(3);
    _gtfs.putRoutes(1);
    _gtfs.putCalendars(1, "start_date=20120903", "end_date=20121016", "mask=1111100");
    _gtfs.putTrips(1, "r0", "sid0");
    _gtfs.putLines("stop_times.txt", "trip_id,stop_id,stop_sequence,arrival_time,departure_time", "t0,s0,0,-01:00:00,-01:05:00", "t0,s1,1,-01:30:00,-01:30:00", "t0,s2,2,00:30:00,00:30:00");
    GtfsMutableRelationalDao dao = _gtfs.read();
    _strategy.run(new TransformContext(), dao);
    Trip trip = dao.getTripForId(_gtfs.id("t0"));
    assertEquals("sid0 -1", trip.getServiceId().getId());
    List<StopTime> stopTimes = dao.getStopTimesForTrip(trip);
    assertEquals(3, stopTimes.size());
    {
        StopTime stopTime = stopTimes.get(0);
        assertEquals(stopTime.getArrivalTime(), StopTimeFieldMappingFactory.getStringAsSeconds("23:00:00"));
        assertEquals(stopTime.getDepartureTime(), StopTimeFieldMappingFactory.getStringAsSeconds("23:05:00"));
    }
    {
        StopTime stopTime = stopTimes.get(1);
        assertEquals(stopTime.getArrivalTime(), StopTimeFieldMappingFactory.getStringAsSeconds("23:30:00"));
        assertEquals(stopTime.getDepartureTime(), StopTimeFieldMappingFactory.getStringAsSeconds("23:30:00"));
    }
    {
        StopTime stopTime = stopTimes.get(2);
        assertEquals(stopTime.getArrivalTime(), StopTimeFieldMappingFactory.getStringAsSeconds("24:30:00"));
        assertEquals(stopTime.getDepartureTime(), StopTimeFieldMappingFactory.getStringAsSeconds("24:30:00"));
    }
    ServiceCalendar c = dao.getCalendarForServiceId(trip.getServiceId());
    assertEquals(c.getStartDate(), new ServiceDate(2012, 9, 2));
    assertEquals(c.getEndDate(), new ServiceDate(2012, 10, 15));
    assertEquals(1, c.getMonday());
    assertEquals(1, c.getTuesday());
    assertEquals(1, c.getWednesday());
    assertEquals(1, c.getThursday());
    assertEquals(0, c.getFriday());
    assertEquals(0, c.getSaturday());
    assertEquals(1, c.getSunday());
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) Trip(org.onebusaway.gtfs.model.Trip) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) TransformContext(org.onebusaway.gtfs_transformer.services.TransformContext) StopTime(org.onebusaway.gtfs.model.StopTime) ServiceCalendar(org.onebusaway.gtfs.model.ServiceCalendar) Test(org.junit.Test)

Example 25 with ServiceCalendar

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

the class CalendarExtensionStrategyTest method testCalendarExtension.

@Test
public void testCalendarExtension() throws IOException {
    _gtfs.putCalendars(2, "start_date=20120630,20120731", "end_date=20121224,20121231", "mask=1111100,0000011");
    GtfsMutableRelationalDao dao = _gtfs.read();
    ServiceDate endDate = new ServiceDate(2013, 12, 31);
    _strategy.setEndDate(endDate);
    _strategy.run(_context, dao);
    {
        ServiceCalendar calendar = dao.getCalendarForServiceId(new AgencyAndId("a0", "sid0"));
        assertEquals(endDate, calendar.getEndDate());
    }
    {
        ServiceCalendar calendar = dao.getCalendarForServiceId(new AgencyAndId("a0", "sid1"));
        assertEquals(endDate, calendar.getEndDate());
    }
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ServiceCalendar(org.onebusaway.gtfs.model.ServiceCalendar) Test(org.junit.Test)

Aggregations

ServiceCalendar (org.onebusaway.gtfs.model.ServiceCalendar)28 Test (org.junit.Test)18 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)18 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)17 ServiceCalendarDate (org.onebusaway.gtfs.model.ServiceCalendarDate)17 Trip (org.onebusaway.gtfs.model.Trip)13 Agency (org.onebusaway.gtfs.model.Agency)8 Route (org.onebusaway.gtfs.model.Route)6 Stop (org.onebusaway.gtfs.model.Stop)6 GtfsRelationalDao (org.onebusaway.gtfs.services.GtfsRelationalDao)6 ShapePoint (org.onebusaway.gtfs.model.ShapePoint)5 StopTime (org.onebusaway.gtfs.model.StopTime)5 GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)5 FareAttribute (org.onebusaway.gtfs.model.FareAttribute)4 GtfsRelationalDaoImpl (org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl)3 FareRule (org.onebusaway.gtfs.model.FareRule)3 Frequency (org.onebusaway.gtfs.model.Frequency)3 CalendarService (org.onebusaway.gtfs.services.calendar.CalendarService)3 ArrayList (java.util.ArrayList)2 Calendar (java.util.Calendar)2