use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry 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.transit_graph.TripEntry in project onebusaway-application-modules by camsys.
the class BlockLocationServiceImpl method getVehicleLocationRecordAsBlockInstance.
/**
**
* Private Methods
***
*/
private BlockInstance getVehicleLocationRecordAsBlockInstance(VehicleLocationRecord record) {
AgencyAndId blockId = record.getBlockId();
if (blockId == null) {
AgencyAndId tripId = record.getTripId();
if (tripId == null)
throw new IllegalArgumentException("at least one of blockId or tripId must be specified for VehicleLocationRecord");
TripEntry tripEntry = _transitGraphDao.getTripEntryForId(tripId);
if (tripEntry == null)
throw new IllegalArgumentException("trip not found with id=" + tripId);
BlockEntry block = tripEntry.getBlock();
blockId = block.getId();
}
if (record.getServiceDate() == 0)
throw new IllegalArgumentException("you must specify a serviceDate");
if (record.getTimeOfRecord() == 0)
throw new IllegalArgumentException("you must specify a record time");
BlockInstance blockInstance = getBestBlockForRecord(blockId, record.getServiceDate(), record.getTimeOfRecord());
return blockInstance;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry in project onebusaway-application-modules by camsys.
the class BlockLocationServiceImpl method getVehicleLocationRecordAsBlockLocationRecord.
private List<BlockLocationRecord> getVehicleLocationRecordAsBlockLocationRecord(BlockInstance blockInstance, VehicleLocationRecord record, ScheduledBlockLocation scheduledBlockLocation) {
BlockLocationRecord.Builder builder = BlockLocationRecord.builder();
if (scheduledBlockLocation != null) {
BlockTripEntry activeTrip = scheduledBlockLocation.getActiveTrip();
builder.setTripId(activeTrip.getTrip().getId());
builder.setBlockId(activeTrip.getBlockConfiguration().getBlock().getId());
// store the vehicleType for later retrieval
builder.setVehicleType(EVehicleType.toEnum(activeTrip.getTrip().getRoute().getType()));
double distanceAlongBlock = scheduledBlockLocation.getDistanceAlongBlock();
builder.setDistanceAlongBlock(distanceAlongBlock);
double distanceAlongTrip = distanceAlongBlock - activeTrip.getDistanceAlongBlock();
builder.setDistanceAlongTrip(distanceAlongTrip);
}
if (record.getBlockId() != null)
builder.setBlockId(record.getBlockId());
if (record.getTripId() != null)
builder.setTripId(record.getTripId());
builder.setTime(record.getTimeOfRecord());
builder.setServiceDate(record.getServiceDate());
if (record.isScheduleDeviationSet())
builder.setScheduleDeviation(record.getScheduleDeviation());
if (record.isDistanceAlongBlockSet()) {
double distanceAlongBlock = record.getDistanceAlongBlock();
builder.setDistanceAlongBlock(distanceAlongBlock);
AgencyAndId tripId = record.getTripId();
if (tripId != null) {
BlockConfigurationEntry block = blockInstance.getBlock();
for (BlockTripEntry blockTrip : block.getTrips()) {
TripEntry trip = blockTrip.getTrip();
if (trip.getId().equals(tripId)) {
double distanceAlongTrip = distanceAlongBlock - blockTrip.getDistanceAlongBlock();
builder.setDistanceAlongTrip(distanceAlongTrip);
}
}
}
}
if (record.isCurrentLocationSet()) {
builder.setLocationLat(record.getCurrentLocationLat());
builder.setLocationLon(record.getCurrentLocationLon());
}
if (record.isCurrentOrientationSet())
builder.setOrientation(record.getCurrentOrientation());
builder.setPhase(record.getPhase());
builder.setStatus(record.getStatus());
builder.setVehicleId(record.getVehicleId());
List<TimepointPredictionRecord> predictions = record.getTimepointPredictions();
if (predictions == null || predictions.isEmpty())
return Arrays.asList(builder.create());
List<BlockLocationRecord> results = new ArrayList<BlockLocationRecord>();
for (TimepointPredictionRecord tpr : predictions) {
builder.setTimepointId(tpr.getTimepointId());
builder.setTimepointScheduledTime(tpr.getTimepointScheduledTime());
builder.setTimepointPredictedArrivalTime(tpr.getTimepointPredictedArrivalTime());
builder.setTimepointPredictedDepartureTime(tpr.getTimepointPredictedDepartureTime());
results.add(builder.create());
}
return results;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry in project onebusaway-application-modules by camsys.
the class SiriLikeRealtimeSource method calculateScheduleDeviation.
protected Integer calculateScheduleDeviation(VehicleLocationRecord vlr) {
TripEntry tripEntry = this._transitGraphDao.getTripEntryForId(vlr.getTripId());
// unit tests don't have a populated transit graph so fall back on scheduled time from feed
if (tripEntry != null) {
// todo this is a side effect
vlr.setBlockId(tripEntry.getBlock().getId());
long time = vlr.getTimeOfLocationUpdate() / 1000;
double lat = vlr.getCurrentLocationLat();
double lon = vlr.getCurrentLocationLon();
long serviceDateTime = vlr.getServiceDate();
long effectiveScheduleTimeSeconds = getEffectiveScheduleTime(tripEntry, lat, lon, time, serviceDateTime);
long effectiveScheduleTime = effectiveScheduleTimeSeconds + (serviceDateTime / 1000);
int deviation = (int) (time - effectiveScheduleTime);
_log.debug("deviation(" + vlr.getVehicleId() + " is " + deviation + " time=" + new Date(time * 1000) + ", effectiveScheduleTime=" + new Date(effectiveScheduleTime * 1000));
return deviation;
}
return null;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry in project onebusaway-application-modules by camsys.
the class GtfsRealtimeEntitySource method getTripId.
public Id getTripId(String tripId) {
TripEntry trip = getTrip(tripId);
if (trip != null)
return ServiceAlertLibrary.id(trip.getId());
_log.warn("trip not found with id \"{}\"", tripId);
AgencyAndId id = new AgencyAndId(_agencyIds.get(0), tripId);
return ServiceAlertLibrary.id(id);
}
Aggregations