use of org.onebusaway.gtfs_merge.strategies.ServiceCalendarMergeStrategy in project onebusaway-application-modules by camsys.
the class GtfsMergeTask method run.
public void run() {
if (!requestResponse.getRequest().getConsolidateFlag()) {
_log.info("consolidate flag not set, extiting");
return;
}
_log.info("GtfsMergeTask Starting with outputDirectory=" + getOutputDirectory());
try {
_log.info("Started merging modified GTFS feeds.");
GtfsBundles gtfsBundles = getGtfsBundles(_applicationContext);
List<File> inputPaths = new ArrayList<File>();
// note this will be overridden if properly configured
String outputLocation = System.getProperty("java.io.tmpdir") + File.separator + "gtfs_puget_sound_consolidated.zip";
if (getOutputDirectory() != null) {
String consolidatedPath = getOutputDirectory() + File.separator + CONSOLIDATED_DIR;
File consolidatedDir = new File(consolidatedPath);
consolidatedDir.mkdirs();
outputLocation = consolidatedPath + File.separator + "gtfs_puget_sound_consolidated.zip";
}
_log.info("Consolidated file output location: " + outputLocation);
int i = 0;
for (GtfsBundle gtfsBundle : gtfsBundles.getBundles()) {
if (gtfsBundle.getPath() != null) {
_log.info("addiing agency data file path for agency[" + i + "]=" + gtfsBundle.getPath());
inputPaths.add(gtfsBundle.getPath());
} else {
_log.info("null file path for agency.");
}
}
// Now call GTFS merger
GtfsMerger feedMerger = new GtfsMerger();
AgencyMergeStrategy agencyStrategy = new AgencyMergeStrategy();
// agencies aren't duplicates, its by design
agencyStrategy.setDuplicateDetectionStrategy(EDuplicateDetectionStrategy.FUZZY);
feedMerger.setAgencyStrategy(agencyStrategy);
StopMergeStrategy stopStrategy = new StopMergeStrategy();
stopStrategy.setDuplicateRenamingStrategy(EDuplicateRenamingStrategy.AGENCY);
feedMerger.setStopStrategy(stopStrategy);
RouteMergeStrategy routeStrategy = new RouteMergeStrategy();
routeStrategy.setDuplicateRenamingStrategy(EDuplicateRenamingStrategy.AGENCY);
feedMerger.setRouteStrategy(routeStrategy);
ServiceCalendarMergeStrategy serviceCalendarStrategy = new ServiceCalendarMergeStrategy();
serviceCalendarStrategy.setDuplicateRenamingStrategy(EDuplicateRenamingStrategy.AGENCY);
feedMerger.setServiceCalendarStrategy(serviceCalendarStrategy);
TripMergeStrategy tripStrategy = new TripMergeStrategy();
tripStrategy.setDuplicateRenamingStrategy(EDuplicateRenamingStrategy.AGENCY);
feedMerger.setTripStrategy(tripStrategy);
File outputFile = new File(outputLocation);
outputFile.createNewFile();
feedMerger.run(inputPaths, new File(outputLocation));
} catch (Throwable ex) {
_log.error("Error merging gtfs:", ex);
} finally {
_log.info("GtfsMergeTask Exiting");
}
}
use of org.onebusaway.gtfs_merge.strategies.ServiceCalendarMergeStrategy in project onebusaway-gtfs-modules by OneBusAway.
the class GtfsMergerTest method testRenameStrategy.
@Test
public void testRenameStrategy() throws IOException {
// lowest priority feed (first) to highest priority feed (last)
_oldGtfs.putLines("agency.txt", "agency_id,agency_name,agency_url,agency_timezone", "3,Pierce,http://p.us/,America/Los_Angeles");
_oldGtfs.putLines("routes.txt", "route_id,route_short_name,route_long_name,route_type", "R10,10,The Pierce Ten,3");
_oldGtfs.putLines("stops.txt", "stop_id,stop_name,stop_lat,stop_lon", "100,The Stop,47.654403,-122.305211", "200,Pierce Other Stop,47.668594,-122.298859", "400,Pierce Only Stop,47.669563,-122.305420");
_oldGtfs.putLines("calendars.txt", "service_id,monday,tuesday,wednesday,thursday,friday,saturday,sunday,start_date,end_date", "sid0,1,1,1,1,1,0,0,20110101,20111231");
_oldGtfs.putLines("trips.txt", "route_id,service_id,trip_id", "R10,sid0,T10-0", "R10,sid0,T10-1");
// stop conflict only
_oldGtfs.putStopTimes("T10-0", "100,200");
_oldGtfs.putStopTimes("T10-1", "100,400");
_oldGtfs.putLines("stop_times.txt", "trip_id,stop_id,stop_sequence,arrival_time,departure_time", "T10-0,100,0,08:00:00,08:00:00", "T10-0,200,1,09:00:00,09:00:00", "T10-1,100,1,08:00:00,08:00:00", "T10-1,400,1,09:00:00,09:00:00");
_newGtfs.putLines("agency.txt", "agency_id,agency_name,agency_url,agency_timezone", "1,Metro,http://metro.gov/,America/Los_Angeles", "3,Pierce,http://p.us/,America/Los_Angeles");
_newGtfs.putLines("routes.txt", "agency_id,route_id,route_short_name,route_long_name,route_type", "1,R10,10,The KCM Ten,3");
_newGtfs.putLines("stops.txt", "stop_id,stop_name,stop_lat,stop_lon", "100,The Stop,47.654403,-122.305211", "200,The Other Stop,47.656303,-122.315436", "300,The Third Stop,47.668575,-122.283653");
_newGtfs.putCalendars(1, "mask=1111100", "start_date=20120504", "end_date=20120608");
_newGtfs.putLines("trips.txt", "route_id,service_id,trip_id", "R10,sid0,T10-0");
_newGtfs.putLines("stop_times.txt", "trip_id,stop_id,stop_sequence,arrival_time,departure_time", "T10-0,100,0,08:00:00,08:00:00", "T10-0,200,1,09:00:00,09:00:00", "T10-0,300,1,10:00:00,10:00:00");
_pugetGtfs = MockGtfs.create();
_pugetGtfs.putLines("agency.txt", "agency_id,agency_name,agency_url,agency_timezone", "0,Puget Sound Region,http://puget-sound.gov/,America/Los_Angeles");
_pugetGtfs.putLines("routes.txt", "route_id,route_short_name,route_long_name,route_type", "");
_pugetGtfs.putLines("stops.txt", "stop_id,stop_name,stop_lat,stop_lon", "");
_pugetGtfs.putLines("calendars.txt", "service_id,monday,tuesday,wednesday,thursday,friday,saturday,sunday,start_date,end_date", "");
_pugetGtfs.putCalendars(1, "mask=1111100", "start_date=20120504", "end_date=20120608");
_pugetGtfs.putLines("trips.txt", "route_id,service_id,trip_id", "");
_pugetGtfs.putLines("stop_times.txt", "trip_id,stop_id,stop_sequence,arrival_time,departure_time", "");
AgencyMergeStrategy agencyStrategy = new AgencyMergeStrategy();
agencyStrategy.setDuplicateDetectionStrategy(EDuplicateDetectionStrategy.FUZZY);
_merger.setAgencyStrategy(agencyStrategy);
TripMergeStrategy tripStrategy = new TripMergeStrategy();
tripStrategy.setDuplicateDetectionStrategy(EDuplicateDetectionStrategy.FUZZY);
tripStrategy.setDuplicateRenamingStrategy(EDuplicateRenamingStrategy.AGENCY);
_merger.setTripStrategy(tripStrategy);
StopMergeStrategy stopStrategy = new StopMergeStrategy();
stopStrategy.setDuplicateDetectionStrategy(EDuplicateDetectionStrategy.FUZZY);
stopStrategy.setDuplicateRenamingStrategy(EDuplicateRenamingStrategy.AGENCY);
stopStrategy.setLogDuplicatesStrategy(ELogDuplicatesStrategy.WARNING);
_merger.setStopStrategy(stopStrategy);
RouteMergeStrategy routeStrategy = new RouteMergeStrategy();
routeStrategy.setDuplicateDetectionStrategy(EDuplicateDetectionStrategy.FUZZY);
routeStrategy.setDuplicateRenamingStrategy(EDuplicateRenamingStrategy.AGENCY);
_merger.setRouteStrategy(routeStrategy);
ServiceCalendarMergeStrategy serviceStrategy = new ServiceCalendarMergeStrategy();
serviceStrategy.setDuplicateDetectionStrategy(EDuplicateDetectionStrategy.FUZZY);
serviceStrategy.setDuplicateRenamingStrategy(EDuplicateRenamingStrategy.AGENCY);
_merger.setServiceCalendarStrategy(serviceStrategy);
GtfsRelationalDao dao = merge();
// pierce is included twice, it should not show up as a duplicate
assertTrue(dao.getAllAgencies().size() == 3);
for (Trip trip : dao.getAllTrips()) {
String tripId = trip.getId().getId();
// AGENCY renaming strategy
assertTrue(!tripId.matches("^[a-j]-.*"));
assertTrue(dao.getStopTimesForTrip(trip).size() > 0);
}
boolean pugetStopFound = false;
for (Stop stop : dao.getAllStops()) {
if ("0".equals(stop.getId().getAgencyId())) {
pugetStopFound = true;
}
String stopId = stop.getId().getId();
// AGENCY renaming strategy
assertTrue(!stopId.matches("^[a-j]-.*"));
}
for (Route route : dao.getAllRoutes()) {
String routeId = route.getId().getId();
// AGENCY renaming strategy
assertTrue(!routeId.matches("^[a-j]-.*"));
}
for (ServiceCalendar service : dao.getAllCalendars()) {
String serviceId = service.getServiceId().getId();
assertTrue(!serviceId.matches("^[a-j]-.*"));
}
assertTrue("b-sid0".matches("[a-j]-.*"));
assertTrue("expect a puget stop", pugetStopFound);
}
Aggregations