Search in sources :

Example 6 with DataValidationMode

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

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