Search in sources :

Example 11 with GtfsBundles

use of org.onebusaway.transit_data_federation.bundle.model.GtfsBundles in project onebusaway-application-modules by camsys.

the class GtfsModTask method run.

@Override
public void run() {
    try {
        _log.info("GtfsModTask Starting");
        GtfsBundles gtfsBundles = getGtfsBundles(_applicationContext);
        for (GtfsBundle gtfsBundle : gtfsBundles.getBundles()) {
            String agencyId = parseAgencyDir(gtfsBundle.getPath().getPath());
            if (agencyId != null) {
                // lookup meta info for agency
                String modUrl = getModUrl(agencyId);
                _log.info("using modUrl=" + modUrl + " for agency " + agencyId + " and bundle " + gtfsBundle.getPath());
                if (modUrl != null) {
                    // run the mod script on this gtfsBundle
                    String oldFilename = gtfsBundle.getPath().getPath();
                    String transform = getTransform(agencyId, gtfsBundle.getPath().toString());
                    String newFilename = runModifications(gtfsBundle, agencyId, modUrl, transform);
                    logger.changelog("Transformed " + oldFilename + " to " + newFilename + " according to url " + getModUrl(agencyId));
                } else {
                    _log.info("no modUrl found for agency " + agencyId + " and bundle " + gtfsBundle.getPath());
                }
            }
        }
    } catch (Throwable ex) {
        _log.error("error modifying gtfs:", ex);
    } finally {
        _log.info("GtfsModTask Exiting");
    }
}
Also used : GtfsBundle(org.onebusaway.transit_data_federation.bundle.model.GtfsBundle) GtfsBundles(org.onebusaway.transit_data_federation.bundle.model.GtfsBundles)

Example 12 with GtfsBundles

use of org.onebusaway.transit_data_federation.bundle.model.GtfsBundles in project onebusaway-application-modules by camsys.

the class MissingBlockForTrips method run.

@Override
public void run() {
    _log.info("MissingBlockForTrips Task Starting (v2)");
    Set<String> linkTrips = new HashSet<String>();
    Set<String> linkBlocks = new HashSet<String>();
    Set<String> missingBlocks = new HashSet<String>();
    List<String> unlinkedTrips = new ArrayList<String>();
    Map<String, String> linkTripEntries = new HashMap<String, String>();
    GtfsBundles gtfsBundles = getGtfsBundles(_applicationContext);
    for (GtfsBundle gtfsBundle : gtfsBundles.getBundles()) {
        String gtfsFilePath = gtfsBundle.getPath().toString();
        if (gtfsBundle.getAgencyIdMappings().containsKey(LINK_AGENCY)) {
            CSVData blockCsvData = getCSVData(gtfsFilePath, GTFS_BLOCK);
            String blockHeaders = blockCsvData.getHeader();
            List<String> blockRows = blockCsvData.getRows();
            int routeIndex = getIndexForValue(blockHeaders, "block_route_num");
            int blockSeqIndex = getIndexForValue(blockHeaders, "block_seq_num");
            for (String row : blockRows) {
                String[] cols = row.split(",");
                if (LINK_ROUTE.equals(cols[routeIndex])) {
                    String linkBlock = cols[blockSeqIndex].trim();
                    linkBlocks.add(linkBlock);
                }
            }
            CSVData tripCsvData = getCSVData(gtfsFilePath, GTFS_TRIPS);
            String tripHeaders = tripCsvData.getHeader();
            List<String> tripRows = tripCsvData.getRows();
            int blockIndex = getIndexForValue(tripHeaders, "block_id");
            int routeIdIndex = getIndexForValue(tripHeaders, "route_id");
            int tripIndex = getIndexForValue(tripHeaders, "trip_id");
            for (String row : tripRows) {
                String[] cols = row.split(",");
                String tripBlock = cols[blockIndex].trim();
                String routeId = cols[routeIdIndex].trim();
                String tripId = cols[tripIndex];
                if (LINK_ROUTE_ID.equals(routeId)) {
                    linkTrips.add(tripId);
                    _log.info("adding LINK block=" + tripBlock + " for trip= " + tripId);
                    linkTripEntries.put(tripBlock, row);
                    if (linkBlocks.contains(tripBlock)) {
                        _log.info("found block " + tripBlock + " for trip= " + tripId);
                    } else {
                        _log.info("missing block " + tripBlock + " for trip= " + tripId);
                        missingBlocks.add(tripBlock);
                        unlinkedTrips.add(row);
                    }
                }
            }
            _log.info(linkTrips.size() + " trips found in trips.txt for LINK data with " + unlinkedTrips.size() + " unmatched.  " + missingBlocks.size() + " blocks not matched.");
        }
    }
    // Write out results to .csv file
    _logger.header(FILENAME_TRIP, "route_id,service_id,trip_id,trip_headsign,trip_short_name,direction_id,block_id,shape_id,peak_flag,fare_id");
    for (String trip : unlinkedTrips) {
        _logger.logCSV(FILENAME_TRIP, trip);
    }
    _logger.header(FILENAME_BLOCK, "block_id");
    for (String block : missingBlocks) {
        _logger.logCSV(FILENAME_BLOCK, block);
    }
    _log.info("MissingBlockForTrips Task Exiting");
}
Also used : GtfsBundle(org.onebusaway.transit_data_federation.bundle.model.GtfsBundle) GtfsBundles(org.onebusaway.transit_data_federation.bundle.model.GtfsBundles)

