Search in sources :

Example 1 with ExternalServices

use of org.onebusaway.cloud.api.ExternalServices in project onebusaway-gtfs-modules by OneBusAway.

the class CountAndTestBus method run.

@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
    GtfsMutableRelationalDao reference = (GtfsMutableRelationalDao) context.getReferenceReader().getEntityStore();
    CalendarService refCalendarService = CalendarServiceDataFactoryImpl.createService(reference);
    String agency = dao.getAllTrips().iterator().next().getId().getAgencyId();
    String name = dao.getAllAgencies().iterator().next().getName();
    HashMap<String, Route> referenceRoutes = new HashMap<>();
    for (Route route : reference.getAllRoutes()) {
        referenceRoutes.put(route.getId().getId(), route);
    }
    HashMap<String, Trip> referenceTrips = new HashMap<>();
    for (Trip trip : reference.getAllTrips()) {
        referenceTrips.put(trip.getId().getId(), trip);
    }
    HashMap<String, Stop> referenceStops = new HashMap<>();
    for (Stop stop : reference.getAllStops()) {
        referenceStops.put(stop.getId().getId(), stop);
    }
    int matches = 0;
    for (Route route : dao.getAllRoutes()) {
        if (referenceRoutes.containsKey(route.getId().getId())) {
            matches++;
        } else {
            _log.info("ATIS route {} doesn't have match in reference", route.getId().getId());
        }
    }
    _log.info("ATIS Routes: {}, References: {}, ATIS match to reference: {}", dao.getAllRoutes().size(), reference.getAllRoutes().size(), matches);
    int countSt = 0;
    int countCd = 0;
    int countNoSt = 0;
    int countNoCd = 0;
    int curSerTrips = 0;
    int countNoHs = 0;
    int atisTripsThisWeek = 0;
    int refTripsThisWeek = 0;
    int matchingTripsThisWeek = 0;
    AgencyAndId serviceAgencyAndId = new AgencyAndId();
    matches = 0;
    List<String> matchingIds = new ArrayList<String>();
    List<String> matchingIdsThisWeek = new ArrayList<String>();
    // _log.info("ATIS trips that don't have a match in reference: ");
    for (Trip trip : dao.getAllTrips()) {
        if (trip.getId().getId() != null) {
            if (referenceTrips.containsKey(trip.getId().getId())) {
                matches++;
                matchingIds.add(trip.getId().getId());
            } else {
            // _log.info(trip.getId().getId());
            }
            if (tripIsThisWeek(dao.getCalendarDatesForServiceId(trip.getServiceId()))) {
                atisTripsThisWeek++;
                if (referenceTrips.containsKey(trip.getId().getId())) {
                    // ATIS trips this week that match a reference trip (reference trip may not be this week, check this further down)
                    matchingIdsThisWeek.add(trip.getId().getId());
                }
            }
        }
        if (dao.getStopTimesForTrip(trip).size() == 0) {
            countNoSt++;
        } else {
            countSt++;
        }
        serviceAgencyAndId = trip.getServiceId();
        if (dao.getCalendarDatesForServiceId(serviceAgencyAndId).size() == 0) {
            countNoCd++;
        } else {
            countCd++;
        }
        // check for current service
        for (ServiceCalendarDate calDate : dao.getCalendarDatesForServiceId(trip.getServiceId())) {
            Date date = constructDate(calDate.getDate());
            Date today = removeTime(new Date());
            if (calDate.getExceptionType() == 1 && date.equals(today)) {
                curSerTrips++;
                break;
            }
        }
        if (trip.getTripHeadsign() == null) {
            countNoHs++;
        }
        // compare ATIS and Reference trips *this week*
        if (trip.getId().getId() != null) {
            if (referenceTrips.containsKey(trip.getId().getId())) {
                matches++;
                matchingIds.add(trip.getId().getId());
            } else {
            // _log.info(trip.getId().getId());
            }
        }
    }
    // MOTP-1060 Number of trips in reference GTFS that don't appear in mta_trip_id in ATIS
    // for each reference trip
    int noMatch = 0;
    int noMatchNoSdon = 0;
    int noMatchNoSdonNoH9 = 0;
    int refTripsWithSdon = 0;
    int refTripsWoutSdonWithh9 = 0;
    int refTripsThisWeekWithSdon = 0;
    int refTripsThisWeekWoutSdonWithA9 = 0;
    int refTripsThisWeekWoutSdonWithE9 = 0;
    int refTripsThisWeekWoutSdonWithD9 = 0;
    int refTripsThisWeekWoutSdonWithB9 = 0;
    int refTripsThisWeekWoutSdonWithH9 = 0;
    int checkMatchesThisWeek = 0;
    int doesntMatchThisWeek = 0;
    int leftOverNoMatchThisWeek = 0;
    List<String> refTripsMissingATIS = new ArrayList<String>();
    for (Trip refTrip : reference.getAllTrips()) {
        // count number of reference trips this week
        Set<ServiceDate> activeDates = refCalendarService.getServiceDatesForServiceId(refTrip.getServiceId());
        if (tripIsThisWeek(activeDates)) {
            refTripsThisWeek++;
            if (!matchingIdsThisWeek.contains(refTrip.getId().getId())) {
                doesntMatchThisWeek++;
                if (refTrip.getId().getId().contains("SDon")) {
                    refTripsThisWeekWithSdon++;
                } else if (refTrip.getId().getId().contains("A9")) {
                    refTripsThisWeekWoutSdonWithA9++;
                } else if (refTrip.getId().getId().contains("B9")) {
                    refTripsThisWeekWoutSdonWithB9++;
                } else if (refTrip.getId().getId().contains("D9")) {
                    refTripsThisWeekWoutSdonWithD9++;
                } else if (refTrip.getId().getId().contains("E9")) {
                    refTripsThisWeekWoutSdonWithE9++;
                } else if (refTrip.getId().getId().contains("H9")) {
                    refTripsThisWeekWoutSdonWithH9++;
                } else {
                    leftOverNoMatchThisWeek++;
                }
            } else {
                matchingTripsThisWeek++;
            // the number of ATIS trips this week that match with a reference trip
            // that is also this week
            }
        }
        if (!matchingIds.contains(refTrip.getId().getId())) {
            // _log.info(refTrip.getId().getId());
            refTripsMissingATIS.add(refTrip.getId().getId());
            noMatch++;
            if (!refTrip.getId().getId().contains("SDon")) {
                noMatchNoSdon++;
                if (!refTrip.getId().getId().contains("H9")) {
                    // _log.info(refTrip.getId().getId());
                    noMatchNoSdonNoH9++;
                } else // No Sdon, has H9
                {
                    refTripsWoutSdonWithh9++;
                }
            } else // has SDon
            {
                refTripsWithSdon++;
            }
        }
    }
    _log.info("ATIS Trips: {}, Reference: {}, match: {}, In ref NotInATIS: {}, In ref NotInATIS Sdon: {}, In ref NotInATIS not Sdon is H9: {}, Current Service: {}", dao.getAllTrips().size(), reference.getAllTrips().size(), matches, noMatch, refTripsWithSdon, refTripsWoutSdonWithh9, curSerTrips);
    _log.info("ATIS Trips this week {}, Reference trips this week {}, ATIS Trips this week that are also Reference Trips this week {}", atisTripsThisWeek, refTripsThisWeek, matchingTripsThisWeek);
    _log.info("Matches this week {}", matchingTripsThisWeek);
    _log.info("This week matches: {}. This week doesn't match {}, in ref NotInATIS Sdon: {}, In ref NotInATIS not Sdon is A9: {}, B9: {} E9: {}, H9: {}, Leftover: {}", matchingTripsThisWeek, doesntMatchThisWeek, refTripsThisWeekWithSdon, refTripsThisWeekWoutSdonWithA9, refTripsThisWeekWoutSdonWithB9, refTripsThisWeekWoutSdonWithE9, refTripsThisWeekWoutSdonWithH9, leftOverNoMatchThisWeek);
    _log.info("Stops: {}, Stop times {}, Trips w/ st: {}, Trips w/out st: {}", dao.getAllStops().size(), dao.getAllStopTimes().size(), countSt, countNoSt);
    _log.info("Calendar dates: {}, Trips w/cd {}, Trips w/out cd: {}", dao.getAllCalendarDates().size(), countCd, countNoCd);
    _log.info("Total trips w/out headsign: {}", countNoHs);
    matches = 0;
    for (Stop stop : dao.getAllStops()) {
        if (referenceStops.containsKey(stop.getId().getId())) {
            matches++;
        }
    }
    _log.info("ATIS Stops: {}, Reference: {}, ATIS match to reference: {}", dao.getAllStops().size(), reference.getAllStops().size(), matches);
    ExternalServices es = new ExternalServicesBridgeFactory().getExternalServices();
    String feed = CloudContextService.getLikelyFeedName(dao);
    es.publishMetric(CloudContextService.getNamespace(), "ATISBusTripsThisWeek", "feed", feed, atisTripsThisWeek);
    es.publishMetric(CloudContextService.getNamespace(), "refBusTripsThisWeek", "feed", feed, refTripsThisWeek);
    es.publishMetric(CloudContextService.getNamespace(), "matchingBusTripsThisWeek", "feed", feed, matchingTripsThisWeek);
    es.publishMetric(CloudContextService.getNamespace(), "SdonBusTripsThisWeek", "feed", feed, refTripsThisWeekWithSdon);
    es.publishMetric(CloudContextService.getNamespace(), "A9BusTripsThisWeek", "feed", feed, refTripsThisWeekWoutSdonWithA9);
    es.publishMetric(CloudContextService.getNamespace(), "B9BusTripsThisWeek", "feed", feed, refTripsThisWeekWoutSdonWithB9);
    es.publishMetric(CloudContextService.getNamespace(), "D9BusTripsThisWeek", "feed", feed, refTripsThisWeekWoutSdonWithD9);
    es.publishMetric(CloudContextService.getNamespace(), "E9BusTripsThisWeek", "feed", feed, refTripsThisWeekWoutSdonWithE9);
    es.publishMetric(CloudContextService.getNamespace(), "H9BusTripsWitThisWeek", "feed", feed, refTripsThisWeekWoutSdonWithH9);
    es.publishMetric(CloudContextService.getNamespace(), "OtherTripsWithoutMatchThisWeek", "feed", feed, leftOverNoMatchThisWeek);
    if (curSerTrips < 1) {
        throw new IllegalStateException("There is no current service!!");
    }
    es.publishMetric(CloudContextService.getNamespace(), "BusTripsInServiceToday", "feed", feed, curSerTrips);
    if (countNoHs > 0) {
        _log.error("There are trips with no headsign");
    }
    es.publishMetric(CloudContextService.getNamespace(), "TripsWithoutHeadsigns", "feed", feed, countNoHs);
    HashSet<String> ids = new HashSet<String>();
    for (Stop stop : dao.getAllStops()) {
        // check for duplicate stop ids.
        if (ids.contains(stop.getId().getId())) {
            if (ids.contains(stop.getId().getId())) {
                _log.error("Duplicate stop ids! Agency {} stop id {}", agency, stop.getId().getId());
                es.publishMultiDimensionalMetric(CloudContextService.getLikelyFeedName(dao), "DuplicateStopIds", new String[] { "feed", "stopId" }, new String[] { feed, stop.getId().toString() }, 1);
            }
        } else {
            ids.add(stop.getId().getId());
        }
    }
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) ExternalServicesBridgeFactory(org.onebusaway.cloud.api.ExternalServicesBridgeFactory) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) CalendarService(org.onebusaway.gtfs.services.calendar.CalendarService) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) ExternalServices(org.onebusaway.cloud.api.ExternalServices)

