use of org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry in project onebusaway-application-modules by camsys.
the class BlockCalendarServiceImpl method findBlockLayoversInRange.
private void findBlockLayoversInRange(LayoverIntervalBlock intervals, Date serviceDate, Date timeFrom, Date timeTo, List<BlockTripEntry> trips, Collection<BlockInstance> instances) {
int scheduledTimeFrom = (int) ((timeFrom.getTime() - serviceDate.getTime()) / 1000);
int scheduledTimeTo = (int) ((timeTo.getTime() - serviceDate.getTime()) / 1000);
int indexFrom = index(Arrays.binarySearch(intervals.getEndTimes(), scheduledTimeFrom));
int indexTo = index(Arrays.binarySearch(intervals.getStartTimes(), scheduledTimeTo));
InstanceState state = new InstanceState(serviceDate.getTime());
for (int in = indexFrom; in < indexTo; in++) {
BlockTripEntry trip = trips.get(in);
BlockConfigurationEntry block = trip.getBlockConfiguration();
BlockInstance instance = new BlockInstance(block, state);
instances.add(instance);
}
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry 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.BlockTripEntry in project onebusaway-application-modules by camsys.
the class GtfsRealtimeTripLibrary method getBlockStartTimeForTripStartTime.
private int getBlockStartTimeForTripStartTime(BlockInstance instance, AgencyAndId tripId, int tripStartTime) {
BlockConfigurationEntry block = instance.getBlock();
Map<AgencyAndId, BlockTripEntry> blockTripsById = MappingLibrary.mapToValue(block.getTrips(), "trip.id");
int rawBlockStartTime = block.getDepartureTimeForIndex(0);
int rawTripStartTime = blockTripsById.get(tripId).getDepartureTimeForIndex(0);
int adjustedBlockStartTime = rawBlockStartTime + (tripStartTime - rawTripStartTime);
return adjustedBlockStartTime;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry in project onebusaway-application-modules by camsys.
the class BlockBeanServiceImpl method getBlockConfigurationAsBean.
private BlockConfigurationBean getBlockConfigurationAsBean(BlockConfigurationEntry blockConfiguration) {
BlockConfigurationBean bean = new BlockConfigurationBean();
ServiceIdActivation serviceIds = blockConfiguration.getServiceIds();
AgencyAndId blockId = blockConfiguration.getBlock().getId();
bean.setBlockId(AgencyAndIdLibrary.convertToString(blockId));
List<String> activeServiceIds = new ArrayList<String>();
for (LocalizedServiceId lsid : serviceIds.getActiveServiceIds()) activeServiceIds.add(AgencyAndIdLibrary.convertToString(lsid.getId()));
bean.setActiveServiceIds(activeServiceIds);
List<String> inactiveServiceIds = new ArrayList<String>();
for (LocalizedServiceId lsid : serviceIds.getInactiveServiceIds()) inactiveServiceIds.add(AgencyAndIdLibrary.convertToString(lsid.getId()));
bean.setInactiveServiceIds(inactiveServiceIds);
List<BlockTripBean> tripBeans = new ArrayList<BlockTripBean>();
for (BlockTripEntry blockTrip : blockConfiguration.getTrips()) tripBeans.add(getBlockTripAsBean(blockTrip));
bean.setTrips(tripBeans);
TimeZone tz = _agencyService.getTimeZoneForAgencyId(blockId.getAgencyId());
bean.setTimeZone(tz.getID());
return bean;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry in project onebusaway-application-modules by camsys.
the class BlockStatusBeanServiceImpl method bean.
private BlockStatusBean bean(BlockLocation blockLocation) {
if (blockLocation == null)
return null;
BlockInstance instance = blockLocation.getBlockInstance();
BlockConfigurationEntry block = instance.getBlock();
long serviceDate = instance.getServiceDate();
BlockStatusBean bean = new BlockStatusBean();
bean.setBlock(_blockBeanService.getBlockForId(block.getBlock().getId()));
bean.setStatus("default");
bean.setServiceDate(serviceDate);
bean.setTotalDistanceAlongBlock(block.getTotalBlockDistance());
bean.setInService(blockLocation.isInService());
CoordinatePoint location = blockLocation.getLocation();
bean.setLocation(location);
bean.setScheduledDistanceAlongBlock(blockLocation.getScheduledDistanceAlongBlock());
bean.setDistanceAlongBlock(blockLocation.getDistanceAlongBlock());
BlockTripEntry activeTrip = blockLocation.getActiveTrip();
if (activeTrip != null) {
BlockTripBean activeTripBean = _blockBeanService.getBlockTripAsBean(activeTrip);
bean.setActiveTrip(activeTripBean);
}
BlockStopTimeEntry stop = blockLocation.getClosestStop();
if (stop != null) {
StopBean stopBean = _stopBeanService.getStopForId(stop.getStopTime().getStop().getId());
bean.setClosestStop(stopBean);
bean.setClosestStopTimeOffset(blockLocation.getClosestStopTimeOffset());
}
bean.setPredicted(blockLocation.isPredicted());
bean.setLastUpdateTime(blockLocation.getLastUpdateTime());
bean.setScheduleDeviation(blockLocation.getScheduleDeviation());
AgencyAndId vid = blockLocation.getVehicleId();
if (vid != null)
bean.setVehicleId(ApplicationBeanLibrary.getId(vid));
return bean;
}
Aggregations