use of org.onebusaway.gtfs.services.calendar.CalendarService in project onebusaway-gtfs-modules by OneBusAway.
the class CalendarSimplicationStrategy method run.
@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
RemoveEntityLibrary removeEntityLibrary = new RemoveEntityLibrary();
Map<Set<AgencyAndId>, AgencyAndId> serviceIdsToUpdatedServiceId = new HashMap<Set<AgencyAndId>, AgencyAndId>();
Map<AgencyAndId, List<AgencyAndId>> mergeToolIdMapping = computeMergeToolIdMapping(dao);
for (Route route : dao.getAllRoutes()) {
Map<TripKey, List<Trip>> tripsByKey = TripKey.groupTripsForRouteByKey(dao, route);
Map<Set<AgencyAndId>, List<TripKey>> tripKeysByServiceIds = _library.groupTripKeysByServiceIds(tripsByKey);
for (Set<AgencyAndId> serviceIds : tripKeysByServiceIds.keySet()) {
AgencyAndId updatedServiceId = createUpdatedServiceId(serviceIdsToUpdatedServiceId, serviceIds);
for (TripKey tripKey : tripKeysByServiceIds.get(serviceIds)) {
List<Trip> tripsForKey = tripsByKey.get(tripKey);
Trip tripToKeep = tripsForKey.get(0);
tripToKeep.setServiceId(updatedServiceId);
for (int i = 1; i < tripsForKey.size(); i++) {
Trip trip = tripsForKey.get(i);
removeEntityLibrary.removeTrip(dao, trip);
}
if (undoGoogleTransitDataFeedMergeTool) {
AgencyAndId updatedTripId = computeUpdatedTripIdForMergedTripsIfApplicable(mergeToolIdMapping, tripsForKey);
if (updatedTripId != null) {
tripToKeep.setId(updatedTripId);
}
}
}
}
}
CalendarService calendarService = CalendarServiceDataFactoryImpl.createService(dao);
List<Object> newEntities = new ArrayList<Object>();
for (Map.Entry<Set<AgencyAndId>, AgencyAndId> entry : serviceIdsToUpdatedServiceId.entrySet()) {
Set<ServiceDate> allServiceDates = getServiceDatesForServiceIds(calendarService, entry.getKey());
ServiceCalendarSummary summary = _library.getSummaryForServiceDates(allServiceDates);
_library.computeSimplifiedCalendar(entry.getValue(), summary, newEntities);
}
saveUpdatedCalendarEntities(dao, newEntities);
}
use of org.onebusaway.gtfs.services.calendar.CalendarService in project onebusaway-gtfs-modules by OneBusAway.
the class ShiftNegativeStopTimesUpdateStrategy method run.
@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
Set<ShiftedServiceCalendar> shiftedIds = new HashSet<ShiftedServiceCalendar>();
for (Trip trip : dao.getAllTrips()) {
List<StopTime> stopTimes = dao.getStopTimesForTrip(trip);
int minTime = getMinStopTime(stopTimes);
if (minTime >= 0) {
continue;
}
int dayShift = getDayShiftForNegativeStopTime(minTime);
shiftStopTimes(stopTimes, dayShift * SECONDS_IN_DAY);
ShiftedServiceCalendar shifted = new ShiftedServiceCalendar(trip.getServiceId(), -dayShift);
shiftedIds.add(shifted);
trip.setServiceId(shifted.getShiftedServiceId());
}
CalendarService calendarService = CalendarServiceDataFactoryImpl.createService(dao);
CalendarSimplicationLibrary library = new CalendarSimplicationLibrary();
for (ShiftedServiceCalendar shifted : shiftedIds) {
Set<ServiceDate> allServiceDates = calendarService.getServiceDatesForServiceId(shifted.getOriginalServiceId());
Set<ServiceDate> shiftedServiceDates = shiftServiceDates(allServiceDates, shifted.getDayOffset());
ServiceCalendarSummary summary = library.getSummaryForServiceDates(shiftedServiceDates);
List<Object> newEntities = new ArrayList<Object>();
library.computeSimplifiedCalendar(shifted.getShiftedServiceId(), summary, newEntities);
for (Object newEntity : newEntities) {
dao.saveEntity(newEntity);
}
}
UpdateLibrary.clearDaoCache(dao);
}
use of org.onebusaway.gtfs.services.calendar.CalendarService in project onebusaway-gtfs-modules by OneBusAway.
the class CalendarExtensionStrategyTest method testCalendarDateExtension.
@Test
public void testCalendarDateExtension() throws IOException {
_gtfs.putCalendarDates("sid0=20121217,20121218,20121219,20121220,20121221," + "20121224,20121225,20121226,20121227,20121228", "sid1=20121222,20121223,20121229,20121230");
GtfsMutableRelationalDao dao = _gtfs.read();
ServiceDate endDate = new ServiceDate(2013, 01, 06);
_strategy.setEndDate(endDate);
_strategy.run(_context, dao);
CalendarService service = CalendarServiceDataFactoryImpl.createService(dao);
{
Set<ServiceDate> dates = service.getServiceDatesForServiceId(new AgencyAndId("a0", "sid0"));
assertEquals(15, dates.size());
assertTrue(dates.contains(new ServiceDate(2012, 12, 31)));
assertTrue(dates.contains(new ServiceDate(2013, 01, 01)));
assertTrue(dates.contains(new ServiceDate(2013, 01, 02)));
assertTrue(dates.contains(new ServiceDate(2013, 01, 03)));
assertTrue(dates.contains(new ServiceDate(2013, 01, 04)));
}
{
Set<ServiceDate> dates = service.getServiceDatesForServiceId(new AgencyAndId("a0", "sid1"));
assertEquals(6, dates.size());
assertTrue(dates.contains(new ServiceDate(2013, 01, 05)));
assertTrue(dates.contains(new ServiceDate(2013, 01, 06)));
}
}
Aggregations