use of org.onebusaway.transit_data_federation.services.blocks.BlockInstance 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.services.blocks.BlockInstance in project onebusaway-application-modules by camsys.
the class ArrivalAndDepartureAlarmServiceImpl method handleBlockLocation.
/**
**
* {@link BlockLocationListener} Interface
***
*/
@Override
public void handleBlockLocation(BlockLocation blockLocation) {
if (blockLocation == null)
return;
/**
* If we have new real-time info for a block, we need to update the alarms
* attached to the block instance
*/
BlockInstance blockInstance = blockLocation.getBlockInstance();
AlarmsForBlockInstance alarms = _alarmsByBlockInstance.get(blockInstance);
if (alarms != null)
alarms.updateBlockLocation(blockLocation);
}
use of org.onebusaway.transit_data_federation.services.blocks.BlockInstance in project onebusaway-application-modules by camsys.
the class TripStatusBeanServiceImpl method getBlockLocationAsStatusBean.
@Override
public TripStatusBean getBlockLocationAsStatusBean(BlockLocation blockLocation, long time) {
TripStatusBean bean = new TripStatusBean();
bean.setStatus("default");
BlockInstance blockInstance = blockLocation.getBlockInstance();
long serviceDate = blockInstance.getServiceDate();
bean.setServiceDate(serviceDate);
bean.setLastUpdateTime(blockLocation.getLastUpdateTime());
bean.setLastLocationUpdateTime(blockLocation.getLastLocationUpdateTime());
bean.setLastKnownLocation(blockLocation.getLastKnownLocation());
bean.setLastKnownOrientation(blockLocation.getLastKnownOrientation());
bean.setLocation(blockLocation.getLocation());
bean.setOrientation(blockLocation.getOrientation());
bean.setLastKnownLocation(blockLocation.getLastKnownLocation());
if (blockLocation.isLastKnownOrientationSet())
bean.setLastKnownOrientation(blockLocation.getLastKnownOrientation());
bean.setScheduleDeviation(blockLocation.getScheduleDeviation());
BlockTripInstance activeTripInstance = blockLocation.getActiveTripInstance();
if (activeTripInstance != null) {
BlockTripEntry activeBlockTrip = activeTripInstance.getBlockTrip();
bean.setScheduledDistanceAlongTrip(blockLocation.getScheduledDistanceAlongBlock() - activeBlockTrip.getDistanceAlongBlock());
bean.setDistanceAlongTrip(blockLocation.getDistanceAlongBlock() - activeBlockTrip.getDistanceAlongBlock());
TripEntry activeTrip = activeBlockTrip.getTrip();
bean.setTotalDistanceAlongTrip(activeTrip.getTotalTripDistance());
TripBean activeTripBean = _tripBeanService.getTripForId(activeTrip.getId());
bean.setActiveTrip(activeTripBean);
bean.setBlockTripSequence(activeBlockTrip.getSequence());
if (blockLocation.isLastKnownDistanceAlongBlockSet()) {
bean.setLastKnownDistanceAlongTrip(blockLocation.getLastKnownDistanceAlongBlock() - activeBlockTrip.getDistanceAlongBlock());
}
FrequencyEntry frequencyLabel = activeTripInstance.getFrequencyLabel();
if (frequencyLabel != null) {
FrequencyBean fb = FrequencyBeanLibrary.getBeanForFrequency(serviceDate, frequencyLabel);
bean.setFrequency(fb);
}
} else {
_log.warn("no active block trip for block location: blockInstance=" + blockLocation.getBlockInstance() + " time=" + time);
}
BlockStopTimeEntry closestStop = blockLocation.getClosestStop();
if (closestStop != null) {
StopTimeEntry stopTime = closestStop.getStopTime();
StopBean stopBean = _stopBeanService.getStopForId(stopTime.getStop().getId());
bean.setClosestStop(stopBean);
bean.setClosestStopTimeOffset(blockLocation.getClosestStopTimeOffset());
}
BlockStopTimeEntry nextStop = blockLocation.getNextStop();
if (nextStop != null) {
StopTimeEntry stopTime = nextStop.getStopTime();
StopBean stopBean = _stopBeanService.getStopForId(stopTime.getStop().getId());
bean.setNextStop(stopBean);
bean.setNextStopTimeOffset(blockLocation.getNextStopTimeOffset());
bean.setNextStopDistanceFromVehicle(blockLocation.getNextStop().getDistanceAlongBlock() - blockLocation.getDistanceAlongBlock());
}
BlockStopTimeEntry previousStop = blockLocation.getPreviousStop();
if (previousStop != null) {
StopTimeEntry stopTime = previousStop.getStopTime();
StopBean stopBean = _stopBeanService.getStopForId(stopTime.getStop().getId());
bean.setPreviousStop(stopBean);
bean.setPreviousStopTimeOffset(blockLocation.getPreviousStopTimeOffset());
bean.setPreviousStopDistanceFromVehicle(blockLocation.getPreviousStop().getDistanceAlongBlock() - blockLocation.getDistanceAlongBlock());
}
EVehiclePhase phase = blockLocation.getPhase();
if (phase != null)
bean.setPhase(phase.toLabel());
String status = blockLocation.getStatus();
if (status != null)
bean.setStatus(status);
if (blockLocation.getVehicleType() != null)
bean.setVehicleType(blockLocation.getVehicleType().toLabel());
bean.setPredicted(blockLocation.isPredicted());
AgencyAndId vid = blockLocation.getVehicleId();
if (vid != null)
bean.setVehicleId(ApplicationBeanLibrary.getId(vid));
if (activeTripInstance != null) {
List<ServiceAlertBean> situations = _serviceAlertBeanService.getServiceAlertsForVehicleJourney(time, activeTripInstance, blockLocation.getVehicleId());
if (!situations.isEmpty())
bean.setSituations(situations);
}
if (blockLocation.getTimepointPredictions() != null && blockLocation.getTimepointPredictions().size() > 0) {
List<TimepointPredictionBean> timepointPredictions = new ArrayList<TimepointPredictionBean>();
for (TimepointPredictionRecord tpr : blockLocation.getTimepointPredictions()) {
TimepointPredictionBean tpb = new TimepointPredictionBean();
tpb.setTimepointId(tpr.getTimepointId().toString());
tpb.setTripId(tpr.getTripId().toString());
tpb.setStopSequence(tpr.getStopSequence());
tpb.setTimepointPredictedArrivalTime(tpr.getTimepointPredictedArrivalTime());
tpb.setTimepointPredictedDepartureTime(tpr.getTimepointPredictedDepartureTime());
timepointPredictions.add(tpb);
}
bean.setTimepointPredictions(timepointPredictions);
}
return bean;
}
use of org.onebusaway.transit_data_federation.services.blocks.BlockInstance in project onebusaway-application-modules by camsys.
the class BlockCalendarServiceImpl method getBlockInstance.
/**
**
* {@link BlockCalendarService} Interface
***
*/
@Cacheable(isValueSerializable = false)
@Override
public BlockInstance getBlockInstance(AgencyAndId blockId, long serviceDate) {
BlockEntry block = _transitGraphDao.getBlockEntryForId(blockId);
if (block == null)
throw new IllegalArgumentException("unknown block: " + blockId);
List<BlockConfigurationEntry> configurations = block.getConfigurations();
int index = 0;
Date date = new Date(serviceDate);
InstanceState state = new InstanceState(serviceDate);
/**
* See the specific contract for {@link BlockEntry#getConfigurations()}
* about the sort order of configurations
*/
for (BlockConfigurationEntry configuration : configurations) {
if (allServiceIdsAreActiveForServiceDate(configuration, date)) {
return new BlockInstance(configuration, state);
}
index++;
}
return null;
}
use of org.onebusaway.transit_data_federation.services.blocks.BlockInstance in project onebusaway-application-modules by camsys.
the class BlockCalendarServiceImpl method findFrequencyBlockTripsInRange.
private void findFrequencyBlockTripsInRange(FrequencyServiceIntervalBlock serviceIntervalIndex, Date serviceDate, Date timeFrom, Date timeTo, List<BlockTripEntry> trips, List<FrequencyEntry> frequencies, Collection<BlockInstance> instances) {
int scheduledTimeFrom = (int) ((timeFrom.getTime() - serviceDate.getTime()) / 1000);
int scheduledTimeTo = (int) ((timeTo.getTime() - serviceDate.getTime()) / 1000);
int indexFrom = index(Arrays.binarySearch(serviceIntervalIndex.getEndTimes(), scheduledTimeFrom));
int indexTo = index(Arrays.binarySearch(serviceIntervalIndex.getStartTimes(), scheduledTimeTo));
for (int in = indexFrom; in < indexTo; in++) {
BlockTripEntry trip = trips.get(in);
BlockConfigurationEntry block = trip.getBlockConfiguration();
FrequencyEntry frequency = frequencies.get(in);
InstanceState state = new InstanceState(serviceDate.getTime(), frequency);
BlockInstance instance = new BlockInstance(block, state);
instances.add(instance);
}
}
Aggregations