Example 2 with ExternalServices

use of org.onebusaway.cloud.api.ExternalServices in project onebusaway-gtfs-modules by OneBusAway.

the class MTAEntrancesStrategy method run.

@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
    ExternalServices es = new ExternalServicesBridgeFactory().getExternalServices();
    Collection<FeedInfo> feedInfos = dao.getAllFeedInfos();
    String feed = null;
    if (feedInfos.size() > 0)
        feed = feedInfos.iterator().next().getPublisherName();
    File entrancesFile = new File(entrancesCsv);
    if (!entrancesFile.exists()) {
        es.publishMultiDimensionalMetric(getNamespace(), "MissingControlFiles", new String[] { "feed", "controlFileName" }, new String[] { feed, entrancesCsv }, 1);
        throw new IllegalStateException("Entrances file does not exist: " + entrancesFile.getName());
    }
    if (elevatorsCsv != null) {
        File elevatorsFile = new File(elevatorsCsv);
        if (!elevatorsFile.exists()) {
            es.publishMultiDimensionalMetric(getNamespace(), "MissingControlFiles", new String[] { "feed", "controlFileName" }, new String[] { feed, elevatorsCsv }, 1);
            throw new IllegalStateException("Elevators file does not exist: " + elevatorsFile.getName());
        }
    }
    agencyId = dao.getAllAgencies().iterator().next().getId();
    newStops = new HashSet<>();
    newPathways = new HashSet<>();
    pathwayUtil = new PathwayUtil(agencyId, newPathways);
    for (Pathway pathway : dao.getAllPathways()) {
        stopIdsWithPathways.add(pathway.getFromStop().getId());
        stopIdsWithPathways.add(pathway.getToStop().getId());
    }
    Map<String, StopGroup> stopGroups = new HashMap<>();
    // For every stop that's not a station, add an entrance which is not wheelchair accessible, and a pathway.
    for (Stop stop : dao.getAllStops()) {
        if (stopsHaveParents) {
            // Put stop into a stop-group with parent, uptown, downtown
            String gid = stop.getLocationType() == LOCATION_TYPE_STOP ? stop.getParentStation() : stop.getId().getId();
            if (gid == null) {
                gid = stop.getId().getId();
                // don't fret about this one, it's a shuttle stop
                if (stop.getName().contains("SHUTTLE BUS STOP"))
                    continue;
                _log.warn("stop {} didn't have a parent set--using own stop ID.", stop.getName());
                continue;
            }
            StopGroup group = stopGroups.get(gid);
            if (group == null) {
                group = new StopGroup();
                stopGroups.put(gid, group);
            }
            if (stop.getLocationType() == LOCATION_TYPE_STATION) {
                group.parent = stop;
            } else if (stop.getId().getId().endsWith("S")) {
                group.downtown = stop;
            } else if (stop.getId().getId().endsWith("N")) {
                group.uptown = stop;
            } else {
                // it's a pathway, ignore
                if (stop.getLocationType() >= 2)
                    continue;
                // don't fret about this one, it's a shuttle stop
                if (stop.getName().contains("SHUTTLE BUS STOP"))
                    continue;
                _log.error("unexpected stop not of parent type but of {} for stop {}: {}", stop.getLocationType(), stop.getId(), stop.getName());
                continue;
            }
        } else {
            StopGroup group = new StopGroup();
            group.parent = stop;
            String gid = stop.getId().getId();
            stopGroups.put(gid, group);
        }
    }
    readEntranceData(stopGroups);
    if (elevatorsCsv != null) {
        readElevatorData(stopGroups, getComplexList(dao));
    }
    for (Stop s : newStops) {
        dao.saveEntity(s);
    }
    for (Pathway pathway : newPathways) {
        dao.saveEntity(pathway);
    }
}
Also used : ExternalServicesBridgeFactory(org.onebusaway.cloud.api.ExternalServicesBridgeFactory) HashMap(java.util.HashMap) Stop(org.onebusaway.gtfs.model.Stop) Pathway(org.onebusaway.gtfs.model.Pathway) FeedInfo(org.onebusaway.gtfs.model.FeedInfo) PathwayUtil(org.onebusaway.gtfs_transformer.util.PathwayUtil) ExternalServices(org.onebusaway.cloud.api.ExternalServices) File(java.io.File)

