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;
}
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;
}
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;
}
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);
}
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);
}
}
Aggregations