Search in sources :

Example 16 with AgencyAndId

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

the class WSFScheduleService method resolve.

public Trip resolve(String departingTerminalId, long departureTime, String arrivingTerminalId) {
    ServiceDate initialServiceDate = new ServiceDate(new Date(departureTime * 1000));
    int lookBackDays = (_maxStopTime / 86400) + 1;
    AgencyAndId stopId = new AgencyAndId(_agencyId, departingTerminalId);
    AgencyAndId routeId = new AgencyAndId(_agencyId, departingTerminalId + arrivingTerminalId);
    for (StopTime st : _dao.getAllStopTimes()) {
        if (st.getStop().getId().equals(stopId) && st.getTrip().getRoute().getId().equals(routeId)) {
            ServiceDate sd = initialServiceDate;
            for (int i = 0; i < lookBackDays; i++) {
                if (_csd.getServiceIdsForDate(sd).contains(st.getTrip().getServiceId()) && st.getDepartureTime() == (departureTime - (sd.getAsCalendar(_agencyTimeZone).getTimeInMillis() / 1000))) {
                    return st.getTrip();
                }
                sd = sd.previous();
            }
        }
    }
    _log.warn("no trip found for resolve(departId=" + departingTerminalId + ", departureTime=" + departureTime + ", arrivalId=" + arrivingTerminalId + ")");
    return null;
}
Also used : ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Date(java.util.Date) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) StopTime(org.onebusaway.gtfs.model.StopTime)

Example 17 with AgencyAndId

use of org.onebusaway.gtfs.model.AgencyAndId 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 18 with AgencyAndId

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

the class TrimTripTransformStrategyTest method testStopTimeTrimming.

@Test
public void testStopTimeTrimming() throws IOException {
    _gtfs.putAgencies(1);
    _gtfs.putStops(6);
    _gtfs.putRoutes(1);
    _gtfs.putTrips(1, "r0", "sid0");
    _gtfs.putStopTimes("t0", "s0,s1,s2,s3,s4,s5");
    GtfsMutableRelationalDao dao = _gtfs.read();
    TrimOperation operation = new TrimOperation();
    operation.setMatch(new TypedEntityMatch(Trip.class, new AlwaysMatch()));
    operation.setToStopId("s1");
    operation.setFromStopId("s4");
    _strategy.addOperation(operation);
    _strategy.run(_context, dao);
    Collection<Trip> allTrips = dao.getAllTrips();
    assertEquals(1, allTrips.size());
    Trip trip = allTrips.iterator().next();
    assertEquals(new AgencyAndId("a0", "t0-s1-s4"), trip.getId());
    List<StopTime> stopTimes = dao.getStopTimesForTrip(trip);
    assertEquals(2, stopTimes.size());
    assertEquals("s2", stopTimes.get(0).getStop().getId().getId());
    assertEquals("s3", stopTimes.get(1).getStop().getId().getId());
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) TypedEntityMatch(org.onebusaway.gtfs_transformer.match.TypedEntityMatch) Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TrimOperation(org.onebusaway.gtfs_transformer.updates.TrimTripTransformStrategy.TrimOperation) AlwaysMatch(org.onebusaway.gtfs_transformer.match.AlwaysMatch) StopTime(org.onebusaway.gtfs.model.StopTime) Test(org.junit.Test)

Example 19 with AgencyAndId

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

the class TrimTripTransformStrategyTest method testShapeTrimming.

