Search in sources :

Example 6 with Stop

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

the class RouteStopsInCommonDuplicateScoringStrategy method getAllStopsForRoute.

private Set<Stop> getAllStopsForRoute(GtfsRelationalDao dao, Route route) {
    Set<Stop> stops = new HashSet<Stop>();
    List<Trip> tripsForRoute = new ArrayList<Trip>();
    // make this thread safe
    tripsForRoute.addAll(dao.getTripsForRoute(route));
    for (Trip trip : tripsForRoute) {
        List<StopTime> stopTimesForTrip = new ArrayList<StopTime>();
        stopTimesForTrip.addAll(dao.getStopTimesForTrip(trip));
        for (StopTime stopTime : stopTimesForTrip) {
            stops.add(stopTime.getStop());
        }
    }
    return stops;
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) Stop(org.onebusaway.gtfs.model.Stop) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) StopTime(org.onebusaway.gtfs.model.StopTime)

Example 7 with Stop

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

the class StopMergeStrategy method save.

@Override
protected void save(GtfsMergeContext context, IdentityBean<?> entity) {
    GtfsRelationalDao source = context.getSource();
    GtfsMutableRelationalDao target = context.getTarget();
    Stop stop = (Stop) entity;
    super.save(context, entity);
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) GtfsRelationalDao(org.onebusaway.gtfs.services.GtfsRelationalDao) Stop(org.onebusaway.gtfs.model.Stop)

Example 8 with Stop

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

the class TrimTripTransformStrategy 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(shapeId.getAgencyId(), 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)

Example 9 with Stop

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

the class TripKey method getTripKeyForTrip.

public static TripKey getTripKeyForTrip(GtfsMutableRelationalDao dao, Trip trip) {
    List<StopTime> stopTimes = dao.getStopTimesForTrip(trip);
    Stop[] stops = new Stop[stopTimes.size()];
    int[] arrivalTimes = new int[stopTimes.size()];
    int[] departureTimes = new int[stopTimes.size()];
    for (int i = 0; i < stopTimes.size(); i++) {
        StopTime stopTime = stopTimes.get(i);
        stops[i] = stopTime.getStop();
        arrivalTimes[i] = stopTime.getArrivalTime();
        departureTimes[i] = stopTime.getDepartureTime();
    }
    return new TripKey(stops, arrivalTimes, departureTimes);
}
Also used : Stop(org.onebusaway.gtfs.model.Stop) StopTime(org.onebusaway.gtfs.model.StopTime)

Example 10 with Stop

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

the class EntityRetentionGraphTest method testRetainStop.

@Test
public void testRetainStop() {
    Stop stop = _dao.getStopForId(aid("A"));
    _graph.retainUp(stop);
    // 9 stop_times + 3 trips + 1 route + 1 agency + 3 stops + 1 service id + 1
    // calendar
    assertEquals(19, _graph.getSize());
    assertTrue(_graph.isRetained(_dao.getStopForId(aid("A"))));
    assertTrue(_graph.isRetained(_dao.getStopForId(aid("B"))));
    assertTrue(_graph.isRetained(_dao.getStopForId(aid("C"))));
    assertFalse(_graph.isRetained(_dao.getStopForId(aid("D"))));
    assertTrue(_graph.isRetained(_dao.getTripForId(aid("1.1"))));
    assertTrue(_graph.isRetained(_dao.getTripForId(aid("1.2"))));
    assertTrue(_graph.isRetained(_dao.getTripForId(aid("1.3"))));
    assertFalse(_graph.isRetained(_dao.getTripForId(aid("2.1"))));
    assertTrue(_graph.isRetained(_dao.getRouteForId(aid("1"))));
    assertFalse(_graph.isRetained(_dao.getRouteForId(aid("2"))));
    assertTrue(_graph.isRetained(_dao.getAgencyForId("agency")));
    _graph.retainUp(stop);
    assertEquals(19, _graph.getSize());
}
Also used : Stop(org.onebusaway.gtfs.model.Stop) Test(org.junit.Test)

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