use of org.onebusaway.transit_data.model.blocks.BlockTripBean in project onebusaway-application-modules by camsys.
the class SiriSupport method fillOnwardCalls.
private static void fillOnwardCalls(MonitoredVehicleJourneyStructure monitoredVehicleJourney, BlockInstanceBean blockInstance, TripBean framedJourneyTripBean, TripStatusBean currentVehicleTripStatus, OnwardCallsMode onwardCallsMode, PresentationService presentationService, TransitDataService transitDataService, Map<String, TimepointPredictionRecord> stopLevelPredictions, int maximumOnwardCalls, boolean hasRealtimeData, long responseTimestamp) {
String tripIdOfMonitoredCall = framedJourneyTripBean.getId();
monitoredVehicleJourney.setOnwardCalls(new OnwardCallsStructure());
// no need to go further if this is the case!
if (maximumOnwardCalls == 0) {
return;
}
List<BlockTripBean> blockTrips = blockInstance.getBlockConfiguration().getTrips();
double distanceOfVehicleAlongBlock = 0;
int blockTripStopsAfterTheVehicle = 0;
int onwardCallsAdded = 0;
boolean foundActiveTrip = false;
for (int i = 0; i < blockTrips.size(); i++) {
BlockTripBean blockTrip = blockTrips.get(i);
if (!foundActiveTrip) {
if (currentVehicleTripStatus.getActiveTrip().getId().equals(blockTrip.getTrip().getId())) {
distanceOfVehicleAlongBlock += currentVehicleTripStatus.getDistanceAlongTrip();
foundActiveTrip = true;
} else {
// so to get the size of this one, we have to look at the next.
if (i + 1 < blockTrips.size()) {
distanceOfVehicleAlongBlock = blockTrips.get(i + 1).getDistanceAlongBlock();
}
// bus has already served this trip, so no need to go further
continue;
}
}
if (onwardCallsMode == OnwardCallsMode.STOP_MONITORING) {
// always include onward calls for the trip the monitored call is on ONLY.
if (!blockTrip.getTrip().getId().equals(tripIdOfMonitoredCall)) {
continue;
}
}
boolean foundMatch = false;
HashMap<String, Integer> visitNumberForStopMap = new HashMap<String, Integer>();
for (BlockStopTimeBean stopTime : blockTrip.getBlockStopTimes()) {
int visitNumber = getVisitNumber(visitNumberForStopMap, stopTime.getStopTime().getStop());
StopBean stop = stopTime.getStopTime().getStop();
double distanceOfCallAlongTrip = stopTime.getDistanceAlongBlock() - blockTrip.getDistanceAlongBlock();
double distanceOfVehicleFromCall = stopTime.getDistanceAlongBlock() - distanceOfVehicleAlongBlock;
// on future trips, count always.
if (currentVehicleTripStatus.getActiveTrip().getId().equals(blockTrip.getTrip().getId())) {
if (!hasRealtimeData) {
if (stop.getId().equals(currentVehicleTripStatus.getNextStop().getId()))
foundMatch = true;
if (foundMatch) {
blockTripStopsAfterTheVehicle++;
ArrivalsAndDeparturesQueryBean query = new ArrivalsAndDeparturesQueryBean();
StopWithArrivalsAndDeparturesBean result = transitDataService.getStopWithArrivalsAndDepartures(stop.getId(), query);
// We can't assume the first result is the correct result
Collections.sort(result.getArrivalsAndDepartures(), new SortByTime());
if (result.getArrivalsAndDepartures().isEmpty()) {
// bad data? abort!
continue;
}
ArrivalAndDepartureBean arrivalAndDeparture = result.getArrivalsAndDepartures().get(0);
distanceOfVehicleFromCall = arrivalAndDeparture.getDistanceFromStop();
// responseTimestamp = arrivalAndDeparture.getScheduledArrivalTime();
} else
continue;
} else if (stopTime.getDistanceAlongBlock() >= distanceOfVehicleAlongBlock) {
blockTripStopsAfterTheVehicle++;
} else {
// stop is behind the bus--no need to go further
continue;
}
// future trip--bus hasn't reached this trip yet, so count all stops
} else {
blockTripStopsAfterTheVehicle++;
}
monitoredVehicleJourney.getOnwardCalls().getOnwardCall().add(getOnwardCallStructure(stop, presentationService, distanceOfCallAlongTrip, distanceOfVehicleFromCall, visitNumber, blockTripStopsAfterTheVehicle - 1, stopLevelPredictions.get(stopTime.getStopTime().getStop().getId()), hasRealtimeData, responseTimestamp, (currentVehicleTripStatus.getServiceDate() + stopTime.getStopTime().getArrivalTime() * 1000)));
onwardCallsAdded++;
if (onwardCallsAdded >= maximumOnwardCalls) {
return;
}
}
// if we get here, we added our stops
return;
}
return;
}
use of org.onebusaway.transit_data.model.blocks.BlockTripBean in project onebusaway-application-modules by camsys.
the class SiriSupportV2 method fillMonitoredCall.
private static void fillMonitoredCall(MonitoredVehicleJourneyStructure monitoredVehicleJourney, BlockInstanceBean blockInstance, TripStatusBean tripStatus, StopBean monitoredCallStopBean, PresentationService presentationService, TransitDataService transitDataService, Map<String, TimepointPredictionRecord> stopLevelPredictions, boolean hasRealtimeData, DetailLevel detailLevel, long responseTimestamp) {
List<BlockTripBean> blockTrips = blockInstance.getBlockConfiguration().getTrips();
double distanceOfVehicleAlongBlock = 0;
int blockTripStopsAfterTheVehicle = 0;
boolean foundActiveTrip = false;
for (int i = 0; i < blockTrips.size(); i++) {
BlockTripBean blockTrip = blockTrips.get(i);
if (!foundActiveTrip) {
if (tripStatus.getActiveTrip().getId().equals(blockTrip.getTrip().getId())) {
double distanceAlongTrip = tripStatus.getDistanceAlongTrip();
if (!hasRealtimeData) {
distanceAlongTrip = tripStatus.getScheduledDistanceAlongTrip();
}
distanceOfVehicleAlongBlock += distanceAlongTrip;
foundActiveTrip = true;
} else {
// next.
if (i + 1 < blockTrips.size()) {
distanceOfVehicleAlongBlock = blockTrips.get(i + 1).getDistanceAlongBlock();
}
// further
continue;
}
}
HashMap<String, Integer> visitNumberForStopMap = new HashMap<String, Integer>();
for (BlockStopTimeBean stopTime : blockTrip.getBlockStopTimes()) {
int visitNumber = getVisitNumber(visitNumberForStopMap, stopTime.getStopTime().getStop());
// on future trips, count always.
if (tripStatus.getActiveTrip().getId().equals(blockTrip.getTrip().getId())) {
if (stopTime.getDistanceAlongBlock() >= distanceOfVehicleAlongBlock) {
blockTripStopsAfterTheVehicle++;
} else {
// further
continue;
}
// future trip--bus hasn't reached this trip yet, so count
// all stops
} else {
blockTripStopsAfterTheVehicle++;
}
// monitored call
if (stopTime.getStopTime().getStop().getId().equals(monitoredCallStopBean.getId())) {
if (!presentationService.isOnDetour(tripStatus)) {
monitoredVehicleJourney.setMonitoredCall(getMonitoredCallStructure(stopTime.getStopTime().getStop(), presentationService, stopTime.getDistanceAlongBlock() - blockTrip.getDistanceAlongBlock(), stopTime.getDistanceAlongBlock() - distanceOfVehicleAlongBlock, visitNumber, blockTripStopsAfterTheVehicle - 1, stopLevelPredictions.get(stopTime.getStopTime().getStop().getId()), detailLevel, responseTimestamp));
}
// we found our monitored call--stop
return;
}
}
}
}
use of org.onebusaway.transit_data.model.blocks.BlockTripBean in project onebusaway-application-modules by camsys.
the class BeanFactoryV2 method getBlockConfig.
public BlockConfigurationV2Bean getBlockConfig(BlockConfigurationBean blockConfig) {
BlockConfigurationV2Bean bean = new BlockConfigurationV2Bean();
bean.setActiveServiceIds(blockConfig.getActiveServiceIds());
bean.setInactiveServiceIds(blockConfig.getInactiveServiceIds());
List<BlockTripV2Bean> blockTrips = new ArrayList<BlockTripV2Bean>();
for (BlockTripBean blockTrip : blockConfig.getTrips()) blockTrips.add(getBlockTrip(blockTrip));
bean.setTrips(blockTrips);
return bean;
}
use of org.onebusaway.transit_data.model.blocks.BlockTripBean 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.model.blocks.BlockTripBean in project onebusaway-application-modules by camsys.
the class BlockBeanServiceImpl method getBlockLocationAsBean.
private ScheduledBlockLocationBean getBlockLocationAsBean(ScheduledBlockLocation blockLocation) {
ScheduledBlockLocationBean bean = new ScheduledBlockLocationBean();
if (blockLocation.getActiveTrip() != null) {
BlockTripBean activeTrip = getBlockTripAsBean(blockLocation.getActiveTrip());
bean.setActiveTrip(activeTrip);
}
bean.setDistanceAlongBlock(blockLocation.getDistanceAlongBlock());
bean.setInService(blockLocation.isInService());
bean.setLocation(blockLocation.getLocation());
bean.setScheduledTime(blockLocation.getScheduledTime());
bean.setStopTimeIndex(blockLocation.getStopTimeIndex());
return bean;
}
Aggregations