Search in sources :

Example 1 with DataValidationMode

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

the class CompareBundlesAction method findFixedRouteDiffs.

/**
 * Find the differences between two Lists of modes
 *
 * @param currentModes
 * @param selectedModes
 * @return
 */
private List<DataValidationMode> findFixedRouteDiffs(List<DataValidationMode> currentModes, List<DataValidationMode> selectedModes) {
    List<DataValidationMode> fixedRouteDiffs = new ArrayList<>();
    if (currentModes != null && selectedModes == null) {
        return currentModes;
    }
    if (currentModes == null && selectedModes != null) {
        return selectedModes;
    }
    if (currentModes == null && selectedModes == null) {
        return fixedRouteDiffs;
    }
    for (DataValidationMode currentMode : currentModes) {
        // Check if this mode exists in selectedModes
        DataValidationMode diffMode = null;
        if (currentMode == null)
            continue;
        String modeName = currentMode.getModeName();
        for (DataValidationMode selectedMode : selectedModes) {
            if (modeName.equals(selectedMode.getModeName())) {
                selectedModes.remove(selectedMode);
                diffMode = compareModes(currentMode, selectedMode);
                break;
            }
        }
        if (diffMode == null && currentMode != null) {
            currentMode.setSrcCode("1");
            diffMode = currentMode;
        }
        if (diffMode.getRoutes().size() > 0) {
            fixedRouteDiffs.add(diffMode);
        }
    }
    if (selectedModes.size() > 0) {
        for (DataValidationMode selectedMode : selectedModes) {
            selectedMode.setSrcCode("2");
            fixedRouteDiffs.add(selectedMode);
        }
    }
    return fixedRouteDiffs;
}
Also used : DataValidationMode(org.onebusaway.admin.model.ui.DataValidationMode) ArrayList(java.util.ArrayList)

Example 2 with DataValidationMode

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

the class CompareBundlesAction method compareFixedRouteValidations.

private List<DataValidationMode> compareFixedRouteValidations(String datasetName, String buildName, String datasetName2, String buildName2) {
    List<DataValidationMode> currentModes;
    List<DataValidationMode> selectedModes;
    long startTime = (new Date()).getTime();
    long buildModeTime1 = 0L;
    long buildModeTime2 = 0L;
    if (!useArchived) {
        String currentValidationReportPath = fileService.getBucketName() + File.separator + datasetName + "/builds/" + buildName + "/outputs/fixed_route_validation.csv";
        File currentValidationReportFile = new File(currentValidationReportPath);
        String selectedValidationReportPath = fileService.getBucketName() + File.separator + datasetName2 + "/builds/" + buildName2 + "/outputs/fixed_route_validation.csv";
        File selectedValidationReportFile = new File(selectedValidationReportPath);
        // parse input files
        currentModes = _fixedRouteParserService.parseFixedRouteReportFile(currentValidationReportFile);
        selectedModes = _fixedRouteParserService.parseFixedRouteReportFile(selectedValidationReportFile);
    } else {
        long buildModeStartTime = (new Date()).getTime();
        currentModes = buildModes(dataset_1_build_id);
        buildModeTime1 = (new Date()).getTime() - buildModeStartTime;
        buildModeStartTime = (new Date()).getTime();
        selectedModes = buildModes(dataset_2_build_id);
        buildModeTime2 = (new Date()).getTime() - buildModeStartTime;
    }
    // compare and get diffs
    List<DataValidationMode> fixedRouteDiffs = findFixedRouteDiffs(currentModes, selectedModes);
    long totalTime = (new Date()).getTime() - startTime;
    String buildTimeMsg1 = ("Elapsed time for building mode for first dataset was " + buildModeTime1 / (60 * 1000) + " min ") + (buildModeTime1 / 1000) % 60 + " sec";
    String buildTimeMsg2 = ("Elapsed time for building mode for second dataset was " + buildModeTime2 / (60 * 1000) + " min ") + (buildModeTime2 / 1000) % 60 + " sec";
    String totalTimeMsg = ("Total elapsed time for Fixed Route Comparison report was " + totalTime / (60 * 1000) + " min ") + (totalTime / 1000) % 60 + " sec";
    _log.info(buildTimeMsg1);
    _log.info(buildTimeMsg2);
    _log.info(totalTimeMsg);
    return fixedRouteDiffs;
}
Also used : DataValidationMode(org.onebusaway.admin.model.ui.DataValidationMode) File(java.io.File) Date(java.util.Date) LocalDate(org.joda.time.LocalDate)

Example 3 with DataValidationMode

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

the class FixedRouteParserServiceImpl method parseFixedRouteReportFile.

/**
 * Parses a FixedRouteDataValidation report file into a List of
 * DataValidationMode objects.
 *
 * @param fixedRouteReportFile name of the file containing the report
 *                             in csv format.
 * @return a List of DataValidationMode objects containing the report data.
 */
@Override
public List<DataValidationMode> parseFixedRouteReportFile(File fixedRouteReportFile) {
    List<DataValidationMode> parsedModes = new ArrayList<>();
    if (fixedRouteReportFile != null && fixedRouteReportFile.exists()) {
        DataValidationMode currentMode = null;
        try {
            Reader in = new FileReader(fixedRouteReportFile);
            int i = 0;
            for (CSVRecord record : CSVFormat.DEFAULT.parse(in)) {
                if (i == 0) {
                    i++;
                    // Skip the first record, which is just the column headers
                    continue;
                }
                // When the record being parsed is for a new mode, the parseRecord
                // method will add the previous mode to the parsedModes List.
                currentMode = parseRecord(record, currentMode, parsedModes);
                i++;
            }
        } catch (FileNotFoundException e) {
            _log.info("Exception parsing csv file " + fixedRouteReportFile, e);
            e.printStackTrace();
        } catch (IOException e) {
            _log.info("Exception parsing csv file " + fixedRouteReportFile, e);
            e.printStackTrace();
        }
        // Add in the last mode processed.
        parsedModes.add(currentMode);
    }
    return parsedModes;
}
Also used : DataValidationMode(org.onebusaway.admin.model.ui.DataValidationMode) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) Reader(java.io.Reader) FileReader(java.io.FileReader) FileReader(java.io.FileReader) CSVRecord(org.apache.commons.csv.CSVRecord) IOException(java.io.IOException)

Example 4 with DataValidationMode

use of org.onebusaway.admin.model.ui.DataValidationMode 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 5 with DataValidationMode

use of org.onebusaway.admin.model.ui.DataValidationMode 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)

Aggregations

DataValidationMode (org.onebusaway.admin.model.ui.DataValidationMode)6 ArrayList (java.util.ArrayList)3 DataValidationRouteCounts (org.onebusaway.admin.model.ui.DataValidationRouteCounts)3 Date (java.util.Date)2 LocalDate (org.joda.time.LocalDate)2 DataValidationDirectionCts (org.onebusaway.admin.model.ui.DataValidationDirectionCts)2 DataValidationHeadsignCts (org.onebusaway.admin.model.ui.DataValidationHeadsignCts)2 DataValidationStopCt (org.onebusaway.admin.model.ui.DataValidationStopCt)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 Reader (java.io.Reader)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 CSVRecord (org.apache.commons.csv.CSVRecord)1 ArchivedAgency (org.onebusaway.admin.service.bundle.task.model.ArchivedAgency)1