use of org.onebusaway.transit_data_federation.services.blocks.InstanceState in project onebusaway-application-modules by camsys.
the class ArrivalAndDepartureServiceImpl method setPredictedTimesFromScheduleDeviation.
private void setPredictedTimesFromScheduleDeviation(ArrivalAndDepartureInstance instance, BlockLocation blockLocation, int scheduleDeviation, long targetTime) {
BlockStopTimeEntry blockStopTime = instance.getBlockStopTime();
int effectiveScheduleTime = (int) (((targetTime - instance.getServiceDate()) / 1000) - scheduleDeviation);
int arrivalDeviation = calculateArrivalDeviation(blockLocation.getNextStop(), blockStopTime, effectiveScheduleTime, scheduleDeviation);
int departureDeviation = calculateDepartureDeviation(blockLocation.getNextStop(), blockStopTime, effectiveScheduleTime, scheduleDeviation);
/**
* Why don't we use the ArrivalAndDepartureTime scheduled arrival and
* departures here? Because they may have been artificially shifted for a
* frequency-based method
*/
InstanceState state = instance.getStopTimeInstance().getState();
ArrivalAndDepartureTime schedule = ArrivalAndDepartureTime.getScheduledTime(state, instance.getBlockStopTime());
long arrivalTime = schedule.getArrivalTime() + arrivalDeviation * 1000;
setPredictedArrivalTimeForInstance(instance, arrivalTime);
long departureTime = schedule.getDepartureTime() + departureDeviation * 1000;
setPredictedDepartureTimeForInstance(instance, departureTime);
}
use of org.onebusaway.transit_data_federation.services.blocks.InstanceState in project onebusaway-application-modules by camsys.
the class StopTimeServiceImpl method getFrequenciesForStopAndServiceIdsAndTimeRange.
private List<Integer> getFrequenciesForStopAndServiceIdsAndTimeRange(FrequencyStopTripIndex index, Date serviceDate, Date from, Date to, List<StopTimeInstance> stopTimeInstances, EFrequencyStopTimeBehavior frequencyBehavior) {
int relativeFrom = effectiveTime(serviceDate, from);
int relativeTo = effectiveTime(serviceDate, to);
int fromIndex = GenericBinarySearch.search(index, index.size(), relativeFrom, IndexAdapters.FREQUENCY_END_TIME_INSTANCE);
int toIndex = GenericBinarySearch.search(index, index.size(), relativeTo, IndexAdapters.FREQUENCY_START_TIME_INSTANCE);
List<FrequencyBlockStopTimeEntry> frequencyStopTimes = index.getFrequencyStopTimes();
List<Integer> offsetsIntoIndex = new ArrayList<Integer>();
for (int in = fromIndex; in < toIndex; in++) {
FrequencyBlockStopTimeEntry entry = frequencyStopTimes.get(in);
BlockStopTimeEntry bst = entry.getStopTime();
FrequencyEntry frequency = entry.getFrequency();
InstanceState state = new InstanceState(serviceDate.getTime(), frequency);
switch(frequencyBehavior) {
case INCLUDE_UNSPECIFIED:
{
stopTimeInstances.add(new StopTimeInstance(bst, state));
offsetsIntoIndex.add(in);
break;
}
case INCLUDE_INTERPOLATED:
{
int stopTimeOffset = entry.getStopTimeOffset();
int tFrom = Math.max(relativeFrom, frequency.getStartTime());
int tTo = Math.min(relativeTo, frequency.getEndTime());
tFrom = snapToFrequencyStopTime(frequency, tFrom, stopTimeOffset, true);
tTo = snapToFrequencyStopTime(frequency, tTo, stopTimeOffset, false);
for (int t = tFrom; t <= tTo; t += frequency.getHeadwaySecs()) {
int frequencyOffset = t - bst.getStopTime().getDepartureTime();
stopTimeInstances.add(new StopTimeInstance(bst, state, frequencyOffset));
offsetsIntoIndex.add(in);
}
break;
}
}
}
return offsetsIntoIndex;
}
use of org.onebusaway.transit_data_federation.services.blocks.InstanceState in project onebusaway-application-modules by camsys.
the class ArrivalAndDepartureServiceImpl method getNextStopArrivalAndDeparture.
@Override
public ArrivalAndDepartureInstance getNextStopArrivalAndDeparture(ArrivalAndDepartureInstance instance) {
BlockStopTimeEntry stopTime = instance.getBlockStopTime();
BlockTripEntry trip = stopTime.getTrip();
BlockConfigurationEntry blockConfig = trip.getBlockConfiguration();
List<BlockStopTimeEntry> stopTimes = blockConfig.getStopTimes();
int index = stopTime.getBlockSequence() + 1;
if (index >= stopTimes.size())
return null;
BlockStopTimeEntry nextStopTime = stopTimes.get(index);
InstanceState state = instance.getStopTimeInstance().getState();
ArrivalAndDepartureTime scheduledTime = ArrivalAndDepartureTime.getScheduledTime(state, nextStopTime);
if (state.getFrequency() != null) {
StopTimeEntry nStopTime = nextStopTime.getStopTime();
int betweenStopDelta = nStopTime.getArrivalTime() - stopTime.getStopTime().getDepartureTime();
int atStopDelta = nStopTime.getDepartureTime() - nStopTime.getArrivalTime();
long scheduledArrivalTime = instance.getScheduledDepartureTime() + betweenStopDelta * 1000;
long scheduledDepartureTime = scheduledArrivalTime + atStopDelta * 1000;
scheduledTime.setArrivalTime(scheduledArrivalTime);
scheduledTime.setDepartureTime(scheduledDepartureTime);
}
StopTimeInstance nextStopTimeInstance = new StopTimeInstance(stopTime, state);
ArrivalAndDepartureInstance nextInstance = new ArrivalAndDepartureInstance(nextStopTimeInstance, scheduledTime);
if (instance.isPredictedDepartureTimeSet()) {
int scheduledDeviation = (int) ((instance.getPredictedDepartureTime() - instance.getScheduledDepartureTime()) / 1000);
int arrivalDeviation = propagateScheduleDeviationForwardBetweenStops(stopTime, nextStopTime, scheduledDeviation);
int departureDeviation = propagateScheduleDeviationForwardAcrossStop(nextStopTime, arrivalDeviation);
setPredictedArrivalTimeForInstance(nextInstance, nextInstance.getScheduledArrivalTime() + arrivalDeviation * 1000);
setPredictedDepartureTimeForInstance(nextInstance, nextInstance.getScheduledDepartureTime() + departureDeviation * 1000);
}
return nextInstance;
}
use of org.onebusaway.transit_data_federation.services.blocks.InstanceState in project onebusaway-application-modules by camsys.
the class ArrivalAndDepartureServiceImpl method getPreviousStopArrivalAndDeparture.
@Override
public ArrivalAndDepartureInstance getPreviousStopArrivalAndDeparture(ArrivalAndDepartureInstance instance) {
BlockStopTimeEntry stopTime = instance.getBlockStopTime();
BlockTripEntry trip = stopTime.getTrip();
BlockConfigurationEntry blockConfig = trip.getBlockConfiguration();
List<BlockStopTimeEntry> stopTimes = blockConfig.getStopTimes();
int index = stopTime.getBlockSequence() - 1;
if (index < 0)
return null;
BlockStopTimeEntry prevStopTime = stopTimes.get(index);
InstanceState state = instance.getStopTimeInstance().getState();
ArrivalAndDepartureTime scheduledTime = ArrivalAndDepartureTime.getScheduledTime(state, prevStopTime);
if (instance.getFrequency() != null) {
StopTimeEntry pStopTime = prevStopTime.getStopTime();
int betweenStopDelta = stopTime.getStopTime().getArrivalTime() - pStopTime.getDepartureTime();
int atStopDelta = pStopTime.getDepartureTime() - pStopTime.getArrivalTime();
long scheduledDepartureTime = instance.getScheduledArrivalTime() - betweenStopDelta * 1000;
long scheduledArrivalTime = scheduledDepartureTime - atStopDelta * 1000;
scheduledTime.setArrivalTime(scheduledArrivalTime);
scheduledTime.setDepartureTime(scheduledDepartureTime);
}
StopTimeInstance prevStopTimeInstance = new StopTimeInstance(prevStopTime, state);
ArrivalAndDepartureInstance prevInstance = new ArrivalAndDepartureInstance(prevStopTimeInstance, scheduledTime);
if (instance.isPredictedArrivalTimeSet()) {
int scheduledDeviation = (int) ((instance.getPredictedArrivalTime() - instance.getScheduledArrivalTime()) / 1000);
int departureDeviation = propagateScheduleDeviationBackwardBetweenStops(prevStopTime, stopTime, scheduledDeviation);
int arrivalDeviation = propagateScheduleDeviationBackwardAcrossStop(prevStopTime, departureDeviation);
setPredictedArrivalTimeForInstance(prevInstance, prevInstance.getScheduledArrivalTime() + arrivalDeviation * 1000);
setPredictedDepartureTimeForInstance(prevInstance, prevInstance.getScheduledDepartureTime() + departureDeviation * 1000);
}
return prevInstance;
}
use of org.onebusaway.transit_data_federation.services.blocks.InstanceState in project onebusaway-application-modules by camsys.
the class StopScheduleBeanServiceImpl method groupFrequencyInstancesByRouteCollectionId.
private void groupFrequencyInstancesByRouteCollectionId(StopEntry stopEntry, ServiceDate date, Map<AgencyAndId, List<StopTimeInstance>> frequenciesByRouteCollectionId) {
for (FrequencyBlockStopTimeIndex index : _blockIndexService.getFrequencyStopTimeIndicesForStop(stopEntry)) {
ServiceIdActivation serviceIds = index.getServiceIds();
Set<ServiceDate> serviceDates = _calendarService.getServiceDatesForServiceIds(serviceIds);
if (!serviceDates.contains(date))
continue;
Date serviceDate = date.getAsDate(serviceIds.getTimeZone());
for (FrequencyBlockStopTimeEntry entry : index.getFrequencyStopTimes()) {
BlockStopTimeEntry stopTime = entry.getStopTime();
BlockTripEntry blockTrip = stopTime.getTrip();
TripEntry trip = blockTrip.getTrip();
AgencyAndId routeCollectionId = trip.getRouteCollection().getId();
InstanceState state = new InstanceState(serviceDate.getTime(), entry.getFrequency());
StopTimeInstance sti = new StopTimeInstance(stopTime, state);
frequenciesByRouteCollectionId.get(routeCollectionId).add(sti);
}
}
}
Aggregations