Search in sources :

Example 6 with CalendarServiceData

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

the class CalendarServiceDataFactoryImpl method createData.

@Override
public CalendarServiceData createData() {
    CalendarServiceData data = new CalendarServiceData();
    setTimeZonesForAgencies(data);
    List<AgencyAndId> serviceIds = _dao.getAllServiceIds();
    int index = 0;
    for (AgencyAndId serviceId : serviceIds) {
        index++;
        _log.info("serviceId=" + serviceId + " (" + index + "/" + serviceIds.size() + ")");
        TimeZone serviceIdTimeZone = data.getTimeZoneForAgencyId(serviceId.getAgencyId());
        if (serviceIdTimeZone == null) {
            serviceIdTimeZone = TimeZone.getDefault();
        }
        Set<ServiceDate> activeDates = getServiceDatesForServiceId(serviceId, serviceIdTimeZone);
        List<ServiceDate> serviceDates = new ArrayList<ServiceDate>(activeDates);
        Collections.sort(serviceDates);
        data.putServiceDatesForServiceId(serviceId, serviceDates);
        List<String> tripAgencyIds = _dao.getTripAgencyIdsReferencingServiceId(serviceId);
        Set<TimeZone> timeZones = new HashSet<TimeZone>();
        for (String tripAgencyId : tripAgencyIds) {
            TimeZone timeZone = data.getTimeZoneForAgencyId(tripAgencyId);
            timeZones.add(timeZone);
        }
        for (TimeZone timeZone : timeZones) {
            List<Date> dates = new ArrayList<Date>(serviceDates.size());
            for (ServiceDate serviceDate : serviceDates) dates.add(serviceDate.getAsDate(timeZone));
            LocalizedServiceId id = new LocalizedServiceId(serviceId, timeZone);
            data.putDatesForLocalizedServiceId(id, dates);
        }
    }
    return data;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ArrayList(java.util.ArrayList) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) Date(java.util.Date) ServiceCalendarDate(org.onebusaway.gtfs.model.ServiceCalendarDate) CalendarServiceData(org.onebusaway.gtfs.model.calendar.CalendarServiceData) TimeZone(java.util.TimeZone) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) LocalizedServiceId(org.onebusaway.gtfs.model.calendar.LocalizedServiceId) HashSet(java.util.HashSet)

Example 7 with CalendarServiceData

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

the class CalendarServiceImpl method isLocalizedServiceIdActiveOnDate.

@Override
public boolean isLocalizedServiceIdActiveOnDate(LocalizedServiceId localizedServiceId, Date serviceDate) {
    // TODO : Make this more efficient?
    CalendarServiceData data = getData();
    List<Date> dates = data.getDatesForLocalizedServiceId(localizedServiceId);
    return Collections.binarySearch(dates, serviceDate) >= 0;
}
Also used : CalendarServiceData(org.onebusaway.gtfs.model.calendar.CalendarServiceData) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) Date(java.util.Date)

Example 8 with CalendarServiceData

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

the class CalendarServiceImpl method getServiceDatesForServiceId.

@Override
public Set<ServiceDate> getServiceDatesForServiceId(AgencyAndId serviceId) {
    Set<ServiceDate> dates = new HashSet<ServiceDate>();
    CalendarServiceData allData = getData();
    List<ServiceDate> serviceDates = allData.getServiceDatesForServiceId(serviceId);
    if (serviceDates != null)
        dates.addAll(serviceDates);
    return dates;
}
Also used : CalendarServiceData(org.onebusaway.gtfs.model.calendar.CalendarServiceData) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) HashSet(java.util.HashSet)

Example 9 with CalendarServiceData

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

the class CalendarServiceImplSyntheticTest method setup.