Example 3 with ExternalServices

use of org.onebusaway.cloud.api.ExternalServices in project onebusaway-gtfs-modules by OneBusAway.

the class AnomalyCheckFutureTripCounts method run.

@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
    Collection<Date> datesToIgnore;
    SetListener datesToIgnoreListener = new SetListener();
    datesToIgnoreListener = (SetListener) readCsvFrom(datesToIgnoreListener, datesToIgnoreUrl, datesToIgnoreFile);
    datesToIgnore = datesToIgnoreListener.returnContents();
    Collection<Date> holidays;
    SetListener holidaysListener = new SetListener();
    holidaysListener = (SetListener) readCsvFrom(holidaysListener, holidaysUrl, holidaysFile);
    holidays = holidaysListener.returnContents();
    Map<String, Double> dayAvgTripsMap = new HashMap<String, Double>();
    MapListener mapListener = new MapListener();
    mapListener = (MapListener) readCsvFrom(mapListener, dayAvgTripMapUrl, dayAvgTripMapFile);
    dayAvgTripsMap = mapListener.returnContents();
    SimpleDateFormat dayOfWeekFormat = new SimpleDateFormat("EEEE");
    for (Date date : holidays) {
        _log.info("holiday: " + date.toString() + " on a " + dayOfWeekFormat.format(date));
    }
    for (Date date : datesToIgnore) {
        _log.info("ignore: " + date.toString());
    }
    for (String key : dayAvgTripsMap.keySet()) {
        _log.info("key: " + key + " value: " + dayAvgTripsMap.get(key));
    }
    ExternalServices es = new ExternalServicesBridgeFactory().getExternalServices();
    String[] days = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Holiday" };
    Map<Date, Integer> dateTripMap = getDateTripMap(dao);
    int dayCounter = 0;
    Map<String, ArrayList<Double>> dayAvgTripsMapUpdate = new HashMap<String, ArrayList<Double>>();
    for (String day : days) {
        dayAvgTripsMapUpdate.put(day, new ArrayList<Double>());
    }
    Date dateDay = removeTime(addDays(new Date(), dayCounter));
    while (dateTripMap.get(dateDay) != null) {
        int tripCount = dateTripMap.get(dateDay);
        if (dayAvgTripMapFile == null && dayAvgTripMapUrl == null) {
            _log.info("On {} there are {} trips", dateDay.toString(), tripCount);
        } else {
            if ((tripCount < dayAvgTripsMap.get(dayOfWeekFormat.format(dateDay)) * (1 + percentageMatch / 100)) && (tripCount > dayAvgTripsMap.get(dayOfWeekFormat.format(dateDay)) * (1 - percentageMatch / 100)) && !holidays.contains(dateDay)) {
                _log.info(dateDay + " has " + tripCount + " trips, and that's within reasonable expections");
                dayAvgTripsMapUpdate.get(dayOfWeekFormat.format(dateDay)).add((double) tripCount);
            } else if (holidays.contains(dateDay) & (tripCount < dayAvgTripsMap.get("Holiday") * (1 + percentageMatch / 100) && (tripCount > dayAvgTripsMap.get("Holiday") * (1 - percentageMatch / 100)))) {
                _log.info(dateDay + " has " + tripCount + " trips, is a holiday, and that's within reasonable expections");
                dayAvgTripsMapUpdate.get("Holiday").add((double) tripCount);
            } else if (datesToIgnore.contains(dateDay)) {
                _log.info(dateDay + " has " + tripCount + " trips, and we are ignoring this possible anomoly");
            } else {
                _log.info(dateDay + " has " + tripCount + " trips, this may indicate a problem.");
                if (!silentMode) {
                    es.publishMessage(CloudContextService.getTopic(), dateDay.toString() + " has " + tripCount + " trips, this may indicate a problem.");
                }
            }
        }
        dayCounter++;
        dateDay = removeTime(addDays(new Date(), dayCounter));
    }
    String out = "";
    for (String stringDay : days) {
        double tripsUpcoming;
        try {
            tripsUpcoming = dayAvgTripsMapUpdate.get(stringDay).stream().mapToDouble(a -> a).average().getAsDouble();
        } catch (NoSuchElementException exception) {
            tripsUpcoming = dayAvgTripsMap.get(stringDay);
        }
        double currentAvg = dayAvgTripsMap.get(stringDay);
        int aprox_hours_per_month = 28 * 24;
        double suggestedAvg = currentAvg + ((tripsUpcoming - currentAvg) / (aprox_hours_per_month));
        out += stringDay + "," + suggestedAvg + "\n";
    }
    _log.info(out);
    try {
        Files.deleteIfExists(Paths.get(dayAvgTripMapFile));
        Files.write(Paths.get(dayAvgTripMapFile), out.getBytes());
    } catch (IOException io) {
        _log.error(io.getMessage());
    }
}
Also used : ExternalServices(org.onebusaway.cloud.api.ExternalServices) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) java.util(java.util) CsvField(org.onebusaway.csv_entities.schema.annotations.CsvField) ServiceCalendar(org.onebusaway.gtfs.model.ServiceCalendar) Logger(org.slf4j.Logger) Files(java.nio.file.Files) URL(java.net.URL) LoggerFactory(org.slf4j.LoggerFactory) GtfsTransformStrategy(org.onebusaway.gtfs_transformer.services.GtfsTransformStrategy) SimpleDateFormat(java.text.SimpleDateFormat) Trip(org.onebusaway.gtfs.model.Trip) CSVLibrary(org.onebusaway.csv_entities.CSVLibrary) CSVListener(org.onebusaway.csv_entities.CSVListener) TransformContext(org.onebusaway.gtfs_transformer.services.TransformContext) java.io(java.io) Paths(java.nio.file.Paths) ExternalServicesBridgeFactory(org.onebusaway.cloud.api.ExternalServicesBridgeFactory) ServiceCalendarDate(org.onebusaway.gtfs.model.ServiceCalendarDate) CloudContextService(org.onebusaway.gtfs_transformer.services.CloudContextService) ExternalServicesBridgeFactory(org.onebusaway.cloud.api.ExternalServicesBridgeFactory) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) ServiceCalendarDate(org.onebusaway.gtfs.model.ServiceCalendarDate) ExternalServices(org.onebusaway.cloud.api.ExternalServices) SimpleDateFormat(java.text.SimpleDateFormat)

