use of org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry in project onebusaway-application-modules by camsys.
the class BlockConfigurationEntriesFactoryTest method test.
@Test
public void test() {
StopEntryImpl stopA = stop("stopA", 47.0, -122.0);
StopEntryImpl stopB = stop("stopB", 47.1, -122.1);
TripEntryImpl tripA = trip("tripA", "sA", 300.0);
StopTimeEntryImpl st0 = stopTime(0, stopA, tripA, time(9, 00), time(9, 05), 100.0);
StopTimeEntryImpl st1 = stopTime(1, stopB, tripA, time(9, 30), time(9, 35), 200.0);
TripEntryImpl tripB = trip("tripB", "sA", 300.0);
StopTimeEntryImpl st2 = stopTime(2, stopA, tripB, time(10, 00), time(10, 05), 100.0);
StopTimeEntryImpl st3 = stopTime(3, stopB, tripB, time(10, 30), time(10, 35), 200.0);
TripEntryImpl tripC = trip("tripC", "sB", 300.0);
StopTimeEntryImpl st4 = stopTime(4, stopA, tripC, time(11, 00), time(11, 05), 100.0);
StopTimeEntryImpl st5 = stopTime(5, stopB, tripC, time(11, 30), time(11, 35), 200.0);
TripEntryImpl tripD = trip("tripD", "sB", 300.0);
StopTimeEntryImpl st6 = stopTime(6, stopA, tripD, time(12, 00), time(12, 05), 100.0);
StopTimeEntryImpl st7 = stopTime(7, stopB, tripD, time(12, 30), time(12, 35), 200.0);
/**
**
* Actual Test
***
*/
BlockEntryImpl block = new BlockEntryImpl();
List<TripEntryImpl> tripsInBlock = Arrays.asList(tripA, tripB, tripC, tripD);
_factory.processBlockConfigurations(block, tripsInBlock);
List<BlockConfigurationEntry> configurations = block.getConfigurations();
assertEquals(3, configurations.size());
/**
**
* Order of the configurations matter. See
* {@link BlockEntry#getConfigurations()} for details.
***
*/
/**
**
* Configuration A & B
***
*/
BlockConfigurationEntry entry = configurations.get(0);
assertSame(block, entry.getBlock());
assertEquals(serviceIds(lsids("sA", "sB"), lsids()), entry.getServiceIds());
assertEquals(1200.0, entry.getTotalBlockDistance(), 0.0);
assertNull(entry.getFrequencies());
List<BlockTripEntry> trips = entry.getTrips();
assertEquals(4, trips.size());
BlockTripEntry trip = trips.get(0);
assertEquals(0, trip.getAccumulatedStopTimeIndex());
assertEquals(0, trip.getAccumulatedSlackTime());
assertEquals(0.0, trip.getDistanceAlongBlock(), 0.0);
assertSame(tripA, trip.getTrip());
assertNull(trip.getPreviousTrip());
assertSame(trips.get(1), trip.getNextTrip());
trip = trips.get(1);
assertEquals(2, trip.getAccumulatedStopTimeIndex());
assertEquals(10 * 60, trip.getAccumulatedSlackTime());
assertEquals(300.0, trip.getDistanceAlongBlock(), 0.0);
assertSame(tripB, trip.getTrip());
assertSame(trips.get(0), trip.getPreviousTrip());
assertSame(trips.get(2), trip.getNextTrip());
trip = trips.get(2);
assertEquals(4, trip.getAccumulatedStopTimeIndex());
assertEquals(20 * 60, trip.getAccumulatedSlackTime());
assertEquals(600.0, trip.getDistanceAlongBlock(), 0.0);
assertSame(tripC, trip.getTrip());
assertSame(trips.get(1), trip.getPreviousTrip());
assertSame(trips.get(3), trip.getNextTrip());
trip = trips.get(3);
assertEquals(6, trip.getAccumulatedStopTimeIndex());
assertEquals(30 * 60, trip.getAccumulatedSlackTime());
assertEquals(900.0, trip.getDistanceAlongBlock(), 0.0);
assertSame(tripD, trip.getTrip());
assertSame(trips.get(2), trip.getPreviousTrip());
assertNull(trip.getNextTrip());
List<BlockStopTimeEntry> stopTimes = entry.getStopTimes();
assertEquals(8, stopTimes.size());
BlockStopTimeEntry bst = stopTimes.get(0);
assertEquals(0, bst.getAccumulatedSlackTime());
assertEquals(0, bst.getBlockSequence());
assertEquals(100.0, bst.getDistanceAlongBlock(), 0.0);
assertSame(st0, bst.getStopTime());
assertSame(trips.get(0), bst.getTrip());
bst = stopTimes.get(1);
assertEquals(5 * 60, bst.getAccumulatedSlackTime());
assertEquals(1, bst.getBlockSequence());
assertEquals(200.0, bst.getDistanceAlongBlock(), 0.0);
assertSame(st1, bst.getStopTime());
assertSame(trips.get(0), bst.getTrip());
bst = stopTimes.get(2);
assertEquals(10 * 60, bst.getAccumulatedSlackTime());
assertEquals(2, bst.getBlockSequence());
assertEquals(400.0, bst.getDistanceAlongBlock(), 0.0);
assertSame(st2, bst.getStopTime());
assertSame(trips.get(1), bst.getTrip());
bst = stopTimes.get(3);
assertEquals(15 * 60, bst.getAccumulatedSlackTime());
assertEquals(3, bst.getBlockSequence());
assertEquals(500.0, bst.getDistanceAlongBlock(), 0.0);
assertSame(st3, bst.getStopTime());
assertSame(trips.get(1), bst.getTrip());
bst = stopTimes.get(4);
assertEquals(20 * 60, bst.getAccumulatedSlackTime());
assertEquals(4, bst.getBlockSequence());
assertEquals(700.0, bst.getDistanceAlongBlock(), 0.0);
assertSame(st4, bst.getStopTime());
assertSame(trips.get(2), bst.getTrip());
bst = stopTimes.get(5);
assertEquals(25 * 60, bst.getAccumulatedSlackTime());
assertEquals(5, bst.getBlockSequence());
assertEquals(800.0, bst.getDistanceAlongBlock(), 0.0);
assertSame(st5, bst.getStopTime());
assertSame(trips.get(2), bst.getTrip());
bst = stopTimes.get(6);
assertEquals(30 * 60, bst.getAccumulatedSlackTime());
assertEquals(6, bst.getBlockSequence());
assertEquals(1000.0, bst.getDistanceAlongBlock(), 0.0);
assertSame(st6, bst.getStopTime());
assertSame(trips.get(3), bst.getTrip());
bst = stopTimes.get(7);
assertEquals(35 * 60, bst.getAccumulatedSlackTime());
assertEquals(7, bst.getBlockSequence());
assertEquals(1100.0, bst.getDistanceAlongBlock(), 0.0);
assertSame(st7, bst.getStopTime());
assertSame(trips.get(3), bst.getTrip());
/**
**
* Configuration A
***
*/
entry = configurations.get(1);
assertSame(block, entry.getBlock());
assertEquals(serviceIds(lsids("sA"), lsids("sB")), entry.getServiceIds());
assertEquals(600.0, entry.getTotalBlockDistance(), 0.0);
assertNull(entry.getFrequencies());
trips = entry.getTrips();
assertEquals(2, trips.size());
trip = trips.get(0);
assertEquals(0, trip.getAccumulatedStopTimeIndex());
assertEquals(0, trip.getAccumulatedSlackTime());
assertEquals(0.0, trip.getDistanceAlongBlock(), 0.0);
assertSame(tripA, trip.getTrip());
assertNull(trip.getPreviousTrip());
assertSame(trips.get(1), trip.getNextTrip());
trip = trips.get(1);
assertEquals(2, trip.getAccumulatedStopTimeIndex());
assertEquals(10 * 60, trip.getAccumulatedSlackTime());
assertEquals(300.0, trip.getDistanceAlongBlock(), 0.0);
assertSame(tripB, trip.getTrip());
assertSame(trips.get(0), trip.getPreviousTrip());
assertNull(trip.getNextTrip());
stopTimes = entry.getStopTimes();
assertEquals(4, stopTimes.size());
bst = stopTimes.get(0);
assertEquals(0, bst.getAccumulatedSlackTime());
assertEquals(0, bst.getBlockSequence());
assertEquals(100.0, bst.getDistanceAlongBlock(), 0.0);
assertSame(st0, bst.getStopTime());
assertSame(trips.get(0), bst.getTrip());
bst = stopTimes.get(1);
assertEquals(5 * 60, bst.getAccumulatedSlackTime());
assertEquals(1, bst.getBlockSequence());
assertEquals(200.0, bst.getDistanceAlongBlock(), 0.0);
assertSame(st1, bst.getStopTime());
assertSame(trips.get(0), bst.getTrip());
bst = stopTimes.get(2);
assertEquals(10 * 60, bst.getAccumulatedSlackTime());
assertEquals(2, bst.getBlockSequence());
assertEquals(400.0, bst.getDistanceAlongBlock(), 0.0);
assertSame(st2, bst.getStopTime());
assertSame(trips.get(1), bst.getTrip());
bst = stopTimes.get(3);
assertEquals(15 * 60, bst.getAccumulatedSlackTime());
assertEquals(3, bst.getBlockSequence());
assertEquals(500.0, bst.getDistanceAlongBlock(), 0.0);
assertSame(st3, bst.getStopTime());
assertSame(trips.get(1), bst.getTrip());
/**
**
* Configuration B
***
*/
entry = configurations.get(2);
assertSame(block, entry.getBlock());
assertEquals(serviceIds(lsids("sB"), lsids("sA")), entry.getServiceIds());
assertEquals(600.0, entry.getTotalBlockDistance(), 0.0);
assertNull(entry.getFrequencies());
trips = entry.getTrips();
assertEquals(2, trips.size());
trip = trips.get(0);
assertEquals(0, trip.getAccumulatedStopTimeIndex());
assertEquals(0, trip.getAccumulatedSlackTime());
assertEquals(0.0, trip.getDistanceAlongBlock(), 0.0);
assertSame(tripC, trip.getTrip());
assertNull(trip.getPreviousTrip());
assertSame(trips.get(1), trip.getNextTrip());
trip = trips.get(1);
assertEquals(2, trip.getAccumulatedStopTimeIndex());
assertEquals(10 * 60, trip.getAccumulatedSlackTime());
assertEquals(300.0, trip.getDistanceAlongBlock(), 0.0);
assertSame(tripD, trip.getTrip());
assertSame(trips.get(0), trip.getPreviousTrip());
assertNull(trip.getNextTrip());
stopTimes = entry.getStopTimes();
assertEquals(4, stopTimes.size());
bst = stopTimes.get(0);
assertEquals(0, bst.getAccumulatedSlackTime());
assertEquals(0, bst.getBlockSequence());
assertEquals(100.0, bst.getDistanceAlongBlock(), 0.0);
assertSame(st4, bst.getStopTime());
assertSame(trips.get(0), bst.getTrip());
bst = stopTimes.get(1);
assertEquals(5 * 60, bst.getAccumulatedSlackTime());
assertEquals(1, bst.getBlockSequence());
assertEquals(200.0, bst.getDistanceAlongBlock(), 0.0);
assertSame(st5, bst.getStopTime());
assertSame(trips.get(0), bst.getTrip());
bst = stopTimes.get(2);
assertEquals(10 * 60, bst.getAccumulatedSlackTime());
assertEquals(2, bst.getBlockSequence());
assertEquals(400.0, bst.getDistanceAlongBlock(), 0.0);
assertSame(st6, bst.getStopTime());
assertSame(trips.get(1), bst.getTrip());
bst = stopTimes.get(3);
assertEquals(15 * 60, bst.getAccumulatedSlackTime());
assertEquals(3, bst.getBlockSequence());
assertEquals(500.0, bst.getDistanceAlongBlock(), 0.0);
assertSame(st7, bst.getStopTime());
assertSame(trips.get(1), bst.getTrip());
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry 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.BlockConfigurationEntry in project onebusaway-application-modules by camsys.
the class StopTimeServiceImplTest method test01.
@Test
public void test01() {
Date from = date("2009-09-01 10:00");
Date to = date("2009-09-01 10:30");
Date day = getTimeAsDay(from);
StopTimeEntryImpl stA = stopTime(0, _stop, trip("A", "sA"), time(9, 50), 0);
StopTimeEntryImpl stB = stopTime(1, _stop, trip("B", "sA"), time(10, 10), 0);
StopTimeEntryImpl stC = stopTime(2, _stop, trip("C", "sA"), time(10, 20), 0);
StopTimeEntryImpl stD = stopTime(3, _stop, trip("D", "sA"), time(10, 40), 0);
BlockConfigurationEntry bA = linkBlockTrips("bA", stA.getTrip());
BlockConfigurationEntry bB = linkBlockTrips("bB", stB.getTrip());
BlockConfigurationEntry bC = linkBlockTrips("bC", stC.getTrip());
BlockConfigurationEntry bD = linkBlockTrips("bD", stD.getTrip());
addFirstStopToBlockIndex(bA, bB, bC, bD);
List<StopTimeInstance> results = _service.getStopTimeInstancesInTimeRange(_stopId, from, to);
sort(results);
assertEquals(2, results.size());
StopTimeInstance sti = results.get(0);
assertEquals(day.getTime(), sti.getServiceDate());
assertEquals(dateAsLong("2009-09-01 10:10"), sti.getArrivalTime());
assertEquals(dateAsLong("2009-09-01 10:10"), sti.getDepartureTime());
sti = results.get(1);
assertEquals(day.getTime(), sti.getServiceDate());
assertEquals(date("2009-09-01 10:20").getTime(), sti.getArrivalTime());
assertEquals(date("2009-09-01 10:20").getTime(), sti.getDepartureTime());
from = date("2009-09-01 10:15");
to = date("2009-09-01 10:25");
results = _service.getStopTimeInstancesInTimeRange(_stopId, from, to);
sort(results);
assertEquals(1, results.size());
sti = results.get(0);
assertEquals(day.getTime(), sti.getServiceDate());
assertEquals(date("2009-09-01 10:20").getTime(), sti.getArrivalTime());
assertEquals(date("2009-09-01 10:20").getTime(), sti.getDepartureTime());
from = date("2009-09-01 10:21");
to = date("2009-09-01 10:25");
results = _service.getStopTimeInstancesInTimeRange(_stopId, from, to);
assertEquals(0, results.size());
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry 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.BlockConfigurationEntry in project onebusaway-application-modules by camsys.
the class BlockStopTimeIndicesFactoryTest method testFrequencies.
@Test
public void testFrequencies() {
StopEntryImpl stopA = stop("a", 47.0, -122.0);
StopEntryImpl stopB = stop("b", 47.1, -122.1);
/**
**
* Block A
***
*/
BlockEntryImpl blockA = block("a");
TripEntryImpl tripA = trip("a", "s1");
stopTime(0, stopA, tripA, 0, 10, 0);
stopTime(0, stopB, tripA, 20, 20, 0);
FrequencyEntry freqA1 = frequency(time(6, 00), time(9, 00), 10, 0);
FrequencyEntry freqA2 = frequency(time(15, 00), time(18, 00), 10, 0);
List<FrequencyEntry> freqsA = Arrays.asList(freqA1, freqA2);
BlockConfigurationEntry bcA = linkBlockTrips(blockA, freqsA, tripA);
/**
**
* Block B
***
*/
BlockEntryImpl blockB = block("b");
TripEntryImpl tripB = trip("b", "s1");
stopTime(0, stopA, tripB, 20, 30, 0);
stopTime(0, stopB, tripB, 50, 50, 0);
FrequencyEntry freqB1 = frequency(time(9, 00), time(15, 00), 20, 0);
FrequencyEntry freqB2 = frequency(time(18, 00), time(21, 00), 20, 0);
List<FrequencyEntry> freqsB = Arrays.asList(freqB1, freqB2);
BlockConfigurationEntry bcB = linkBlockTrips(blockB, freqsB, tripB);
BlockStopTimeIndicesFactory factory = new BlockStopTimeIndicesFactory();
List<FrequencyBlockStopTimeIndex> allIndices = factory.createFrequencyIndices(Arrays.asList((BlockEntry) blockB, blockA));
assertEquals(2, allIndices.size());
List<FrequencyBlockStopTimeIndex> indices = grep(allIndices, aid("a"), serviceIds(lsids("s1"), lsids()));
assertEquals(1, indices.size());
FrequencyBlockStopTimeIndex index = indices.get(0);
assertEquals(freqA1, index.getFrequencies().get(0));
assertEquals(freqB1, index.getFrequencies().get(1));
assertEquals(freqA2, index.getFrequencies().get(2));
assertEquals(freqB2, index.getFrequencies().get(3));
assertEquals(bcA, index.getBlockConfigs().get(0));
assertEquals(bcB, index.getBlockConfigs().get(1));
assertEquals(bcA, index.getBlockConfigs().get(2));
assertEquals(bcB, index.getBlockConfigs().get(3));
}
Aggregations