Search in sources :

Example 21 with Stop

use of org.onebusaway.gtfs.model.Stop in project onebusaway-gtfs-modules by OneBusAway.

the class HibernateGtfsRelationalDaoImplTest method testStopsForStation.

@Test
public void testStopsForStation() {
    Stop stationA = new Stop();
    stationA.setId(new AgencyAndId("X", "A"));
    _dao.saveEntity(stationA);
    Stop stationB = new Stop();
    stationB.setId(new AgencyAndId("X", "B"));
    _dao.saveEntity(stationB);
    Stop stopA1 = new Stop();
    stopA1.setId(new AgencyAndId("X", "A1"));
    stopA1.setParentStation("A");
    _dao.saveEntity(stopA1);
    Stop stopA2 = new Stop();
    stopA2.setId(new AgencyAndId("X", "A2"));
    stopA2.setParentStation("A");
    _dao.saveEntity(stopA2);
    Stop stopB1 = new Stop();
    stopB1.setId(new AgencyAndId("X", "B1"));
    stopB1.setParentStation("B");
    _dao.saveEntity(stopB1);
    _dao.flush();
    Stop station2 = _dao.getStopForId(new AgencyAndId("X", "A"));
    List<Stop> stops = _dao.getStopsForStation(station2);
    assertEquals(2, stops.size());
    Set<String> ids = new HashSet<String>();
    ids.add("A1");
    ids.add("A2");
    assertTrue(ids.contains(stops.get(0).getId().getId()));
    assertTrue(ids.contains(stops.get(1).getId().getId()));
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 22 with Stop

use of org.onebusaway.gtfs.model.Stop 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)

Example 23 with Stop

use of org.onebusaway.gtfs.model.Stop 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);
}
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) RouteMergeStrategy(org.onebusaway.gtfs_merge.strategies.RouteMergeStrategy) StopMergeStrategy(org.onebusaway.gtfs_merge.strategies.StopMergeStrategy) ServiceCalendarMergeStrategy(org.onebusaway.gtfs_merge.strategies.ServiceCalendarMergeStrategy) Route(org.onebusaway.gtfs.model.Route) ServiceCalendar(org.onebusaway.gtfs.model.ServiceCalendar) Test(org.junit.Test)

Example 24 with Stop

use of org.onebusaway.gtfs.model.Stop in project onebusaway-gtfs-modules by OneBusAway.

the class AgencyMergeStrategyTest method testRenameAllAgencyIdReferences.

@Test
public void testRenameAllAgencyIdReferences() {
    GtfsRelationalDaoImpl sourceA = new GtfsRelationalDaoImpl();
    Agency agencyA = new Agency();
    agencyA.setId("1");
    agencyA.setName("Metro");
    agencyA.setUrl("http://metro.gov/");
    sourceA.saveEntity(agencyA);
    GtfsRelationalDaoImpl sourceB = new GtfsRelationalDaoImpl();
    Agency agencyB = new Agency();
    agencyB.setId("1");
    agencyA.setName("Metra");
    agencyA.setUrl("http://metra.gov/");
    sourceB.saveEntity(agencyB);
    Route route = new Route();
    route.setAgency(agencyB);
    route.setId(new AgencyAndId("1", "routeId"));
    sourceB.saveEntity(route);
    Trip trip = new Trip();
    trip.setRoute(route);
    trip.setId(new AgencyAndId("1", "tripId"));
    trip.setServiceId(new AgencyAndId("1", "serviceId"));
    trip.setShapeId(new AgencyAndId("1", "shapeId"));
    sourceB.saveEntity(trip);
    FareAttribute fare = new FareAttribute();
    fare.setId(new AgencyAndId("1", "fareId"));
    sourceB.saveEntity(fare);
    Stop stop = new Stop();
    stop.setId(new AgencyAndId("1", "stopId"));
    sourceB.saveEntity(stop);
    ServiceCalendar calendar = new ServiceCalendar();
    calendar.setServiceId(new AgencyAndId("1", "serviceId"));
    sourceB.saveEntity(calendar);
    ServiceCalendarDate calendarDate = new ServiceCalendarDate();
    calendarDate.setServiceId(new AgencyAndId("1", "serviceId"));
    sourceB.saveEntity(calendarDate);
    ShapePoint point = new ShapePoint();
    point.setShapeId(new AgencyAndId("1", "shapeId"));
    sourceB.saveEntity(point);
    _strategy.merge(context(sourceA, _target, "a-"));
    _strategy.merge(context(sourceB, _target, "b-"));
    Collection<Agency> agencies = _target.getAllAgencies();
    assertEquals(2, agencies.size());
    assertSame(agencyA, _target.getAgencyForId("1"));
    assertSame(agencyB, _target.getAgencyForId("b-1"));
    assertEquals("b-1", route.getId().getAgencyId());
    assertEquals("b-1", trip.getId().getAgencyId());
    assertEquals("b-1", trip.getServiceId().getAgencyId());
    assertEquals("b-1", trip.getShapeId().getAgencyId());
    assertEquals("b-1", fare.getId().getAgencyId());
    assertEquals("b-1", stop.getId().getAgencyId());
    assertEquals("b-1", calendar.getServiceId().getAgencyId());
    assertEquals("b-1", calendarDate.getServiceId().getAgencyId());
    assertEquals("b-1", point.getShapeId().getAgencyId());
}
Also used : FareAttribute(org.onebusaway.gtfs.model.FareAttribute) ServiceCalendarDate(org.onebusaway.gtfs.model.ServiceCalendarDate) Trip(org.onebusaway.gtfs.model.Trip) ShapePoint(org.onebusaway.gtfs.model.ShapePoint) Agency(org.onebusaway.gtfs.model.Agency) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) GtfsRelationalDaoImpl(org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl) Route(org.onebusaway.gtfs.model.Route) ServiceCalendar(org.onebusaway.gtfs.model.ServiceCalendar) Test(org.junit.Test)

