Search in sources :

Example 1 with DataValidationRouteCounts

use of org.onebusaway.admin.model.ui.DataValidationRouteCounts in project onebusaway-application-modules by camsys.

the class CompareBundlesAction method compareModes.

private DataValidationMode compareModes(DataValidationMode currentMode, DataValidationMode selectedMode) {
    DataValidationMode diffMode = new DataValidationMode();
    diffMode.setModeName(currentMode.getModeName());
    diffMode.setRoutes(new TreeSet<DataValidationRouteCounts>());
    for (DataValidationRouteCounts currentRoute : currentMode.getRoutes()) {
        // Check if this route exists in selectedMode
        DataValidationRouteCounts diffRoute = null;
        String routeNum = currentRoute.getRouteNum();
        String routeName = currentRoute.getRouteName();
        for (DataValidationRouteCounts selectedRoute : selectedMode.getRoutes()) {
            if (routeNum.equals(selectedRoute.getRouteNum())) {
                selectedMode.getRoutes().remove(selectedRoute);
                if (routeName.equals(selectedRoute.getRouteName())) {
                    diffRoute = compareRoutes(currentRoute, selectedRoute);
                } else {
                    // Route name changed, but not route number.
                    currentRoute.setSrcCode("1");
                    selectedRoute.setSrcCode("2");
                    diffMode.getRoutes().add(currentRoute);
                    diffRoute = selectedRoute;
                }
                break;
            }
        }
        if (diffRoute == null) {
            currentRoute.setSrcCode("1");
            diffRoute = currentRoute;
        }
        if (diffRoute.getHeadsignCounts().size() > 0) {
            diffMode.getRoutes().add(diffRoute);
        }
    }
    if (selectedMode.getRoutes().size() > 0) {
        for (DataValidationRouteCounts selectedRoute : selectedMode.getRoutes()) {
            selectedRoute.setSrcCode("2");
            diffMode.getRoutes().add(selectedRoute);
        }
    }
    return diffMode;
}
Also used : DataValidationRouteCounts(org.onebusaway.admin.model.ui.DataValidationRouteCounts) DataValidationMode(org.onebusaway.admin.model.ui.DataValidationMode)

Example 2 with DataValidationRouteCounts

use of org.onebusaway.admin.model.ui.DataValidationRouteCounts in project onebusaway-application-modules by camsys.

the class CompareBundlesAction method compareRoutes.

private DataValidationRouteCounts compareRoutes(DataValidationRouteCounts currentRoute, DataValidationRouteCounts selectedRoute) {
    DataValidationRouteCounts diffRoute = new DataValidationRouteCounts();
    diffRoute.setRouteName(currentRoute.getRouteName());
    diffRoute.setRouteNum(currentRoute.getRouteNum());
    diffRoute.setHeadsignCounts(new TreeSet<DataValidationHeadsignCts>());
    for (DataValidationHeadsignCts currentHeadsign : currentRoute.getHeadsignCounts()) {
        // Check if this headsign exists in selectedMode
        DataValidationHeadsignCts diffHeadsign = null;
        String headsignName = currentHeadsign.getHeadsign();
        for (DataValidationHeadsignCts selectedHeadsign : selectedRoute.getHeadsignCounts()) {
            if (headsignName.equals(selectedHeadsign.getHeadsign())) {
                selectedRoute.getHeadsignCounts().remove(selectedHeadsign);
                diffHeadsign = compareHeadsigns(currentHeadsign, selectedHeadsign);
                break;
            }
        }
        if (diffHeadsign == null) {
            currentHeadsign.setSrcCode("1");
            diffHeadsign = currentHeadsign;
        }
        if (diffHeadsign.getDirCounts().size() > 0) {
            diffRoute.getHeadsignCounts().add(diffHeadsign);
        }
    }
    if (selectedRoute.getHeadsignCounts().size() > 0) {
        for (DataValidationHeadsignCts selectedHeadsign : selectedRoute.getHeadsignCounts()) {
            selectedHeadsign.setSrcCode("2");
            diffRoute.getHeadsignCounts().add(selectedHeadsign);
        }
    }
    return diffRoute;
}
Also used : DataValidationRouteCounts(org.onebusaway.admin.model.ui.DataValidationRouteCounts) DataValidationHeadsignCts(org.onebusaway.admin.model.ui.DataValidationHeadsignCts)

