use of org.onebusaway.cloud.api.ExternalServicesBridgeFactory 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);
}
use of org.onebusaway.cloud.api.ExternalServicesBridgeFactory in project onebusaway-gtfs-modules by OneBusAway.
the class UpdateStopTimesForTime method run.
@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
RemoveEntityLibrary removeEntityLibrary = new RemoveEntityLibrary();
StopTime currentStop = new StopTime();
int negativeTimes = 0;
ArrayList<Trip> tripsToRemove = new ArrayList<Trip>();
// For now, for any trip with stop_times that go back in time, remove the trip.
for (Trip trip : dao.getAllTrips()) {
StopTime previousStop = new StopTime();
previousStop.setArrivalTime(0);
for (StopTime stopTime : dao.getStopTimesForTrip(trip)) {
currentStop = stopTime;
// handle the cases where there is no stop time (stop time is negative)
if (currentStop.getArrivalTime() < 0) {
_log.error("Ignoring negative stop time for {}", currentStop.toString());
} else {
// handle the case of decreasing stop time
if (previousStop.getArrivalTime() > currentStop.getArrivalTime()) {
_log.info("Time travel! previous arrival time {} this stop {}", previousStop.displayArrival(), currentStop.toString());
tripsToRemove.add(trip);
negativeTimes++;
break;
}
previousStop = currentStop;
}
}
}
_log.info("Decreasing times: {}, TripsToRemove: {}", negativeTimes, tripsToRemove.size());
ExternalServices es = new ExternalServicesBridgeFactory().getExternalServices();
String feed = CloudContextService.getLikelyFeedName(dao);
es.publishMetric(CloudContextService.getNamespace(), "TripsWithDecreasingStopTimes", "feed", feed, tripsToRemove.size());
StringBuffer illegalTripList = new StringBuffer();
for (Trip trip : tripsToRemove) {
illegalTripList.append(trip.getId().toString()).append(" ");
removeEntityLibrary.removeTrip(dao, trip);
}
}
Aggregations