use of org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry in project onebusaway-application-modules by camsys.
the class RouteServiceImpl method getStopsForRouteCollection.
@Override
@Cacheable
public Collection<AgencyAndId> getStopsForRouteCollection(AgencyAndId id) {
Set<AgencyAndId> stopIds = new HashSet<AgencyAndId>();
RouteCollectionEntry routeCollectionEntry = _transitGraphDao.getRouteCollectionForId(id);
for (RouteEntry route : routeCollectionEntry.getChildren()) {
List<TripEntry> trips = route.getTrips();
for (TripEntry trip : trips) {
List<StopTimeEntry> stopTimes = trip.getStopTimes();
for (StopTimeEntry stopTime : stopTimes) stopIds.add(stopTime.getStop().getId());
}
}
return new ArrayList<AgencyAndId>(stopIds);
}
use of org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry in project onebusaway-application-modules by camsys.
the class TripEntriesFactoryTest method test.
@Test
public void test() {
GtfsRelationalDao gtfsDao = Mockito.mock(GtfsRelationalDao.class);
Agency agency = new Agency();
agency.setId("1");
agency.setTimezone("America/Los_Angeles");
// gtfsDao.saveEntity(agency);
Route route = new Route();
route.setId(new AgencyAndId("1", "routeA"));
route.setAgency(agency);
Mockito.when(gtfsDao.getAllRoutes()).thenReturn(Arrays.asList(route));
AgencyAndId shapeId = new AgencyAndId("1", "shapeId");
Trip trip = new Trip();
trip.setId(new AgencyAndId("1", "tripA"));
trip.setRoute(route);
trip.setServiceId(new AgencyAndId("1", "serviceId"));
trip.setShapeId(shapeId);
Mockito.when(gtfsDao.getTripsForRoute(route)).thenReturn(Arrays.asList(trip));
Stop stopA = new Stop();
stopA.setId(aid("stopA"));
StopTime stA = new StopTime();
stA.setId(100);
stA.setArrivalTime(time(9, 00));
stA.setDepartureTime(time(9, 05));
stA.setStopSequence(100);
stA.setStop(stopA);
stA.setTrip(trip);
Stop stopB = new Stop();
stopB.setId(aid("stopB"));
StopTime stB = new StopTime();
stB.setId(101);
stB.setArrivalTime(time(10, 00));
stB.setDepartureTime(time(10, 05));
stB.setStopSequence(102);
stB.setStop(stopB);
stB.setTrip(trip);
Mockito.when(gtfsDao.getStopTimesForTrip(trip)).thenReturn(Arrays.asList(stA, stB));
TransitGraphImpl graph = new TransitGraphImpl();
graph.putStopEntry(stop("stopA", 47.672207391799056, -122.387855896286));
graph.putStopEntry(stop("stopB", 47.66852277218285, -122.3853882639923));
RouteEntryImpl routeEntry = route("routeA");
graph.putRouteEntry(routeEntry);
graph.initialize();
ShapePointsFactory shapePointsFactory = new ShapePointsFactory();
shapePointsFactory.addPoint(47.673840100841396, -122.38756621771239);
shapePointsFactory.addPoint(47.668667271970484, -122.38756621771239);
shapePointsFactory.addPoint(47.66868172192725, -122.3661729186096);
ShapePoints shapePoints = shapePointsFactory.create();
ShapePointHelper shapePointHelper = Mockito.mock(ShapePointHelper.class);
Mockito.when(shapePointHelper.getShapePointsForShapeId(shapeId)).thenReturn(shapePoints);
TripEntriesFactory factory = new TripEntriesFactory();
factory.setGtfsDao(gtfsDao);
factory.setShapePointHelper(shapePointHelper);
factory.setUniqueService(new UniqueServiceImpl());
StopTimeEntriesFactory stopTimeEntriesFactory = new StopTimeEntriesFactory();
stopTimeEntriesFactory.setDistanceAlongShapeLibrary(new DistanceAlongShapeLibrary());
factory.setStopTimeEntriesFactory(stopTimeEntriesFactory);
factory.processTrips(graph);
TripEntryImpl entry = graph.getTripEntryForId(trip.getId());
assertEquals(trip.getId(), entry.getId());
assertEquals(route.getId(), entry.getRoute().getId());
assertEquals(lsid("serviceId"), entry.getServiceId());
assertEquals(trip.getShapeId(), entry.getShapeId());
assertEquals(2177.1, entry.getTotalTripDistance(), 0.1);
List<StopTimeEntry> stopTimes = entry.getStopTimes();
assertEquals(2, stopTimes.size());
for (StopTimeEntry stopTime : stopTimes) {
assertSame(entry, stopTime.getTrip());
}
}
use of org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry in project onebusaway-application-modules by camsys.
the class ScheduledServiceServiceImpl method stopHasRevenueServiceOnRoute.
@Override
public Boolean stopHasRevenueServiceOnRoute(String agencyId, String stopId, String routeId, String directionId) {
AgencyAndId stopAndId = null;
if (stopId != null && stopId.contains("_"))
stopAndId = AgencyAndIdLibrary.convertFromString(stopId);
else if (stopId != null)
stopAndId = new AgencyAndId(agencyId, stopId);
StopEntry stopEntry = _transitGraphDao.getStopEntryForId(stopAndId);
List<BlockStopTimeIndex> stopTimeIndicesForStop = _blockIndexService.getStopTimeIndicesForStop(stopEntry);
for (BlockStopTimeIndex bsti : stopTimeIndicesForStop) {
List<BlockStopTimeEntry> stopTimes = bsti.getStopTimes();
for (BlockStopTimeEntry bste : stopTimes) {
StopTimeEntry stopTime = bste.getStopTime();
TripEntry theTrip = stopTime.getTrip();
if (routeId != null && !theTrip.getRoute().getId().toString().equals(routeId)) {
continue;
}
if (directionId != null && theTrip.getDirectionId() != null) {
if (!theTrip.getDirectionId().equals(directionId)) {
continue;
}
}
/*
* If at least one stoptime on one trip (subject to the
* route and direction filters above) permits unrestricted
* pick-up or drop-off at this stop (type=0), then it is
* considered a 'revenue' stop.
*/
if (stopTime.getDropOffType() == 0 || stopTime.getPickupType() == 0) {
return true;
}
}
}
return false;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry in project onebusaway-application-modules by camsys.
the class BlockConfigurationEntryImpl method getStopTimeForIndex.
/**
***
* Private Methods
***
*/
private StopTimeEntry getStopTimeForIndex(int index) {
int tripIndex = tripIndices[index];
BlockTripEntry blockTrip = trips.get(tripIndex);
TripEntry trip = blockTrip.getTrip();
List<StopTimeEntry> stopTimes = trip.getStopTimes();
int stopTimeIndex = index - accumulatedStopTimeIndices[tripIndex];
StopTimeEntry stopTime = stopTimes.get(stopTimeIndex);
return stopTime;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry in project onebusaway-application-modules by camsys.
the class RealTimeHistoryServiceImpl method getScheduleDeviationHistogramForArrivalAndDepartureInstance.
@Override
public ScheduleDeviationHistogram getScheduleDeviationHistogramForArrivalAndDepartureInstance(ArrivalAndDepartureInstance instance, int stepSizeInSeconds) {
BlockTripEntry blockTrip = instance.getBlockTrip();
TripEntry trip = blockTrip.getTrip();
AgencyAndId tripId = trip.getId();
ScheduleDeviationHistory history = _scheduleDeviationHistoryDao.getScheduleDeviationHistoryForTripId(tripId);
if (history == null)
return null;
BlockStopTimeEntry blockStopTime = instance.getBlockStopTime();
StopTimeEntry stopTime = blockStopTime.getStopTime();
double[] values = getScheduleDeviationsForScheduleTime(history, stopTime.getDepartureTime());
return createHistogramFromValues(values, stepSizeInSeconds);
}
Aggregations