use of org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry in project onebusaway-application-modules by camsys.
the class StopTimeServiceImpl method getNextBlockSequenceDeparturesForStop.
@Override
public List<StopTimeInstance> getNextBlockSequenceDeparturesForStop(StopEntry stopEntry, long time, boolean includePrivateSerivce) {
List<StopTimeInstance> stopTimeInstances = new ArrayList<StopTimeInstance>();
List<BlockStopSequenceIndex> blockStopTripIndices = _blockIndexService.getStopSequenceIndicesForStop(stopEntry);
for (BlockStopSequenceIndex index : blockStopTripIndices) {
List<Date> serviceDates = _calendarService.getNextServiceDatesForDepartureInterval(index.getServiceIds(), index.getServiceInterval(), time);
for (Date serviceDate : serviceDates) {
int relativeFrom = effectiveTime(serviceDate.getTime(), time);
int fromIndex = GenericBinarySearch.search(index, index.size(), relativeFrom, IndexAdapters.BLOCK_STOP_TIME_DEPARTURE_INSTANCE);
if (fromIndex < index.size()) {
BlockStopTimeEntry blockStopTime = index.getBlockStopTimeForIndex(fromIndex);
InstanceState state = new InstanceState(serviceDate.getTime());
StopTimeInstance sti = new StopTimeInstance(blockStopTime, state);
stopTimeInstances.add(sti);
}
}
}
List<FrequencyBlockStopTimeIndex> frequencyIndices = _blockIndexService.getFrequencyStopTimeIndicesForStop(stopEntry);
for (FrequencyBlockStopTimeIndex index : frequencyIndices) {
List<Date> serviceDates = _calendarService.getNextServiceDatesForDepartureInterval(index.getServiceIds(), index.getServiceInterval(), time);
for (Date serviceDate : serviceDates) {
int relativeFrom = effectiveTime(serviceDate.getTime(), time);
int fromIndex = GenericBinarySearch.search(index, index.size(), relativeFrom, IndexAdapters.FREQUENCY_END_TIME_INSTANCE);
List<FrequencyBlockStopTimeEntry> frequencyStopTimes = index.getFrequencyStopTimes();
if (fromIndex < index.size()) {
FrequencyBlockStopTimeEntry entry = frequencyStopTimes.get(fromIndex);
BlockStopTimeEntry bst = entry.getStopTime();
FrequencyEntry frequency = entry.getFrequency();
InstanceState state = new InstanceState(serviceDate.getTime(), frequency);
int stopTimeOffset = entry.getStopTimeOffset();
int frequencyOffset = computeFrequencyOffset(relativeFrom, bst, frequency, stopTimeOffset, true);
StopTimeInstance sti = new StopTimeInstance(bst, state, frequencyOffset);
stopTimeInstances.add(sti);
}
}
}
return stopTimeInstances;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry in project onebusaway-application-modules by camsys.
the class ArrivalsAndDeparturesBeanServiceImpl method applyBlockLocationToBean.
private void applyBlockLocationToBean(ArrivalAndDepartureInstance instance, ArrivalAndDepartureBean bean, long targetTime) {
boolean hasFrequency = instance.getFrequency() != null;
if (instance.isPredictedArrivalTimeSet()) {
bean.setPredictedArrivalTime(instance.getPredictedArrivalTime());
if (hasFrequency)
bean.setScheduledArrivalTime(bean.getPredictedArrivalTime());
}
if (instance.isPredictedDepartureTimeSet()) {
bean.setPredictedDepartureTime(instance.getPredictedDepartureTime());
if (hasFrequency)
bean.setScheduledDepartureTime(bean.getPredictedDepartureTime());
}
BlockStopTimeEntry stopTime = instance.getBlockStopTime();
BlockLocation blockLocation = instance.getBlockLocation();
if (blockLocation == null)
return;
bean.setPredicted(blockLocation.isPredicted());
// Distance from stop
if (blockLocation.isDistanceAlongBlockSet()) {
double distanceFromStop = stopTime.getDistanceAlongBlock() - blockLocation.getDistanceAlongBlock();
bean.setDistanceFromStop(distanceFromStop);
} else {
double distanceFromStop = stopTime.getDistanceAlongBlock() - blockLocation.getScheduledDistanceAlongBlock();
bean.setDistanceFromStop(distanceFromStop);
}
// Number of stops away
if (blockLocation.getNextStop() != null) {
BlockStopTimeEntry nextStopTime = blockLocation.getNextStop();
bean.setNumberOfStopsAway(stopTime.getBlockSequence() - nextStopTime.getBlockSequence());
}
if (blockLocation.getLastUpdateTime() > 0)
bean.setLastUpdateTime(blockLocation.getLastUpdateTime());
if (blockLocation.getVehicleId() != null)
bean.setVehicleId(AgencyAndIdLibrary.convertToString(blockLocation.getVehicleId()));
TripStatusBean tripStatusBean = _tripDetailsBeanService.getBlockLocationAsStatusBean(blockLocation, targetTime);
bean.setTripStatus(tripStatusBean);
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry in project onebusaway-application-modules by camsys.
the class ArrivalsAndDeparturesBeanServiceImpl method getStopTimeInstanceAsBean.
/**
**
* Private Methods
***
*/
private ArrivalAndDepartureBean getStopTimeInstanceAsBean(long time, ArrivalAndDepartureInstance instance, Map<AgencyAndId, StopBean> stopBeanCache) {
ArrivalAndDepartureBean pab = new ArrivalAndDepartureBean();
pab.setServiceDate(instance.getServiceDate());
BlockStopTimeEntry blockStopTime = instance.getBlockStopTime();
BlockTripEntry blockTrip = blockStopTime.getTrip();
StopTimeEntry stopTime = blockStopTime.getStopTime();
StopEntry stop = stopTime.getStop();
TripEntry trip = stopTime.getTrip();
TripBean tripBean = _tripBeanService.getTripForId(trip.getId());
pab.setTrip(tripBean);
pab.setBlockTripSequence(blockTrip.getSequence());
pab.setArrivalEnabled(stopTime.getSequence() > 0);
pab.setDepartureEnabled(stopTime.getSequence() + 1 < trip.getStopTimes().size());
StopTimeNarrative stopTimeNarrative = _narrativeService.getStopTimeForEntry(stopTime);
pab.setRouteShortName(stopTimeNarrative.getRouteShortName());
pab.setTripHeadsign(stopTimeNarrative.getStopHeadsign());
StopBean stopBean = stopBeanCache.get(stop.getId());
if (stopBean == null) {
stopBean = _stopBeanService.getStopForId(stop.getId());
stopBeanCache.put(stop.getId(), stopBean);
}
pab.setStop(stopBean);
pab.setStopSequence(stopTime.getSequence());
pab.setTotalStopsInTrip(stopTime.getTotalStopsInTrip());
pab.setStatus("default");
pab.setScheduledArrivalTime(instance.getScheduledArrivalTime());
pab.setScheduledDepartureTime(instance.getScheduledDepartureTime());
FrequencyEntry frequency = instance.getFrequencyLabel();
pab.setFrequency(null);
if (frequency != null) {
FrequencyBean fb = FrequencyBeanLibrary.getBeanForFrequency(instance.getServiceDate(), frequency);
pab.setFrequency(fb);
}
return pab;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry in project onebusaway-application-modules by camsys.
the class ScheduledBlockLocationServiceImpl method getScheduledBlockLocationFromScheduledTime.
@Override
public ScheduledBlockLocation getScheduledBlockLocationFromScheduledTime(ScheduledBlockLocation previousLocation, int scheduleTime) {
if (previousLocation.getScheduledTime() > scheduleTime)
throw new IllegalStateException("previousLocation's scheduledTime must be before the requested scheduleTime");
BlockTripEntry trip = previousLocation.getActiveTrip();
BlockConfigurationEntry blockConfig = trip.getBlockConfiguration();
List<BlockStopTimeEntry> stopTimes = blockConfig.getStopTimes();
int index = previousLocation.getStopTimeIndex();
while (index < stopTimes.size()) {
int t = blockConfig.getDepartureTimeForIndex(index);
if (scheduleTime <= t)
break;
index++;
}
return getScheduledBlockLocationFromScheduleTimeAndStopTimeIndex(stopTimes, scheduleTime, index);
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry in project onebusaway-application-modules by camsys.
the class ScheduledBlockLocationServiceImpl method getScheduledBlockLocationFromDistanceAlongBlockAndStopTimeIndex.
/**
**
* Private Methods
***
*/
private ScheduledBlockLocation getScheduledBlockLocationFromDistanceAlongBlockAndStopTimeIndex(List<BlockStopTimeEntry> stopTimes, double distanceAlongBlock, int stopTimeIndex) {
int n = stopTimes.size();
// Are we out beyond our last stop-time?
if (stopTimeIndex == n) {
// If we only have one stop time, we can't interpolate the schedule time
if (n == 1)
return null;
BlockStopTimeEntry blockFrom = stopTimes.get(n - 2);
BlockStopTimeEntry blockTo = stopTimes.get(n - 1);
if (n == 2)
return interpolateLocation(blockFrom, blockTo, distanceAlongBlock, stopTimeIndex);
BlockStopTimeEntry previousBlock = stopTimes.get(n - 3);
return interpolateLocation(previousBlock, blockFrom, blockTo, distanceAlongBlock, stopTimeIndex);
}
// Are we before out first stop-time?
if (stopTimeIndex == 0) {
// If we only have one stop time, we can't interpolate the schedule time
if (n == 1)
return null;
BlockStopTimeEntry blockFrom = stopTimes.get(0);
BlockStopTimeEntry blockTo = stopTimes.get(1);
return interpolateLocation(blockFrom, blockTo, distanceAlongBlock, stopTimeIndex);
}
BlockStopTimeEntry blockBefore = stopTimes.get(stopTimeIndex - 1);
BlockStopTimeEntry blockAfter = stopTimes.get(stopTimeIndex);
StopTimeEntry before = blockBefore.getStopTime();
StopTimeEntry after = blockAfter.getStopTime();
double ratio = (distanceAlongBlock - blockBefore.getDistanceAlongBlock()) / (blockAfter.getDistanceAlongBlock() - blockBefore.getDistanceAlongBlock());
int scheduleTime = (int) (before.getDepartureTime() + (after.getArrivalTime() - before.getDepartureTime()) * ratio);
return getScheduledBlockLocationFromScheduleTimeAndStopTimeIndex(stopTimes, scheduleTime, stopTimeIndex);
}
Aggregations