Search in sources :

Example 11 with GtfsRelationalDao

use of org.onebusaway.gtfs.services.GtfsRelationalDao in project onebusaway-gtfs-modules by OneBusAway.

the class GtfsTransformerTest method testUpdateTrips.

@Test
public void testUpdateTrips() throws Exception {
    GtfsRelationalDao dao = transform("{'op':'update', 'match':{'file':'trips.txt', 'route_id':'r0'}, 'update':{'route_id': 'r1'}}");
    assertEquals(2, dao.getTripsForRoute(dao.getRouteForId(new AgencyAndId("a0", "r1"))).size());
}
Also used : GtfsRelationalDao(org.onebusaway.gtfs.services.GtfsRelationalDao) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Test(org.junit.Test)

Example 12 with GtfsRelationalDao

use of org.onebusaway.gtfs.services.GtfsRelationalDao in project onebusaway-gtfs-modules by OneBusAway.

the class GtfsTransformerTest method testRetainCalendarCollection.

@Test
public void testRetainCalendarCollection() throws Exception {
    GtfsRelationalDao dao = transform("{'op':'retain', 'match':{'collection':'calendar', 'service_id':'sid1'}}");
    assertNull(dao.getCalendarForServiceId(new AgencyAndId("a0", "sid0")));
    assertNull(dao.getTripForId(new AgencyAndId("a0", "t0")));
}
Also used : GtfsRelationalDao(org.onebusaway.gtfs.services.GtfsRelationalDao) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Test(org.junit.Test)

Example 13 with GtfsRelationalDao

use of org.onebusaway.gtfs.services.GtfsRelationalDao in project onebusaway-gtfs-modules by OneBusAway.

the class GtfsTransformerTest method testRemoveRoute.

@Test
public void testRemoveRoute() throws Exception {
    GtfsRelationalDao dao = transform("{'op':'remove', 'match':{'file':'routes.txt', 'route_id':'r0'}}");
    assertNull(dao.getRouteForId(new AgencyAndId("a0", "r0")));
    assertNotNull(dao.getRouteForId(new AgencyAndId("a0", "r1")));
    assertNull(dao.getTripForId(new AgencyAndId("a0", "t0")));
    assertNotNull(dao.getTripForId(new AgencyAndId("a0", "t1")));
    assertEquals(2, dao.getAllStopTimes().size());
}
Also used : GtfsRelationalDao(org.onebusaway.gtfs.services.GtfsRelationalDao) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Test(org.junit.Test)

Example 14 with GtfsRelationalDao

use of org.onebusaway.gtfs.services.GtfsRelationalDao in project onebusaway-gtfs-modules by OneBusAway.

the class AbstractIdentifiableSingleEntityMergeStrategy method pickBestDuplicateDetectionStrategy.

@Override
protected EDuplicateDetectionStrategy pickBestDuplicateDetectionStrategy(GtfsMergeContext context) {
    /**
     * If there are currently no elements to be duplicated, then return the NONE
     * strategy.
     */
    GtfsRelationalDao source = context.getSource();
    GtfsMutableRelationalDao target = context.getTarget();
    if (target.getAllEntitiesForType(_entityType).isEmpty() || source.getAllEntitiesForType(_entityType).isEmpty()) {
        return EDuplicateDetectionStrategy.NONE;
    }
    if (hasLikelyIdentifierOverlap(context)) {
        return EDuplicateDetectionStrategy.IDENTITY;
    } else if (hasLikelyFuzzyOverlap(context)) {
        return EDuplicateDetectionStrategy.FUZZY;
    } else {
        return EDuplicateDetectionStrategy.NONE;
    }
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) GtfsRelationalDao(org.onebusaway.gtfs.services.GtfsRelationalDao)

Example 15 with GtfsRelationalDao

use of org.onebusaway.gtfs.services.GtfsRelationalDao in project onebusaway-gtfs-modules by OneBusAway.

the class GtfsMergerTest method testAgencyPreference.

@Test
public void testAgencyPreference() 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", "R11,11,The Eleven,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", "sid1,1,1,1,1,1,0,0,20110101,20111231");
    _oldGtfs.putLines("trips.txt", "route_id,service_id,trip_id", "R11,sid1,T11-0", "R11,sid1,T11-1");
    // stop conflict only
    _oldGtfs.putStopTimes("T11-0", "100,200");
    _oldGtfs.putStopTimes("T11-1", "100,400");
    _oldGtfs.putLines("stop_times.txt", "trip_id,stop_id,stop_sequence,arrival_time,departure_time", "T11-0,100,0,08:00:00,08:00:00", "T11-0,200,1,09:00:00,09:00:00", "T11-1,100,1,08:00:00,08:00:00", "T11-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 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);
    _merger.setTripStrategy(tripStrategy);
    StopMergeStrategy stopStrategy = new StopMergeStrategy();
    stopStrategy.setDuplicateDetectionStrategy(EDuplicateDetectionStrategy.FUZZY);
    stopStrategy.setDuplicateRenamingStrategy(EDuplicateRenamingStrategy.AGENCY);
    stopStrategy.setLogDuplicatesStrategy(ELogDuplicatesStrategy.WARNING);
    _merger.setStopStrategy(stopStrategy);
    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()) {
        assertTrue(dao.getStopTimesForTrip(trip).size() > 0);
    }
    boolean pugetStopFound = false;
    for (Stop stop : dao.getAllStops()) {
        if ("0".equals(stop.getId().getAgencyId())) {
            pugetStopFound = true;
        }
    }
    assertTrue("expect a puget stop", pugetStopFound);
}
Also used : GtfsRelationalDao(org.onebusaway.gtfs.services.GtfsRelationalDao) Trip(org.onebusaway.gtfs.model.Trip) TripMergeStrategy(org.onebusaway.gtfs_merge.strategies.TripMergeStrategy) AgencyMergeStrategy(org.onebusaway.gtfs_merge.strategies.AgencyMergeStrategy) Stop(org.onebusaway.gtfs.model.Stop) StopMergeStrategy(org.onebusaway.gtfs_merge.strategies.StopMergeStrategy) Test(org.junit.Test)

Aggregations

GtfsRelationalDao (org.onebusaway.gtfs.services.GtfsRelationalDao)29 Test (org.junit.Test)15 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)11 Trip (org.onebusaway.gtfs.model.Trip)8 GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)7 ServiceCalendar (org.onebusaway.gtfs.model.ServiceCalendar)6 ServiceCalendarDate (org.onebusaway.gtfs.model.ServiceCalendarDate)5 Stop (org.onebusaway.gtfs.model.Stop)5 StopTime (org.onebusaway.gtfs.model.StopTime)5 Agency (org.onebusaway.gtfs.model.Agency)3 TripMergeStrategy (org.onebusaway.gtfs_merge.strategies.TripMergeStrategy)3 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 Frequency (org.onebusaway.gtfs.model.Frequency)2 Route (org.onebusaway.gtfs.model.Route)2 ShapePoint (org.onebusaway.gtfs.model.ShapePoint)2 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)2 AgencyMergeStrategy (org.onebusaway.gtfs_merge.strategies.AgencyMergeStrategy)2 StopMergeStrategy (org.onebusaway.gtfs_merge.strategies.StopMergeStrategy)2 Serializable (java.io.Serializable)1