use of org.onebusaway.realtime.api.TimepointPredictionRecord 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;
}
Aggregations