use of org.onebusaway.gtfs.model.calendar.ServiceDate 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.model.calendar.ServiceDate 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.model.calendar.ServiceDate in project onebusaway-gtfs-modules by OneBusAway.
the class ThirtyDayCalendarExtensionStrategy method ensureActiveCalendar.
private void ensureActiveCalendar(int daysFromNow, Map<Date, List<ServiceCalendar>> serviceIdsByDate, GtfsMutableRelationalDao dao) {
Date date = removeTime(new Date(System.currentTimeMillis() + daysFromNow * milisPerDay));
List<ServiceCalendar> activeServiceIds = getLastActiveCalendar(daysFromNow, serviceIdsByDate);
// update service ids in dao
for (ServiceCalendar serviceId : activeServiceIds) {
ServiceCalendar serviceCalendar = serviceId;
serviceCalendar.setEndDate(new ServiceDate(date));
dao.saveOrUpdateEntity(serviceCalendar);
dao.flush();
}
}
use of org.onebusaway.gtfs.model.calendar.ServiceDate in project onebusaway-gtfs-modules by OneBusAway.
the class VerifyBusService method constructDate.
private Date constructDate(ServiceDate date) {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, date.getYear());
calendar.set(Calendar.MONTH, date.getMonth() - 1);
calendar.set(Calendar.DATE, date.getDay());
Date date1 = calendar.getTime();
date1 = removeTime(date1);
return date1;
}
use of org.onebusaway.gtfs.model.calendar.ServiceDate in project onebusaway-gtfs-modules by OneBusAway.
the class VerifyBusService method run.
@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
GtfsMutableRelationalDao reference = (GtfsMutableRelationalDao) context.getReferenceReader().getEntityStore();
ExternalServices es = new ExternalServicesBridgeFactory().getExternalServices();
String feed = CloudContextService.getLikelyFeedName(dao);
CalendarService refCalendarService = CalendarServiceDataFactoryImpl.createService(reference);
AgencyAndId refAgencyAndId = reference.getAllTrips().iterator().next().getId();
int curSerRoute = 0;
int alarmingRoutes = 0;
Date today = removeTime(new Date());
// list of all routes in ATIS
Set<String> ATISrouteIds = new HashSet<>();
// check for route specific current service
for (Route route : dao.getAllRoutes()) {
ATISrouteIds.add(route.getId().getId());
_log.info("Adding route: {}", route.getId().getId());
curSerRoute = 0;
triploop: for (Trip trip1 : dao.getTripsForRoute(route)) {
for (ServiceCalendarDate calDate : dao.getCalendarDatesForServiceId(trip1.getServiceId())) {
Date date = constructDate(calDate.getDate());
if (calDate.getExceptionType() == 1 && date.equals(today)) {
_log.info("ATIS has current service for route: {}", route.getId().getId());
curSerRoute++;
break triploop;
}
}
}
if (curSerRoute == 0) {
_log.error("No current service for {}", route.getId().getId());
// if there is no current service, check that it should have service
// there are certain routes that don't run on the weekend or won't have service in reference
ServiceDate sToday = createServiceDate(today);
Route refRoute = reference.getRouteForId(new AgencyAndId(refAgencyAndId.getAgencyId(), route.getId().getId()));
reftriploop: for (Trip refTrip : reference.getTripsForRoute(refRoute)) {
Set<ServiceDate> activeDates = refCalendarService.getServiceDatesForServiceId(refTrip.getServiceId());
if (activeDates.contains(sToday)) {
_log.info("Reference has service for this bus route today but ATIS does not: {}", route.getId());
// This would be the site to add to a bulk metric, missingBus:
alarmingRoutes++;
}
}
}
}
es.publishMetric(CloudContextService.getNamespace(), "RoutesMissingTripsFromAtisButInRefToday", "feed", feed, alarmingRoutes);
es.publishMetric(CloudContextService.getNamespace(), "RoutesContainingTripsToday", "feed", feed, curSerRoute);
}
Aggregations