Example 25 with Stop

use of org.onebusaway.gtfs.model.Stop in project onebusaway-gtfs-modules by OneBusAway.

the class SubsectionTripTransformStrategy method updateShape.

private void updateShape(GtfsMutableRelationalDao dao, Trip trip, List<StopTime> stopTimes, Set<AgencyAndId> newShapeIds) {
    if (stopTimes.size() < 2) {
        trip.setShapeId(null);
        return;
    }
    AgencyAndId shapeId = trip.getShapeId();
    if (shapeId == null || !shapeId.hasValues()) {
        return;
    }
    List<ShapePoint> points = dao.getShapePointsForShapeId(shapeId);
    if (points.isEmpty()) {
        return;
    }
    Stop firstStop = stopTimes.get(0).getStop();
    Stop lastStop = stopTimes.get(stopTimes.size() - 1).getStop();
    String id = shapeId.getId() + "-" + firstStop.getId().getId() + "-" + lastStop.getId().getId();
    AgencyAndId newShapeId = new AgencyAndId("1", id);
    trip.setShapeId(newShapeId);
    if (!newShapeIds.add(newShapeId)) {
        return;
    }
    int shapePointFrom = getClosestShapePointToStop(points, firstStop);
    int shapePointTo = getClosestShapePointToStop(points, lastStop);
    for (int index = shapePointFrom; index <= shapePointTo; ++index) {
        ShapePoint point = new ShapePoint(points.get(index));
        point.setId(0);
        point.setShapeId(newShapeId);
        dao.saveEntity(point);
    }
}
Also used : ShapePoint(org.onebusaway.gtfs.model.ShapePoint) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) ShapePoint(org.onebusaway.gtfs.model.ShapePoint)

Aggregations

Stop (org.onebusaway.gtfs.model.Stop)40 Test (org.junit.Test)29 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)24 StopTime (org.onebusaway.gtfs.model.StopTime)11 Trip (org.onebusaway.gtfs.model.Trip)11 Agency (org.onebusaway.gtfs.model.Agency)8 ShapePoint (org.onebusaway.gtfs.model.ShapePoint)7 Route (org.onebusaway.gtfs.model.Route)6 ServiceCalendar (org.onebusaway.gtfs.model.ServiceCalendar)6 FareAttribute (org.onebusaway.gtfs.model.FareAttribute)5 ServiceCalendarDate (org.onebusaway.gtfs.model.ServiceCalendarDate)5 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)5 GtfsRelationalDao (org.onebusaway.gtfs.services.GtfsRelationalDao)5 FareRule (org.onebusaway.gtfs.model.FareRule)4 GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 CsvEntityContextImpl (org.onebusaway.csv_entities.CsvEntityContextImpl)3 Frequency (org.onebusaway.gtfs.model.Frequency)3 Transfer (org.onebusaway.gtfs.model.Transfer)3