@Test
public void testShapeTrimming() throws IOException {
    _gtfs.putAgencies(1);
    _gtfs.putLines("stops.txt", "stop_id,stop_name,stop_lat,stop_lon", "s0,S0,47.668422,-122.290149", "s1,S1,47.670300,-122.290235", "s2,S2,47.672172,-122.290213", "s3,S3,47.673985,-122.290277", "s4,S4,47.675791,-122.290213", "s5,S5,47.677626,-122.290320");
    _gtfs.putRoutes(1);
    _gtfs.putTrips(1, "r0", "sid0", "shape_id=shape0");
    _gtfs.putStopTimes("t0", "s0,s1,s2,s3,s4,s5");
    _gtfs.putLines("shapes.txt", "shape_id,shape_pt_sequence,shape_pt_lat,shape_pt_lon", "shape0,0,47.668422,-122.290149", "shape0,1,47.670300,-122.290235", "shape0,2,47.672172,-122.290213", "shape0,3,47.673985,-122.290277", "shape0,4,47.675791,-122.290213", "shape0,5,47.677626,-122.290320");
    GtfsMutableRelationalDao dao = _gtfs.read();
    TrimOperation operation = new TrimOperation();
    operation.setMatch(new TypedEntityMatch(Trip.class, new AlwaysMatch()));
    operation.setToStopId("s0");
    operation.setFromStopId("s4");
    _strategy.addOperation(operation);
    _strategy.run(_context, dao);
    Trip trip = dao.getTripForId(new AgencyAndId("a0", "t0-s0-s4"));
    assertEquals(new AgencyAndId("a0", "shape0-s1-s3"), trip.getShapeId());
    List<ShapePoint> shapePoints = dao.getShapePointsForShapeId(trip.getShapeId());
    assertEquals(3, shapePoints.size());
    assertEquals(47.670300, shapePoints.get(0).getLat(), 1e-6);
    assertEquals(47.673985, shapePoints.get(2).getLat(), 1e-6);
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) TypedEntityMatch(org.onebusaway.gtfs_transformer.match.TypedEntityMatch) Trip(org.onebusaway.gtfs.model.Trip) ShapePoint(org.onebusaway.gtfs.model.ShapePoint) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TrimOperation(org.onebusaway.gtfs_transformer.updates.TrimTripTransformStrategy.TrimOperation) AlwaysMatch(org.onebusaway.gtfs_transformer.match.AlwaysMatch) Test(org.junit.Test)

Example 20 with AgencyAndId

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

the class GtfsRelationalDaoImpl method getStopsForStation.

@Override
public List<Stop> getStopsForStation(Stop station) {
    if (_stopsByStation == null) {
        _stopsByStation = new HashMap<Stop, List<Stop>>();
        for (Stop stop : getAllStops()) {
            if (stop.getLocationType() == 0 && stop.getParentStation() != null) {
                Stop parentStation = getStopForId(new AgencyAndId(stop.getId().getAgencyId(), stop.getParentStation()));
                List<Stop> subStops = _stopsByStation.get(parentStation);
                if (subStops == null) {
                    subStops = new ArrayList<Stop>(2);
                    _stopsByStation.put(parentStation, subStops);
                }
                subStops.add(stop);
            }
        }
    }
    return list(_stopsByStation.get(station));
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)102 Test (org.junit.Test)63 Trip (org.onebusaway.gtfs.model.Trip)37 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)25 Stop (org.onebusaway.gtfs.model.Stop)24 ServiceCalendar (org.onebusaway.gtfs.model.ServiceCalendar)17 ServiceCalendarDate (org.onebusaway.gtfs.model.ServiceCalendarDate)16 ArrayList (java.util.ArrayList)15 Route (org.onebusaway.gtfs.model.Route)15 StopTime (org.onebusaway.gtfs.model.StopTime)15 GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)15 Agency (org.onebusaway.gtfs.model.Agency)13 ShapePoint (org.onebusaway.gtfs.model.ShapePoint)12 GtfsRelationalDao (org.onebusaway.gtfs.services.GtfsRelationalDao)11 HashSet (java.util.HashSet)10 GtfsRelationalDaoImpl (org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl)10 List (java.util.List)9 Frequency (org.onebusaway.gtfs.model.Frequency)9 CalendarService (org.onebusaway.gtfs.services.calendar.CalendarService)7 Set (java.util.Set)6