@Before
public void setup() {
    CalendarServiceData data = new CalendarServiceData();
    data.putTimeZoneForAgencyId("A", tz);
    putServiceDatesForServiceId(data, lsid1, Arrays.asList(d1, d2));
    putServiceDatesForServiceId(data, lsid2, Arrays.asList(d2, d3));
    putServiceDatesForServiceId(data, lsid3, Arrays.asList(d1, d3));
    intervals = new ServiceIdIntervals();
    intervals.addStopTime(lsid1, hourToSec(6), hourToSec(6));
    intervals.addStopTime(lsid1, hourToSec(25), hourToSec(25));
    intervals.addStopTime(lsid2, hourToSec(4), hourToSec(5));
    intervals.addStopTime(lsid2, hourToSec(30), hourToSec(30));
    intervals.addStopTime(lsid3, hourToSec(7), hourToSec(7));
    intervals.addStopTime(lsid3, hourToSec(23), hourToSec(23));
    service = new CalendarServiceImpl();
    service.setData(data);
}
Also used : CalendarServiceData(org.onebusaway.gtfs.model.calendar.CalendarServiceData) ServiceIdIntervals(org.onebusaway.gtfs.model.calendar.ServiceIdIntervals) Before(org.junit.Before)

Example 10 with CalendarServiceData

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

the class CalendarServiceImplTest method test.

@Test
public void test() throws IOException {
    GtfsRelationalDaoImpl dao = new GtfsRelationalDaoImpl();
    GtfsTestData.readGtfs(dao, GtfsTestData.getIslandGtfs(), "26");
    CalendarServiceDataFactoryImpl factory = new CalendarServiceDataFactoryImpl();
    factory.setGtfsDao(dao);
    CalendarServiceData data = factory.createData();
    CalendarServiceImpl service = new CalendarServiceImpl();
    service.setData(data);
    ServiceDate from = new ServiceDate(2008, 10, 27);
    ServiceDate to = new ServiceDate(2009, 9, 27);
    Set<ServiceDate> toExclude = new HashSet<ServiceDate>();
    toExclude.add(new ServiceDate(2009, 1, 1));
    // 23,1,1,1,1,1,0,0,20081027,20090927
    Set<ServiceDate> dates = service.getServiceDatesForServiceId(new AgencyAndId("26", "23"));
    assertEquals(239, dates.size());
    Date fromDate = from.getAsDate();
    Date toDate = to.getAsDate();
    Calendar c = Calendar.getInstance();
    c.setTime(fromDate);
    while (c.getTime().compareTo(toDate) <= 0) {
        ServiceDate day = new ServiceDate(c);
        int dow = c.get(Calendar.DAY_OF_WEEK);
        if (!(dow == Calendar.SATURDAY || dow == Calendar.SUNDAY || toExclude.contains(day))) {
            assertTrue(dates.contains(day));
        }
        c.add(Calendar.DAY_OF_YEAR, 1);
    }
}
Also used : CalendarServiceData(org.onebusaway.gtfs.model.calendar.CalendarServiceData) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Calendar(java.util.Calendar) GtfsRelationalDaoImpl(org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) Date(java.util.Date) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

CalendarServiceData (org.onebusaway.gtfs.model.calendar.CalendarServiceData)10 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)9 Date (java.util.Date)6 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)6 Test (org.junit.Test)5 GtfsRelationalDaoImpl (org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl)5 LocalizedServiceId (org.onebusaway.gtfs.model.calendar.LocalizedServiceId)4 HashSet (java.util.HashSet)3 TimeZone (java.util.TimeZone)3 Agency (org.onebusaway.gtfs.model.Agency)3 ServiceCalendarDate (org.onebusaway.gtfs.model.ServiceCalendarDate)3 ArrayList (java.util.ArrayList)2 ServiceCalendar (org.onebusaway.gtfs.model.ServiceCalendar)2 Calendar (java.util.Calendar)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Before (org.junit.Before)1 Trip (org.onebusaway.gtfs.model.Trip)1 ServiceIdIntervals (org.onebusaway.gtfs.model.calendar.ServiceIdIntervals)1