Example 4 with ExternalServices

use of org.onebusaway.cloud.api.ExternalServices in project onebusaway-gtfs-modules by OneBusAway.

the class VerifyFutureRouteService method run.

@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
    Collection<String> problemRoutes = new HashSet<String>();
    ProblemRouteListener listener = new ProblemRouteListener();
    try {
        if (problemRoutesUrl != null) {
            URL url = new URL(problemRoutesUrl);
            try (InputStream is = url.openStream()) {
                new CSVLibrary().parse(is, listener);
            }
        }
        if (problemRoutesFile != null) {
            InputStream is = new BufferedInputStream(new FileInputStream(problemRoutesFile));
            new CSVLibrary().parse(is, listener);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    problemRoutes = listener.returnRouteIds();
    GtfsMutableRelationalDao reference = (GtfsMutableRelationalDao) context.getReferenceReader().getEntityStore();
    CalendarService refCalendarService = CalendarServiceDataFactoryImpl.createService(reference);
    String feed = CloudContextService.getLikelyFeedName(dao);
    ExternalServices es = new ExternalServicesBridgeFactory().getExternalServices();
    String agencyName = dao.getAllAgencies().iterator().next().getName();
    int[] tripsToday;
    int[] tripsTomorrow;
    int[] tripsNextDay;
    int[] tripsDayAfterNext;
    Date today = removeTime(new Date());
    Date tomorrow = removeTime(addDays(new Date(), 1));
    Date nextDay = removeTime(addDays(new Date(), 2));
    Date dayAfterNext = removeTime(addDays(new Date(), 3));
    tripsToday = hasRouteServiceForDate(dao, reference, refCalendarService, today, problemRoutes);
    tripsTomorrow = hasRouteServiceForDate(dao, reference, refCalendarService, tomorrow, problemRoutes);
    tripsNextDay = hasRouteServiceForDate(dao, reference, refCalendarService, nextDay, problemRoutes);
    tripsDayAfterNext = hasRouteServiceForDate(dao, reference, refCalendarService, dayAfterNext, problemRoutes);
    _log.info("Feed for metrics: {}, agency name: {}", feed, agencyName);
    _log.info("Active routes {}: {}, {}: {}, {}: {}, {}: {}", today, tripsToday[ACTIVE_ROUTES], tomorrow, tripsTomorrow[ACTIVE_ROUTES], nextDay, tripsNextDay[ACTIVE_ROUTES], dayAfterNext, tripsDayAfterNext[ACTIVE_ROUTES]);
    es.publishMetric(CloudContextService.getNamespace(), "RoutesContainingTripsToday", "feed", feed, tripsToday[ACTIVE_ROUTES]);
    es.publishMetric(CloudContextService.getNamespace(), "RoutesNoTripsInAtisButInRefToday", "feed", feed, tripsToday[ALARMING_ROUTES]);
    es.publishMetric(CloudContextService.getNamespace(), "RoutesContainingTripsTomorrow", "feed", feed, tripsTomorrow[ACTIVE_ROUTES]);
    es.publishMetric(CloudContextService.getNamespace(), "RoutesNoTripsInAtisButInRefTomorrow", "feed", feed, tripsTomorrow[ALARMING_ROUTES]);
    es.publishMetric(CloudContextService.getNamespace(), "RoutesContainingTripsIn2Days", "feed", feed, tripsNextDay[ACTIVE_ROUTES]);
    es.publishMetric(CloudContextService.getNamespace(), "RoutesNoTripsInAtisButInRefIn2Days", "feed", feed, tripsNextDay[ALARMING_ROUTES]);
    es.publishMetric(CloudContextService.getNamespace(), "RoutesContainingTripsIn3Days", "feed", feed, tripsDayAfterNext[ACTIVE_ROUTES]);
    es.publishMetric(CloudContextService.getNamespace(), "RoutesNoTripsInAtisButInRefIn3Days", "feed", feed, tripsDayAfterNext[ALARMING_ROUTES]);
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) ExternalServicesBridgeFactory(org.onebusaway.cloud.api.ExternalServicesBridgeFactory) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) URL(java.net.URL) FileInputStream(java.io.FileInputStream) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) CalendarService(org.onebusaway.gtfs.services.calendar.CalendarService) BufferedInputStream(java.io.BufferedInputStream) ExternalServices(org.onebusaway.cloud.api.ExternalServices) CSVLibrary(org.onebusaway.csv_entities.CSVLibrary)