Example 3 with DataValidationRouteCounts

use of org.onebusaway.admin.model.ui.DataValidationRouteCounts in project onebusaway-application-modules by camsys.

the class CompareBundlesAction method buildModes.

private List<DataValidationMode> buildModes(int buildId) {
    List<DataValidationMode> modes = new ArrayList<>();
    // Check service ids
    List<ArchivedCalendar> calendars = _gtfsArchiveService.getAllCalendarsByBundleId(buildId);
    // Get dates for checking trips for days of the week
    LocalDate startDate = getStartDate(calendars);
    LocalDate firstMon = getFirstDay(DateTimeConstants.MONDAY, startDate);
    LocalDate firstTues = getFirstDay(DateTimeConstants.TUESDAY, startDate);
    LocalDate firstWed = getFirstDay(DateTimeConstants.WEDNESDAY, startDate);
    LocalDate firstThur = getFirstDay(DateTimeConstants.THURSDAY, startDate);
    LocalDate firstFri = getFirstDay(DateTimeConstants.FRIDAY, startDate);
    LocalDate firstSat = getFirstDay(DateTimeConstants.SATURDAY, startDate);
    LocalDate firstSun = getFirstDay(DateTimeConstants.SUNDAY, startDate);
    // Get the service ids for weekdays, Saturdays, and Sundays
    Set<AgencyAndId> weekdaySvcIds = new HashSet<>();
    Set<AgencyAndId> saturdaySvcIds = new HashSet<>();
    Set<AgencyAndId> sundaySvcIds = new HashSet<>();
    for (ArchivedCalendar calendar : calendars) {
        Date svcStartDate = calendar.getStartDate().getAsDate();
        LocalDate jodaStartDate = new LocalDate(svcStartDate);
        Date svcEndDate = calendar.getEndDate().getAsDate();
        LocalDate jodaEndDate = new LocalDate(svcEndDate);
        if (calendar.getMonday() == 1 && !firstMon.isBefore(jodaStartDate) && !firstMon.isAfter(jodaEndDate)) {
            weekdaySvcIds.add(calendar.getServiceId());
        }
        if (calendar.getTuesday() == 1 && !firstTues.isBefore(jodaStartDate) && !firstTues.isAfter(jodaEndDate)) {
            weekdaySvcIds.add(calendar.getServiceId());
        }
        if (calendar.getWednesday() == 1 && !firstWed.isBefore(jodaStartDate) && !firstWed.isAfter(jodaEndDate)) {
            weekdaySvcIds.add(calendar.getServiceId());
        }
        if (calendar.getThursday() == 1 && !firstThur.isBefore(jodaStartDate) && !firstThur.isAfter(jodaEndDate)) {
            weekdaySvcIds.add(calendar.getServiceId());
        }
        if (calendar.getFriday() == 1 && !firstFri.isBefore(jodaStartDate) && !firstFri.isAfter(jodaEndDate)) {
            weekdaySvcIds.add(calendar.getServiceId());
        }
        if (calendar.getSaturday() == 1 && !firstSat.isBefore(jodaStartDate) && !firstSat.isAfter(jodaEndDate)) {
            saturdaySvcIds.add(calendar.getServiceId());
        }
        if (calendar.getSunday() == 1 && !firstSun.isBefore(jodaStartDate) && !firstSun.isAfter(jodaEndDate)) {
            sundaySvcIds.add(calendar.getServiceId());
        }
    }
    // Get all the routes for this build id
    List<ArchivedRoute> allRoutes = _gtfsArchiveService.getAllRoutesByBundleId(buildId);
    // Get all the trips for this build id
    List<ArchivedTrip> allTrips = _gtfsArchiveService.getAllTripsByBundleId(buildId);
    // Get trip stop countt for all the trips in this build
    // This call returns a list of arrays of Objects of the form
    // [String trip_agencyId, String trip_id, int stop_count]
    List allStopCts = _gtfsArchiveService.getTripStopCounts(buildId);
    Map<AgencyAndId, Integer> tripStopCounts = new HashMap<>();
    for (int i = 0; i < allStopCts.size(); ++i) {
        Object[] tripStopCt = (Object[]) allStopCts.get(i);
        String tripAgencyId = (String) tripStopCt[0];
        String tripId = (String) tripStopCt[1];
        int stopCt = (int) tripStopCt[2];
        AgencyAndId agencyAndId = new AgencyAndId(tripAgencyId, tripId);
        tripStopCounts.put(agencyAndId, stopCt);
    }
    Map<String, List<String>> reportModes = getReportModes();
    Collection<ArchivedAgency> agencies = _gtfsArchiveService.getAllAgenciesByBundleId(buildId);
    for (String currentMode : reportModes.keySet()) {
        DataValidationMode newMode = new DataValidationMode();
        newMode.setModeName(currentMode);
        SortedSet<DataValidationRouteCounts> newModeRouteCts = new TreeSet<DataValidationRouteCounts>();
        // Note: currentRoutes entries might be just an agency id
        List<String> agenciesOrRoutes = reportModes.get(currentMode);
        for (String agencyOrRoute : agenciesOrRoutes) {
            // or a route, i.e. <agencyId>_<routeId>
            // List<ArchivedRoute> routes = null;
            // check if agency or route id
            int idx = agencyOrRoute.indexOf("_");
            int routeCt = allRoutes.size();
            int currentRouteCt = 0;
            for (ArchivedRoute route : allRoutes) {
                if (!route.getAgencyId().equals(agencyOrRoute)) {
                    continue;
                }
                currentRouteCt++;
                int[] wkdayTrips = null;
                int[] satTrips = null;
                int[] sunTrips = null;
                Map<String, TripTotals> tripMap = new HashMap<>();
                String routeId = route.getAgencyId() + ID_SEPARATOR + route.getId();
                DataValidationRouteCounts newRouteCts = new DataValidationRouteCounts();
                String routeName = route.getDesc();
                if (routeName == null || routeName.equals("null") || routeName.isEmpty()) {
                    routeName = route.getLongName();
                }
                if (routeName == null || routeName.equals("null")) {
                    routeName = "";
                }
                newRouteCts.setRouteName(routeName);
                String routeNum = route.getShortName();
                if (routeNum == null || routeNum.equals("null") || routeNum.isEmpty()) {
                    routeNum = route.getId();
                }
                if (routeNum == null || routeNum.equals("null")) {
                    routeNum = "";
                }
                newRouteCts.setRouteNum(routeNum);
                // Build DataValidationHeadsignCts
                SortedSet<DataValidationHeadsignCts> headsignCounts = new TreeSet<>();
                int stopCtIdx = 0;
                for (ArchivedTrip trip : allTrips) {
                    if (trip.getRoute_agencyId().compareTo(route.getAgencyId()) > 0 || (trip.getRoute_agencyId().equals(route.getAgencyId()) && trip.getRoute_id().compareTo(route.getId()) > 0)) {
                        break;
                    }
                    if (!trip.getRoute_agencyId().equals(route.getAgencyId()) || !trip.getRoute_id().equals(route.getId())) {
                        continue;
                    }
                    AgencyAndId tripAgencyAndId = new AgencyAndId(trip.getAgencyId(), trip.getId());
                    int stopCt = tripStopCounts.get(tripAgencyAndId) != null ? tripStopCounts.get(tripAgencyAndId) : 0;
                    if (stopCt > MAX_STOP_CT) {
                        stopCt = MAX_STOP_CT;
                    }
                    TripTotals tripTotals = null;
                    String tripHeadsign = trip.getTripHeadsign();
                    tripHeadsign = tripHeadsign == null ? "" : tripHeadsign;
                    if (tripMap.containsKey(tripHeadsign)) {
                        tripTotals = tripMap.get(tripHeadsign);
                    } else {
                        tripTotals = new TripTotals();
                        tripMap.put(tripHeadsign, tripTotals);
                    }
                    /*
             * TODO: if stopCt exceeds array sizes, resize arrays
             */
                    if (trip.getDirectionId() == null || trip.getDirectionId().equals("0")) {
                        wkdayTrips = tripTotals.wkdayTrips_0;
                        satTrips = tripTotals.satTrips_0;
                        sunTrips = tripTotals.sunTrips_0;
                    } else {
                        wkdayTrips = tripTotals.wkdayTrips_1;
                        satTrips = tripTotals.satTrips_1;
                        sunTrips = tripTotals.sunTrips_1;
                    }
                    AgencyAndId tripSvcId = new AgencyAndId(trip.getServiceId_agencyId(), trip.getServiceId_id());
                    if (weekdaySvcIds.contains(tripSvcId)) {
                        ++wkdayTrips[stopCt];
                    } else if (saturdaySvcIds.contains(tripSvcId)) {
                        ++satTrips[stopCt];
                    } else if (sundaySvcIds.contains(tripSvcId)) {
                        ++sunTrips[stopCt];
                    }
                    tripMap.put(tripHeadsign, tripTotals);
                }
                // End of trips loop.  Stop counts by direction for this route have been set.
                for (String headSign : tripMap.keySet()) {
                    TripTotals tripTotals = tripMap.get(headSign);
                    DataValidationHeadsignCts newHeadsignCt = new DataValidationHeadsignCts();
                    newHeadsignCt.setHeadsign(headSign);
                    SortedSet<DataValidationDirectionCts> newDirCountSet = new TreeSet<DataValidationDirectionCts>();
                    DataValidationDirectionCts newDirCt_0 = new DataValidationDirectionCts();
                    newDirCt_0.setDirection("0");
                    SortedSet<DataValidationStopCt> stopCounts_0 = new TreeSet<>();
                    for (int i = 0; i < MAX_STOP_CT; ++i) {
                        if (tripTotals.wkdayTrips_0[i] > 0 || tripTotals.satTrips_0[i] > 0 || tripTotals.sunTrips_0[i] > 0) {
                            DataValidationStopCt stopCt_0 = new DataValidationStopCt();
                            stopCt_0.setStopCt(i);
                            stopCt_0.setTripCts(new int[] { tripTotals.wkdayTrips_0[i], tripTotals.satTrips_0[i], tripTotals.sunTrips_0[i] });
                            stopCounts_0.add(stopCt_0);
                        }
                    }
                    if (stopCounts_0.size() > 0) {
                        newDirCt_0.setStopCounts(stopCounts_0);
                        newDirCountSet.add(newDirCt_0);
                    }
                    DataValidationDirectionCts newDirCt_1 = new DataValidationDirectionCts();
                    newDirCt_1.setDirection("1");
                    SortedSet<DataValidationStopCt> stopCounts_1 = new TreeSet<>();
                    for (int i = 0; i < MAX_STOP_CT; ++i) {
                        if (tripTotals.wkdayTrips_1[i] > 0 || tripTotals.satTrips_1[i] > 0 || tripTotals.sunTrips_1[i] > 0) {
                            DataValidationStopCt stopCt_1 = new DataValidationStopCt();
                            stopCt_1.setStopCt(i);
                            stopCt_1.setTripCts(new int[] { tripTotals.wkdayTrips_1[i], tripTotals.satTrips_1[i], tripTotals.sunTrips_1[i] });
                            stopCounts_1.add(stopCt_1);
                        }
                        if (stopCounts_1.size() > 0) {
                            newDirCt_1.setStopCounts(stopCounts_1);
                            newDirCountSet.add(newDirCt_1);
                        }
                    }
                    if (newDirCountSet.size() > 0) {
                        newHeadsignCt.setDirCounts(newDirCountSet);
                        headsignCounts.add(newHeadsignCt);
                    }
                }
                if (headsignCounts.size() > 0) {
                    newRouteCts.setHeadsignCounts(headsignCounts);
                    newModeRouteCts.add(newRouteCts);
                }
            }
        }
        if (newModeRouteCts.size() > 0) {
            newMode.setRoutes(newModeRouteCts);
            modes.add(newMode);
        }
    }
    return modes;
}
Also used : DataValidationRouteCounts(org.onebusaway.admin.model.ui.DataValidationRouteCounts) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LocalDate(org.joda.time.LocalDate) ArchivedRoute(org.onebusaway.admin.service.bundle.task.model.ArchivedRoute) ArchivedCalendar(org.onebusaway.admin.service.bundle.task.model.ArchivedCalendar) DataValidationMode(org.onebusaway.admin.model.ui.DataValidationMode) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) List(java.util.List) ArchivedAgency(org.onebusaway.admin.service.bundle.task.model.ArchivedAgency) HashSet(java.util.HashSet) ArchivedTrip(org.onebusaway.admin.service.bundle.task.model.ArchivedTrip) DataValidationDirectionCts(org.onebusaway.admin.model.ui.DataValidationDirectionCts) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) DataValidationHeadsignCts(org.onebusaway.admin.model.ui.DataValidationHeadsignCts) DataValidationStopCt(org.onebusaway.admin.model.ui.DataValidationStopCt)

