Search in sources :

Example 1 with BatchProcessor

use of edu.usf.cutr.gtfsrtvalidator.lib.batch.BatchProcessor in project gtfs-realtime-validator by CUTR-at-USF.

the class BatchTest method testBatchProcessing.

@Test
public void testBatchProcessing() throws IOException, NoSuchAlgorithmException {
    // Run batch validation on the bundled USF Bull Runner GTFS and GTFS-realtime data
    BatchProcessor.Builder builder = new BatchProcessor.Builder("src/test/resources/bullrunner-gtfs.zip", "src/test/resources/");
    BatchProcessor processor = builder.build();
    processor.processFeeds();
    // Read in validation results for GTFS-realtime bullrunner-vehicle-positions file
    ObjectMapper mapper = new ObjectMapper();
    ErrorListHelperModel[] allErrorLists = mapper.readValue(new File("src/test/resources/bullrunner-vehicle-positions" + BatchProcessor.RESULTS_FILE_EXTENSION), ErrorListHelperModel[].class);
    // We should have 3 warnings - W001, W006, and W009, with 10 occurrences each.
    // If running on Travis we may have another warning, W008, due to timestamp being older than 65 seconds
    assertTrue(allErrorLists.length == 3 || allErrorLists.length == 4);
    for (ErrorListHelperModel model : allErrorLists) {
        switch(model.getErrorMessage().getValidationRule().getErrorId()) {
            case "W001":
                assertEquals(10, model.getOccurrenceList().size());
                break;
            case "W006":
                assertEquals(10, model.getOccurrenceList().size());
                break;
            case "W008":
                assertEquals(1, model.getOccurrenceList().size());
                break;
            case "W009":
                assertEquals(10, model.getOccurrenceList().size());
                break;
        }
    }
}
Also used : ErrorListHelperModel(edu.usf.cutr.gtfsrtvalidator.lib.model.helper.ErrorListHelperModel) BatchProcessor(edu.usf.cutr.gtfsrtvalidator.lib.batch.BatchProcessor) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 2 with BatchProcessor

use of edu.usf.cutr.gtfsrtvalidator.lib.batch.BatchProcessor in project gtfs-realtime-validator by CUTR-at-USF.

the class Main method main.

public static void main(String[] args) throws InterruptedException, ParseException {
    // Parse command line parameters
    Options options = setupCommandLineOptions();
    // Process archived files and then terminate
    String gtfs = getGtfsPathAndFileFromArgs(options, args);
    String gtfsRealtime = getGtfsRealtimePath(options, args);
    if (gtfs == null || gtfsRealtime == null) {
        throw new IllegalArgumentException("For batch mode you must provide a path and file name to GTFS data (e.g., -gtfs /dir/gtfs.zip) and path to directory of all archived GTFS-rt files (e.g., -gtfs-realtime-path /dir/gtfsarchive)");
    }
    BatchProcessor.SortBy sortBy = getSortBy(options, args);
    String plainText = getPlainTextFileExtensionfromArgs(options, args);
    boolean returnStats = getReturnStatsFromArgs(options, args);
    boolean ignoreShapes = getIgnoreShapesFromArgs(options, args);
    BatchProcessor.Builder builder = new BatchProcessor.Builder(gtfs, gtfsRealtime).sortBy(sortBy).setPlainTextExtension(plainText).setReturnStatistics(returnStats).setIgnoreShapes(ignoreShapes);
    BatchProcessor processor = builder.build();
    try {
        List<IterationStatistics> stats = processor.processFeeds();
        if (returnStats) {
            _log.info("-------------------------");
            _log.info("  Validation Statistics");
            _log.info("-------------------------");
            for (IterationStatistics stat : stats) {
                _log.info(stat.toString());
            }
        }
    } catch (IOException | NoSuchAlgorithmException e) {
        _log.error("Error running batch processor: " + e);
    }
}
Also used : IterationStatistics(edu.usf.cutr.gtfsrtvalidator.lib.validation.IterationStatistics) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) BatchProcessor(edu.usf.cutr.gtfsrtvalidator.lib.batch.BatchProcessor)

Aggregations

BatchProcessor (edu.usf.cutr.gtfsrtvalidator.lib.batch.BatchProcessor)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ErrorListHelperModel (edu.usf.cutr.gtfsrtvalidator.lib.model.helper.ErrorListHelperModel)1 IterationStatistics (edu.usf.cutr.gtfsrtvalidator.lib.validation.IterationStatistics)1 File (java.io.File)1 IOException (java.io.IOException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 Test (org.junit.Test)1