Example 5 with ExternalServices

use of org.onebusaway.cloud.api.ExternalServices in project onebusaway-gtfs-modules by OneBusAway.

the class VerifyReferenceService method run.

@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
    GtfsMutableRelationalDao reference = (GtfsMutableRelationalDao) context.getReferenceReader().getEntityStore();
    CalendarService refCalendarService = CalendarServiceDataFactoryImpl.createService(reference);
    String feed = CloudContextService.getLikelyFeedName(reference);
    ExternalServices es = new ExternalServicesBridgeFactory().getExternalServices();
    Collection<String> problemRoutes;
    ProblemRouteListener listener = new ProblemRouteListener();
    try {
        if (problemRoutesFile != null) {
            InputStream is = new BufferedInputStream(new FileInputStream(problemRoutesFile));
            new CSVLibrary().parse(is, listener);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    problemRoutes = listener.returnRouteIds();
    for (String route : problemRoutes) {
        _log.info("ProblemRoutes includes: " + route);
    }
    int[] tripsToday;
    int[] tripsTomorrow;
    int[] tripsNextDay;
    int[] tripsDayAfterNext;
    Date today = removeTime(new Date());
    Date tomorrow = removeTime(addDays(new Date(), 1));
    Date nextDay = removeTime(addDays(new Date(), 2));
    Date dayAfterNext = removeTime(addDays(new Date(), 3));
    tripsToday = hasRouteServiceForDate(dao, reference, refCalendarService, today, problemRoutes);
    tripsTomorrow = hasRouteServiceForDate(dao, reference, refCalendarService, tomorrow, problemRoutes);
    tripsNextDay = hasRouteServiceForDate(dao, reference, refCalendarService, nextDay, problemRoutes);
    tripsDayAfterNext = hasRouteServiceForDate(dao, reference, refCalendarService, dayAfterNext, problemRoutes);
    _log.info("Feed for metrics: {}", feed);
    _log.info("Active routes {}: {}, {}: {}, {}: {}, {}: {}", today, tripsToday, tomorrow, tripsTomorrow, nextDay, tripsNextDay, dayAfterNext, tripsDayAfterNext);
    es.publishMetric(CloudContextService.getNamespace(), "RefRoutesContainingTripsToday", "feed", feed, tripsTomorrow[ACTIVE_ROUTES]);
    es.publishMetric(CloudContextService.getNamespace(), "RefRoutesMissingTripsFromRefButInAtisToday", "feed", feed, tripsTomorrow[ALARMING_ROUTES]);
    es.publishMetric(CloudContextService.getNamespace(), "RefRoutesContainingTripsTomorrow", "feed", feed, tripsTomorrow[ACTIVE_ROUTES]);
    es.publishMetric(CloudContextService.getNamespace(), "RefRoutesMissingTripsFromRefButInAtisTomorrow", "feed", feed, tripsTomorrow[ALARMING_ROUTES]);
    es.publishMetric(CloudContextService.getNamespace(), "RefRoutesContainingTripsIn2Days", "feed", feed, tripsNextDay[ACTIVE_ROUTES]);
    es.publishMetric(CloudContextService.getNamespace(), "RefRoutesMissingTripsFromRefButInAtisIn2Days", "feed", feed, tripsNextDay[ALARMING_ROUTES]);
    es.publishMetric(CloudContextService.getNamespace(), "RefRoutesContainingTripsIn3Days", "feed", feed, tripsDayAfterNext[ACTIVE_ROUTES]);
    es.publishMetric(CloudContextService.getNamespace(), "RefRoutesMissingTripsFromRefButInAtisIn3Days", "feed", feed, tripsDayAfterNext[ALARMING_ROUTES]);
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) ExternalServicesBridgeFactory(org.onebusaway.cloud.api.ExternalServicesBridgeFactory) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileInputStream(java.io.FileInputStream) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) CalendarService(org.onebusaway.gtfs.services.calendar.CalendarService) BufferedInputStream(java.io.BufferedInputStream) ExternalServices(org.onebusaway.cloud.api.ExternalServices) CSVLibrary(org.onebusaway.csv_entities.CSVLibrary)

Aggregations

ExternalServices (org.onebusaway.cloud.api.ExternalServices)17 ExternalServicesBridgeFactory (org.onebusaway.cloud.api.ExternalServicesBridgeFactory)17 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)10 GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)8 HashMap (java.util.HashMap)5 File (java.io.File)4 ArrayList (java.util.ArrayList)4 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)4 Stop (org.onebusaway.gtfs.model.Stop)4 CalendarService (org.onebusaway.gtfs.services.calendar.CalendarService)4 Date (java.util.Date)3 HashSet (java.util.HashSet)3 CSVLibrary (org.onebusaway.csv_entities.CSVLibrary)3 Trip (org.onebusaway.gtfs.model.Trip)3 BufferedInputStream (java.io.BufferedInputStream)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 URL (java.net.URL)2 SimpleDateFormat (java.text.SimpleDateFormat)2 ServiceCalendarDate (org.onebusaway.gtfs.model.ServiceCalendarDate)2