use of org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl 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.TripEntryImpl 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.TripEntryImpl 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.TripEntryImpl in project onebusaway-application-modules by camsys.
the class UnitTestingSupport method linkBlockTrips.
public static BlockConfigurationEntry linkBlockTrips(BlockEntryImpl block, List<FrequencyEntry> frequencies, TripEntryImpl... trips) {
List<TripEntry> tripEntries = new ArrayList<TripEntry>();
Set<LocalizedServiceId> serviceIds = new TreeSet<LocalizedServiceId>();
for (int i = 0; i < trips.length; i++) {
TripEntryImpl trip = trips[i];
trip.setBlock(block);
tripEntries.add(trip);
if (trip.getServiceId() != null)
serviceIds.add(trip.getServiceId());
}
Builder builder = BlockConfigurationEntryImpl.builder();
builder.setBlock(block);
builder.setServiceIds(new ServiceIdActivation(new ArrayList<LocalizedServiceId>(serviceIds), new ArrayList<LocalizedServiceId>()));
builder.setTrips(tripEntries);
builder.setFrequencies(frequencies);
builder.setTripGapDistances(new double[tripEntries.size()]);
BlockConfigurationEntry configuration = builder.create();
List<BlockConfigurationEntry> configurations = block.getConfigurations();
if (configurations == null) {
configurations = new ArrayList<BlockConfigurationEntry>();
block.setConfigurations(configurations);
}
configurations.add(configuration);
return configuration;
}
use of org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl in project onebusaway-application-modules by camsys.
the class UnitTestingSupport method trip.
public static TripEntryImpl trip(String id, String serviceId) {
TripEntryImpl trip = trip(id);
trip.setServiceId(new LocalizedServiceId(aid(serviceId), timeZone()));
return trip;
}
Aggregations