use of org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry 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.BlockStopTimeEntry 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);
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry in project onebusaway-application-modules by camsys.
the class ArrivalAndDepartureServiceImplTest method getArrivalsAndDeparturesForLoopRouteInTimeRangeByTimepointPredictionRecord.
/**
* Set up the BlockLocationServiceImpl for the test, using the given
* timepointPredictions
*
* This method creates a loop route with a single trip and two stops in a block
* Stop A is visited twice in the route
*
* stop_id trip_id stop_sequence
* A 1 0
* B 1 1
* A 1 2
*
* @param timepointPredictions real-time predictions to apply to the
* BlockLocationServiceImpl
* @param stop stop_id for this stop is used to call getArrivalsAndDeparturesForStopInTimeRange()
* @return a list of ArrivalAndDepartureInstances which is used to access
* predicted arrival/departure times for a stop, for comparison
* against the expected values
*/
private List<ArrivalAndDepartureInstance> getArrivalsAndDeparturesForLoopRouteInTimeRangeByTimepointPredictionRecord(List<TimepointPredictionRecord> timepointPredictions, StopEntryImpl stop) {
TargetTime target = new TargetTime(mCurrentTime, mCurrentTime);
// Setup block
BlockEntryImpl block = block("blockA");
stopTime(0, mStopA, mTrip1, time(13, 30), time(13, 35), 1000);
stopTime(1, mStopB, mTrip1, time(13, 45), time(13, 50), 2000);
stopTime(2, mStopA, mTrip1, time(13, 55), time(13, 55), 2000);
BlockConfigurationEntry blockConfig = blockConfiguration(block, serviceIds(lsids("sA"), lsids()), mTrip1);
BlockStopTimeEntry bstAA = blockConfig.getStopTimes().get(0);
BlockStopTimeEntry bstAB = blockConfig.getStopTimes().get(1);
BlockStopTimeEntry bstBA = blockConfig.getStopTimes().get(2);
// Setup block location instance for trip B
BlockInstance blockInstance = new BlockInstance(blockConfig, mServiceDate);
BlockLocation blockLocationB = new BlockLocation();
blockLocationB.setActiveTrip(bstBA.getTrip());
blockLocationB.setBlockInstance(blockInstance);
blockLocationB.setClosestStop(bstBA);
blockLocationB.setDistanceAlongBlock(400);
blockLocationB.setInService(true);
blockLocationB.setNextStop(bstAA);
blockLocationB.setPredicted(false);
blockLocationB.setScheduledDistanceAlongBlock(400);
blockLocationB.setTimepointPredictions(timepointPredictions);
// Mock StopTimeInstance with time frame
long stopTimeFrom = dateAsLong("2015-07-23 00:00");
long stopTimeTo = dateAsLong("2015-07-24 00:00");
StopTimeInstance sti1 = new StopTimeInstance(bstAA, blockInstance.getState());
ArrivalAndDepartureInstance in1 = new ArrivalAndDepartureInstance(sti1);
in1.setBlockLocation(blockLocationB);
in1.setPredictedArrivalTime((long) (in1.getScheduledArrivalTime()));
in1.setPredictedDepartureTime((long) (in1.getScheduledDepartureTime()));
StopTimeInstance sti2 = new StopTimeInstance(bstAB, blockInstance.getState());
ArrivalAndDepartureInstance in2 = new ArrivalAndDepartureInstance(sti2);
in2.setBlockLocation(blockLocationB);
StopTimeInstance sti3 = new StopTimeInstance(bstBA, blockInstance.getState());
ArrivalAndDepartureInstance in3 = new ArrivalAndDepartureInstance(sti3);
in3.setBlockLocation(blockLocationB);
in3.setPredictedArrivalTime((long) (in3.getScheduledArrivalTime()));
in3.setPredictedDepartureTime((long) (in3.getScheduledDepartureTime()));
Date fromTimeBuffered = new Date(stopTimeFrom - _blockStatusService.getRunningLateWindow() * 1000);
Date toTimeBuffered = new Date(stopTimeTo + _blockStatusService.getRunningEarlyWindow() * 1000);
Mockito.when(_stopTimeService.getStopTimeInstancesInTimeRange(stop, fromTimeBuffered, toTimeBuffered, EFrequencyStopTimeBehavior.INCLUDE_UNSPECIFIED)).thenReturn(Arrays.asList(sti1, sti2, sti3));
// Create and add vehicle location record cache
VehicleLocationRecordCacheImpl _cache = new VehicleLocationRecordCacheImpl();
VehicleLocationRecord vlr = new VehicleLocationRecord();
vlr.setBlockId(blockLocationB.getBlockInstance().getBlock().getBlock().getId());
vlr.setTripId(mTrip1.getId());
vlr.setTimepointPredictions(blockLocationB.getTimepointPredictions());
vlr.setTimeOfRecord(mCurrentTime);
vlr.setVehicleId(new AgencyAndId("1", "123"));
// Create ScheduledBlockLocation for cache
ScheduledBlockLocation sbl = new ScheduledBlockLocation();
sbl.setActiveTrip(blockLocationB.getActiveTrip());
// Add data to cache
_cache.addRecord(blockInstance, vlr, sbl, null);
_blockLocationService.setVehicleLocationRecordCache(_cache);
ScheduledBlockLocationServiceImpl scheduledBlockLocationServiceImpl = new ScheduledBlockLocationServiceImpl();
_blockLocationService.setScheduledBlockLocationService(scheduledBlockLocationServiceImpl);
// Call ArrivalAndDepartureService
return _service.getArrivalsAndDeparturesForStopInTimeRange(stop, target, stopTimeFrom, stopTimeTo);
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry in project onebusaway-application-modules by camsys.
the class ArrivalsAndDeparturesBeanServiceImplTest method test.
@Test
public void test() {
long t = dateAsLong("2010-10-05 16:30");
long serviceDate = dateAsLong("2010-10-05 00:00");
int minutesBefore = 5;
int minutesAfter = 30;
StopEntryImpl stopA = stop("stopA", 47.0, -122.0);
StopEntryImpl stopB = stop("stopB", 47.0, -122.0);
Mockito.when(_transitGraphDao.getStopEntryForId(stopA.getId(), true)).thenReturn(stopA);
Mockito.when(_transitGraphDao.getStopEntryForId(stopB.getId(), true)).thenReturn(stopB);
/**
**
* Block A
***
*/
BlockEntryImpl blockA = block("blockA");
TripEntryImpl tripA = trip("tripA", "sA", 3000);
stopTime(0, stopA, tripA, time(16, 30), time(16, 35), 1000);
StopTimeEntryImpl stopTimeAB = stopTime(1, stopB, tripA, time(16, 40), time(16, 45), 2000);
BlockConfigurationEntry blockConfigA = blockConfiguration(blockA, serviceIds(lsids("sA"), lsids()), tripA);
BlockStopTimeEntry bstAA = blockConfigA.getStopTimes().get(0);
BlockStopTimeEntry bstAB = blockConfigA.getStopTimes().get(1);
/**
**
* Block B
***
*/
BlockEntryImpl blockB = block("blockB");
TripEntryImpl tripB = trip("tripB", "sA", 3000);
stopTime(2, stopA, tripB, time(16, 40), time(16, 45), 1000);
StopTimeEntryImpl stopTimeBB = stopTime(3, stopB, tripB, time(16, 50), time(16, 55), 2000);
BlockConfigurationEntry blockConfigB = blockConfiguration(blockB, serviceIds(lsids("sA"), lsids()), tripB);
BlockStopTimeEntry bstBA = blockConfigB.getStopTimes().get(0);
BlockStopTimeEntry bstBB = blockConfigB.getStopTimes().get(1);
/**
**
*
***
*/
BlockInstance blockInstanceA = new BlockInstance(blockConfigA, serviceDate);
long lastUpdateTime = dateAsLong("2010-10-05 16:15");
BlockLocation blockLocationA = new BlockLocation();
blockLocationA.setActiveTrip(bstAA.getTrip());
blockLocationA.setBlockInstance(blockInstanceA);
blockLocationA.setClosestStop(bstAA);
blockLocationA.setDistanceAlongBlock(500);
blockLocationA.setInService(true);
blockLocationA.setLastUpdateTime(lastUpdateTime);
blockLocationA.setNextStop(bstAA);
blockLocationA.setPredicted(true);
blockLocationA.setScheduledDistanceAlongBlock(600);
blockLocationA.setScheduleDeviation(10 * 60);
blockLocationA.setVehicleId(aid("vehicle"));
/**
**
*
***
*/
BlockInstance blockInstanceB = new BlockInstance(blockConfigB, serviceDate);
BlockLocation blockLocationB = new BlockLocation();
blockLocationB.setActiveTrip(bstBA.getTrip());
blockLocationB.setBlockInstance(blockInstanceA);
blockLocationB.setClosestStop(bstBA);
blockLocationB.setDistanceAlongBlock(400);
blockLocationB.setInService(true);
blockLocationB.setNextStop(bstAA);
blockLocationB.setPredicted(false);
blockLocationB.setScheduledDistanceAlongBlock(400);
/**
**
*
***
*/
long stopTimeFrom = t - minutesBefore * 60 * 1000;
long stopTimeTo = t + minutesAfter * 60 * 1000;
StopTimeInstance sti1 = new StopTimeInstance(bstAB, blockInstanceA.getState());
ArrivalAndDepartureInstance in1 = new ArrivalAndDepartureInstance(sti1);
in1.setBlockLocation(blockLocationA);
in1.setPredictedArrivalTime((long) (in1.getScheduledArrivalTime() + 5 * 60 * 1000));
in1.setPredictedDepartureTime((long) (in1.getScheduledDepartureTime()));
StopTimeInstance sti2 = new StopTimeInstance(bstBB, blockInstanceB.getState());
ArrivalAndDepartureInstance in2 = new ArrivalAndDepartureInstance(sti2);
in2.setBlockLocation(blockLocationB);
TargetTime target = new TargetTime(t, t);
Mockito.when(_arrivalAndDepartureService.getArrivalsAndDeparturesForStopInTimeRange(stopB, target, stopTimeFrom, stopTimeTo)).thenReturn(Arrays.asList(in1, in2));
/**
**
*
***
*/
Builder stopTimeNarrative = StopTimeNarrative.builder();
stopTimeNarrative.setStopHeadsign("Downtown");
Mockito.when(_narrativeService.getStopTimeForEntry(stopTimeAB)).thenReturn(stopTimeNarrative.create());
stopTimeNarrative = StopTimeNarrative.builder();
stopTimeNarrative.setRouteShortName("XX");
Mockito.when(_narrativeService.getStopTimeForEntry(stopTimeBB)).thenReturn(stopTimeNarrative.create());
/**
**
*
***
*/
StopBean stopABean = new StopBean();
stopABean.setId("1_stopA");
Mockito.when(_stopBeanService.getStopForId(stopA.getId())).thenReturn(stopABean);
StopBean stopBBean = new StopBean();
stopBBean.setId("1_stopB");
Mockito.when(_stopBeanService.getStopForId(stopB.getId())).thenReturn(stopBBean);
/**
**
*
***
*/
TripBean tripABean = new TripBean();
Mockito.when(_tripBeanService.getTripForId(aid("tripA"))).thenReturn(tripABean);
TripBean tripBBean = new TripBean();
Mockito.when(_tripBeanService.getTripForId(aid("tripB"))).thenReturn(tripBBean);
/**
**
*
***
*/
TripStatusBean tripStatusBeanA = new TripStatusBean();
TripStatusBean tripStatusBeanB = new TripStatusBean();
Mockito.when(_tripDetailsBeanService.getBlockLocationAsStatusBean(blockLocationA, t)).thenReturn(tripStatusBeanA);
Mockito.when(_tripDetailsBeanService.getBlockLocationAsStatusBean(blockLocationB, t)).thenReturn(tripStatusBeanB);
/**
**
*
***
*/
ArrivalsAndDeparturesQueryBean query = new ArrivalsAndDeparturesQueryBean();
query.setTime(t);
query.setMinutesBefore(minutesBefore);
query.setMinutesAfter(minutesAfter);
query.setFrequencyMinutesBefore(minutesBefore);
query.setFrequencyMinutesAfter(minutesAfter);
List<ArrivalAndDepartureBean> arrivalsAndDepartures = _service.getArrivalsAndDeparturesByStopId(stopB.getId(), query);
assertEquals(2, arrivalsAndDepartures.size());
ArrivalAndDepartureBean bean = arrivalsAndDepartures.get(0);
assertEquals(1500, bean.getDistanceFromStop(), 0.0);
assertEquals(lastUpdateTime, bean.getLastUpdateTime().longValue());
assertEquals(1, bean.getNumberOfStopsAway());
assertEquals(dateAsLong("2010-10-05 16:45"), bean.getPredictedArrivalTime());
assertEquals(dateAsLong("2010-10-05 16:45"), bean.getPredictedDepartureTime());
assertNull(bean.getRouteShortName());
assertEquals(dateAsLong("2010-10-05 16:40"), bean.getScheduledArrivalTime());
assertEquals(dateAsLong("2010-10-05 16:45"), bean.getScheduledDepartureTime());
assertEquals(serviceDate, bean.getServiceDate());
assertEquals("default", bean.getStatus());
assertSame(stopBBean, bean.getStop());
assertSame(tripABean, bean.getTrip());
assertSame(tripStatusBeanA, bean.getTripStatus());
assertEquals("Downtown", bean.getTripHeadsign());
assertEquals("1_vehicle", bean.getVehicleId());
bean = arrivalsAndDepartures.get(1);
assertEquals(1600, bean.getDistanceFromStop(), 0.0);
assertNull(bean.getLastUpdateTime());
assertEquals(1, bean.getNumberOfStopsAway());
assertEquals(0L, bean.getPredictedArrivalTime());
assertEquals(0L, bean.getPredictedDepartureTime());
assertEquals("XX", bean.getRouteShortName());
assertEquals(dateAsLong("2010-10-05 16:50"), bean.getScheduledArrivalTime());
assertEquals(dateAsLong("2010-10-05 16:55"), bean.getScheduledDepartureTime());
assertEquals(serviceDate, bean.getServiceDate());
assertEquals("default", bean.getStatus());
assertSame(stopBBean, bean.getStop());
assertSame(tripBBean, bean.getTrip());
assertSame(tripStatusBeanB, bean.getTripStatus());
assertNull(bean.getTripHeadsign());
assertNull(bean.getVehicleId());
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry in project onebusaway-application-modules by camsys.
the class ScheduledBlockLocationServiceImplTest method before.
@Before
public void before() {
_service = new ScheduledBlockLocationServiceImpl();
_shapePointService = Mockito.mock(ShapePointService.class);
_service.setShapePointService(_shapePointService);
TripEntryImpl tripA = trip("A", "serviceId", 1000.0);
TripEntryImpl tripB = trip("B", "serviceId", 1000.0);
tripA.setShapeId(aid("shapeA"));
tripB.setShapeId(aid("shapeB"));
ShapePointsFactory m = new ShapePointsFactory();
m.setShapeId(aid("shapeA"));
m.addPoint(47.670170374084805, -122.3875880241394);
m.addPoint(47.66871094987642, -122.38756656646729);
m.addPoint(47.66862425012441, -122.38610744476318);
m.addPoint(47.66869649992775, -122.38439083099365);
m.addPoint(47.664852671516094, -122.3800778388977);
m.addPoint(47.664467962697906, -122.37945087847474);
Mockito.when(_shapePointService.getShapePointsForShapeId(aid("shapeA"))).thenReturn(m.create());
m = new ShapePointsFactory();
m.setShapeId(aid("shapeB"));
m.addPoint(47.664467962697906, -122.37945087847474);
m.addPoint(47.663667674849385, -122.37814664840698);
m.addPoint(47.663667674849385, -122.37355470657349);
Mockito.when(_shapePointService.getShapePointsForShapeId(aid("shapeB"))).thenReturn(m.create());
_stopA = stop("stopA", 47.66868114116101, -122.3870648978625);
_stopB = stop("stopB", 47.66583195331816, -122.38117664826683);
_stopC = stop("stopC", 47.663667674849385, -122.37724035677341);
stopTime(1, _stopA, tripA, time(10, 00), time(10, 00), 200, 1);
stopTime(2, _stopB, tripA, time(10, 10), time(10, 15), 800, 3);
stopTime(3, _stopC, tripB, time(10, 20), time(10, 20), 200, 1);
_blockConfig = linkBlockTrips("blockA", tripA, tripB);
List<BlockTripEntry> trips = _blockConfig.getTrips();
_tripA = trips.get(0);
_tripB = trips.get(1);
List<BlockStopTimeEntry> stopTimes = _blockConfig.getStopTimes();
_stopTimeA = stopTimes.get(0);
_stopTimeB = stopTimes.get(1);
_stopTimeC = stopTimes.get(2);
}
Aggregations