Example 13 with GtfsBundles

use of org.onebusaway.transit_data_federation.bundle.model.GtfsBundles in project onebusaway-application-modules by camsys.

the class MissingTripsForBlock method run.

@Override
public void run() {
    _log.info("MissingTripsForBlock Task Starting");
    Set<String> linkBlocks = new HashSet<String>();
    Map<String, String> linkBlockEntries = new HashMap<String, String>();
    GtfsBundles gtfsBundles = getGtfsBundles(_applicationContext);
    for (GtfsBundle gtfsBundle : gtfsBundles.getBundles()) {
        String gtfsFilePath = gtfsBundle.getPath().toString();
        if (gtfsBundle.getAgencyIdMappings().containsKey(LINK_AGENCY)) {
            CSVData blockCsvData = getCSVData(gtfsFilePath, GTFS_BLOCK);
            String blockHeaders = blockCsvData.getHeader();
            List<String> blockRows = blockCsvData.getRows();
            int blockSeqIndex = getIndexForValue(blockHeaders, "block_seq_num");
            int routeIndex = getIndexForValue(blockHeaders, "block_route_num");
            for (String row : blockRows) {
                String[] cols = row.split(",");
                if (LINK_ROUTE.equals(cols[routeIndex])) {
                    linkBlocks.add(cols[blockSeqIndex]);
                    linkBlockEntries.put(cols[blockSeqIndex], row);
                }
            }
            _log.info(linkBlocks.size() + " blocks found in blocks.txt");
            CSVData tripCsvData = getCSVData(gtfsFilePath, GTFS_TRIPS);
            String tripHeaders = tripCsvData.getHeader();
            List<String> tripRows = tripCsvData.getRows();
            int blockIndex = getIndexForValue(tripHeaders, "block_id");
            int routeIdIndex = getIndexForValue(tripHeaders, "route_id");
            int tripCount = 0;
            for (String row : tripRows) {
                String[] cols = row.split(",");
                String tripBlock = cols[blockIndex];
                if (linkBlocks.contains(tripBlock)) {
                    linkBlocks.remove(tripBlock);
                }
            }
            _log.info(linkBlocks.size() + " unmatched blocks!");
        }
    }
    // Write out results to .csv file
    _logger.header(FILENAME, "block_seq_num,block_var_num,block_route_num,block_run_num");
    for (String block : linkBlocks) {
        _logger.logCSV(FILENAME, linkBlockEntries.get(block));
    }
    _log.info("MissingTripsForBlock Task Exiting");
}
Also used : HashMap(java.util.HashMap) GtfsBundle(org.onebusaway.transit_data_federation.bundle.model.GtfsBundle) GtfsBundles(org.onebusaway.transit_data_federation.bundle.model.GtfsBundles) HashSet(java.util.HashSet)

Aggregations

GtfsBundle (org.onebusaway.transit_data_federation.bundle.model.GtfsBundle)13 GtfsBundles (org.onebusaway.transit_data_federation.bundle.model.GtfsBundles)13 File (java.io.File)3 ArrayList (java.util.ArrayList)2 GtfsReader (org.onebusaway.gtfs.serialization.GtfsReader)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 SessionFactory (org.hibernate.SessionFactory)1 Transaction (org.hibernate.Transaction)1 Configuration (org.hibernate.cfg.Configuration)1 Session (org.hibernate.classic.Session)1 GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)1 HibernateGtfsFactory (org.onebusaway.gtfs.services.HibernateGtfsFactory)1 GtfsMerger (org.onebusaway.gtfs_merge.GtfsMerger)1 AgencyMergeStrategy (org.onebusaway.gtfs_merge.strategies.AgencyMergeStrategy)1 RouteMergeStrategy (org.onebusaway.gtfs_merge.strategies.RouteMergeStrategy)1 ServiceCalendarMergeStrategy (org.onebusaway.gtfs_merge.strategies.ServiceCalendarMergeStrategy)1 StopMergeStrategy (org.onebusaway.gtfs_merge.strategies.StopMergeStrategy)1