use of org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl in project onebusaway-application-modules by camsys.
the class GtfsRealtimeTripLibraryTest method testCreateVehicleLocationRecordForUpdate_NoStopTimeUpdates.
@Test
public void testCreateVehicleLocationRecordForUpdate_NoStopTimeUpdates() {
TripUpdate tripUpdate = TripUpdate.newBuilder().setTrip(TripDescriptor.newBuilder().setTripId("tripA")).setDelay(120).setTimestamp(123456789).build();
TripEntryImpl tripA = trip("tripA");
stopTime(0, stop("stopA", 0, 0), tripA, time(7, 30), 0.0);
BlockEntryImpl blockA = block("blockA");
BlockConfigurationEntry blockConfigA = blockConfiguration(blockA, serviceIds("s1"), tripA);
BlockInstance blockInstanceA = new BlockInstance(blockConfigA, 0L);
Mockito.when(_blockCalendarService.getActiveBlocks(Mockito.eq(blockA.getId()), Mockito.anyLong(), Mockito.anyLong())).thenReturn(Arrays.asList(blockInstanceA));
CombinedTripUpdatesAndVehiclePosition update = new CombinedTripUpdatesAndVehiclePosition();
update.block = new BlockDescriptor();
update.block.setBlockInstance(blockInstanceA);
update.tripUpdates = Arrays.asList(tripUpdate);
VehicleLocationRecord record = _library.createVehicleLocationRecordForUpdate(update);
assertEquals(123456789000L, record.getTimeOfRecord());
assertEquals(120, record.getScheduleDeviation(), 0.0);
}
use of org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl in project onebusaway-application-modules by camsys.
the class GtfsRealtimeTripLibraryTest method testCreateVehicleLocationRecordForUpdate_WithStopTimeUpdates.
@Test
public void testCreateVehicleLocationRecordForUpdate_WithStopTimeUpdates() {
StopTimeUpdate.Builder stopTimeUpdate = StopTimeUpdate.newBuilder();
stopTimeUpdate.setStopId("stopA");
StopTimeEvent.Builder stopTimeEvent = StopTimeEvent.newBuilder();
stopTimeEvent.setDelay(180);
stopTimeUpdate.setDeparture(stopTimeEvent);
TripUpdate tripUpdate = TripUpdate.newBuilder().setTrip(TripDescriptor.newBuilder().setTripId("tripA")).setDelay(120).setTimestamp(123456789).addStopTimeUpdate(stopTimeUpdate).build();
TripEntryImpl tripA = trip("tripA");
stopTime(0, stop("stopA", 0, 0), tripA, time(7, 30), 0.0);
BlockEntryImpl blockA = block("blockA");
BlockConfigurationEntry blockConfigA = blockConfiguration(blockA, serviceIds("s1"), tripA);
BlockInstance blockInstanceA = new BlockInstance(blockConfigA, 0L);
Mockito.when(_blockCalendarService.getActiveBlocks(Mockito.eq(blockA.getId()), Mockito.anyLong(), Mockito.anyLong())).thenReturn(Arrays.asList(blockInstanceA));
CombinedTripUpdatesAndVehiclePosition update = new CombinedTripUpdatesAndVehiclePosition();
update.block = new BlockDescriptor();
update.block.setBlockInstance(blockInstanceA);
update.tripUpdates = Arrays.asList(tripUpdate);
VehicleLocationRecord record = _library.createVehicleLocationRecordForUpdate(update);
TimepointPredictionRecord tpr = record.getTimepointPredictions().get(0);
long departure = tpr.getTimepointPredictedDepartureTime();
// 7:30 plus 3 min delay, + now we are in ms.
assertEquals(departure, time(7, 33) * 1000);
}
use of org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl in project onebusaway-application-modules by camsys.
the class GtfsRealtimeTripLibraryTest method testTprInterpolation_2.
/**
* Test that we do NOT create new timepoint prediction record when it
* already exists.
*
* Current time = 7:25. Trip update delay = 2 minutes
* Schedule time Real-time from feed Timepoint predicted departure time
* Stop A 7:30 7:33 7:33 (and only one)
*/
@Test
public void testTprInterpolation_2() {
_library.setCurrentTime(time(7, 25) * 1000);
TripEntryImpl tripA = trip("tripA");
stopTime(0, stop("stopA", 0, 0), tripA, time(7, 30), 0.0);
BlockEntryImpl blockA = block("blockA");
BlockConfigurationEntry blockConfigA = blockConfiguration(blockA, serviceIds("s1"), tripA);
BlockInstance blockInstanceA = new BlockInstance(blockConfigA, 0L);
StopTimeUpdate.Builder stopTimeUpdate = stopTimeUpdateWithDepartureDelay("stopA", 180);
TripUpdate.Builder tripUpdate = tripUpdate("tripA", _library.getCurrentTime() / 1000, 120, stopTimeUpdate);
Mockito.when(_entitySource.getTrip("tripA")).thenReturn(tripA);
Mockito.when(_blockCalendarService.getActiveBlocks(Mockito.eq(blockA.getId()), Mockito.anyLong(), Mockito.anyLong())).thenReturn(Arrays.asList(blockInstanceA));
VehicleLocationRecord record = vehicleLocationRecord(tripUpdate);
long stopADept = getPredictedDepartureTimeByStopId(record, "stopA");
assertEquals(stopADept, time(7, 33) * 1000);
assertEquals(record.getTimepointPredictions().size(), 1);
}
use of org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl in project onebusaway-application-modules by camsys.
the class UnitTestingSupport method blockConfiguration.
public static BlockConfigurationEntry blockConfiguration(BlockEntry block, ServiceIdActivation serviceIds, TripEntry... trips) {
Builder builder = BlockConfigurationEntryImpl.builder();
builder.setBlock(block);
builder.setServiceIds(serviceIds);
builder.setTrips(Arrays.asList(trips));
builder.setTripGapDistances(new double[trips.length]);
BlockConfigurationEntry blockConfig = builder.create();
BlockEntryImpl blockImpl = (BlockEntryImpl) block;
List<BlockConfigurationEntry> configs = block.getConfigurations();
if (configs == null) {
configs = new ArrayList<BlockConfigurationEntry>();
blockImpl.setConfigurations(configs);
}
configs.add(blockConfig);
for (TripEntry trip : trips) {
if (trip.getBlock() == null)
((TripEntryImpl) trip).setBlock((BlockEntryImpl) block);
}
return blockConfig;
}
use of org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl in project onebusaway-application-modules by camsys.
the class UnitTestingSupport method blockTripIndices.
public static List<BlockTripIndex> blockTripIndices(BlockEntryImpl... blocks) {
List<BlockEntry> list = new ArrayList<BlockEntry>();
for (BlockEntryImpl block : blocks) list.add(block);
BlockIndexFactoryService factory = new BlockIndexFactoryServiceImpl();
return factory.createTripIndices(list);
}
Aggregations