use of org.onebusaway.realtime.api.VehicleLocationRecord 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.realtime.api.VehicleLocationRecord 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.realtime.api.VehicleLocationRecord in project onebusaway-application-modules by camsys.
the class VehicleStatusBeanServiceImpl method submitVehicleLocation.
@Override
public void submitVehicleLocation(VehicleLocationRecordBean bean) {
VehicleLocationRecord r = new VehicleLocationRecord();
r.setTimeOfRecord(bean.getTimeOfRecord());
r.setTimeOfLocationUpdate(bean.getTimeOfLocationUpdate());
r.setServiceDate(bean.getServiceDate());
r.setBlockId(AgencyAndIdLibrary.convertFromString(bean.getBlockId()));
r.setTripId(AgencyAndIdLibrary.convertFromString(bean.getTripId()));
r.setVehicleId(AgencyAndIdLibrary.convertFromString(bean.getVehicleId()));
if (bean.getPhase() != null)
r.setPhase(EVehiclePhase.valueOf(bean.getPhase().toUpperCase()));
r.setStatus(bean.getStatus());
CoordinatePoint p = bean.getCurrentLocation();
if (p != null) {
r.setCurrentLocationLat(p.getLat());
r.setCurrentLocationLon(p.getLon());
}
if (bean.isCurrentOrientationSet())
r.setCurrentOrientation(bean.getCurrentOrientation());
if (bean.isDistanceAlongBlockSet())
r.setDistanceAlongBlock(bean.getDistanceAlongBlock());
if (bean.isScheduleDeviationSet())
r.setScheduleDeviation(bean.getScheduleDeviation());
_vehicleLocationListener.handleVehicleLocationRecord(r);
}
use of org.onebusaway.realtime.api.VehicleLocationRecord in project onebusaway-application-modules by camsys.
the class VehicleStatusBeanServiceImpl method getStatusAsBean.
/**
**
*
***
*/
private VehicleStatusBean getStatusAsBean(VehicleStatus status, long time) {
VehicleLocationRecord record = status.getRecord();
VehicleStatusBean bean = new VehicleStatusBean();
bean.setLastUpdateTime(record.getTimeOfRecord());
bean.setLastLocationUpdateTime(record.getTimeOfLocationUpdate());
EVehiclePhase phase = record.getPhase();
if (phase != null)
bean.setPhase(phase.toLabel());
bean.setStatus(record.getStatus());
if (record.isCurrentLocationSet())
bean.setLocation(new CoordinatePoint(record.getCurrentLocationLat(), record.getCurrentLocationLon()));
bean.setVehicleId(AgencyAndIdLibrary.convertToString(record.getVehicleId()));
TripDetailsBean details = _tripDetailsBeanService.getTripForVehicle(record.getVehicleId(), time, new TripDetailsInclusionBean(true, false, true));
if (details != null && details.getStatus() != null) {
bean.setTrip(details.getTrip());
bean.setTripStatus(details.getStatus());
}
List<VehicleLocationRecord> allRecords = status.getAllRecords();
if (!CollectionsLibrary.isEmpty(allRecords)) {
List<VehicleLocationRecordBean> allRecordBeans = new ArrayList<VehicleLocationRecordBean>();
bean.setAllRecords(allRecordBeans);
for (VehicleLocationRecord r : allRecords) {
VehicleLocationRecordBean rBean = getVehicleLocationRecordAsBean(r);
allRecordBeans.add(rBean);
}
}
return bean;
}
use of org.onebusaway.realtime.api.VehicleLocationRecord in project onebusaway-application-modules by camsys.
the class BlockLocationServiceImpl method getBlockLocationRecordsAsVehicleLocationRecords.
private List<VehicleLocationCacheElements> getBlockLocationRecordsAsVehicleLocationRecords(BlockInstance blockInstance, List<BlockLocationRecord> records) {
List<VehicleLocationCacheElements> results = new ArrayList<VehicleLocationCacheElements>();
for (BlockLocationRecord record : records) {
VehicleLocationRecord vlr = new VehicleLocationRecord();
vlr.setBlockId(blockInstance.getBlock().getBlock().getId());
if (record.isLocationSet()) {
vlr.setCurrentLocationLat(record.getLocationLat());
vlr.setCurrentLocationLon(record.getLocationLon());
}
if (record.isOrientationSet())
vlr.setCurrentOrientation(record.getOrientation());
if (record.isDistanceAlongBlockSet())
vlr.setDistanceAlongBlock(record.getDistanceAlongBlock());
vlr.setPhase(record.getPhase());
if (record.isScheduleDeviationSet())
vlr.setScheduleDeviation(record.getScheduleDeviation());
vlr.setServiceDate(record.getServiceDate());
vlr.setStatus(record.getStatus());
vlr.setTimeOfRecord(record.getTime());
vlr.setVehicleId(record.getVehicleId());
VehicleLocationCacheElement element = new VehicleLocationCacheElement(vlr, null, null);
VehicleLocationCacheElements elements = new VehicleLocationCacheElements(blockInstance, element);
results.add(elements);
}
return results;
}
Aggregations