Example 4 with DataValidationRouteCounts

use of org.onebusaway.admin.model.ui.DataValidationRouteCounts in project onebusaway-application-modules by camsys.

the class FixedRouteParserServiceImpl method parseRecord.

/**
 * Parses a csv record representing one line of a FixedRouteDataValidation
 * report.  If the line is part of the mode currently being processed, it
 * is added to that DataValidationMode object. If it is for a new mode, the
 * current mode is added to the parsedModes list and the record being
 * parsed becomes the new current mode.
 *
 * @param record the record to be parsed
 * @param currentMode the DataValidationMode currently being built
 * @param parsedModes the list of modes already created.
 * @return the DataValidationMode currently being built
 */
private DataValidationMode parseRecord(CSVRecord record, DataValidationMode currentMode, List<DataValidationMode> parsedModes) {
    if (record.size() < 8 || record.get(4).isEmpty() || !record.get(4).matches("^\\d+$")) {
        // Stop count should be numeric
        return currentMode;
    }
    // Create the StopCt for this line (every line should have a stop count)
    DataValidationStopCt currentStopCt = new DataValidationStopCt();
    currentStopCt.setStopCt(Integer.parseInt(record.get(4)));
    int[] stopCtTrips = { 0, 0, 0 };
    for (int i = 0; i < 3; i++) {
        try {
            int tripCt = Integer.parseInt(record.get(5 + i));
            stopCtTrips[i] = tripCt;
        } catch (NumberFormatException ex) {
        // Do nothing, leave array value at 0.
        }
    }
    currentStopCt.setTripCts(stopCtTrips);
    String modeName = record.get(0);
    String routeName = record.get(1);
    String headsign = record.get(2);
    String dirName = record.get(3);
    // If routeName is prefixed with the route number, extract the route number
    String routeNum = "";
    if (routeName.length() > 0) {
        int idx = routeName.substring(0, Math.min(5, routeName.length())).indexOf("-");
        if (idx > 0) {
            routeNum = routeName.substring(0, idx).trim();
            routeName = routeName.substring(idx + 1);
        }
    }
    if (modeName.length() > 0) {
        // new mode
        if (routeName.isEmpty()) {
            // this shouldn't happen.  Any line with a mode
            return currentMode;
        // name should also have a route name.
        }
        if (currentMode != null) {
            parsedModes.add(currentMode);
        }
        currentMode = new DataValidationMode(modeName, routeNum, routeName, headsign, dirName);
        currentRoute = currentMode.getRoutes().first();
        currentHeadsign = currentRoute.getHeadsignCounts().first();
        currentDirection = currentHeadsign.getDirCounts().first();
        SortedSet<DataValidationStopCt> stopCountsList = currentDirection.getStopCounts();
        stopCountsList.add(currentStopCt);
    } else if (routeName.length() > 0) {
        // New route for current mode
        currentRoute = new DataValidationRouteCounts(routeNum, routeName, headsign, dirName);
        currentMode.getRoutes().add(currentRoute);
        currentHeadsign = currentRoute.getHeadsignCounts().first();
        currentDirection = currentHeadsign.getDirCounts().first();
        SortedSet<DataValidationStopCt> stopCountsList = currentDirection.getStopCounts();
        stopCountsList.add(currentStopCt);
    } else if (headsign.length() > 0) {
        currentHeadsign = new DataValidationHeadsignCts(headsign, dirName);
        currentRoute.getHeadsignCounts().add(currentHeadsign);
        currentDirection = currentHeadsign.getDirCounts().first();
        SortedSet<DataValidationStopCt> stopCountsList = currentDirection.getStopCounts();
        stopCountsList.add(currentStopCt);
    } else if (dirName.length() > 0) {
        currentDirection = new DataValidationDirectionCts(dirName);
        currentHeadsign.getDirCounts().add(currentDirection);
        SortedSet<DataValidationStopCt> stopCountsList = currentDirection.getStopCounts();
        stopCountsList.add(currentStopCt);
    } else if (dirName.isEmpty()) {
        SortedSet<DataValidationStopCt> stopCountsList = currentDirection.getStopCounts();
        stopCountsList.add(currentStopCt);
    }
    return currentMode;
}
Also used : DataValidationRouteCounts(org.onebusaway.admin.model.ui.DataValidationRouteCounts) DataValidationStopCt(org.onebusaway.admin.model.ui.DataValidationStopCt) DataValidationMode(org.onebusaway.admin.model.ui.DataValidationMode) DataValidationDirectionCts(org.onebusaway.admin.model.ui.DataValidationDirectionCts) SortedSet(java.util.SortedSet) DataValidationHeadsignCts(org.onebusaway.admin.model.ui.DataValidationHeadsignCts)

Aggregations

DataValidationRouteCounts (org.onebusaway.admin.model.ui.DataValidationRouteCounts)4 DataValidationHeadsignCts (org.onebusaway.admin.model.ui.DataValidationHeadsignCts)3 DataValidationMode (org.onebusaway.admin.model.ui.DataValidationMode)3 DataValidationDirectionCts (org.onebusaway.admin.model.ui.DataValidationDirectionCts)2 DataValidationStopCt (org.onebusaway.admin.model.ui.DataValidationStopCt)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 SortedSet (java.util.SortedSet)1 TreeSet (java.util.TreeSet)1 LocalDate (org.joda.time.LocalDate)1 ArchivedAgency (org.onebusaway.admin.service.bundle.task.model.ArchivedAgency)1 ArchivedCalendar (org.onebusaway.admin.service.bundle.task.model.ArchivedCalendar)1 ArchivedRoute (org.onebusaway.admin.service.bundle.task.model.ArchivedRoute)1 ArchivedTrip (org.onebusaway.admin.service.bundle.task.model.ArchivedTrip)1 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)1