use of org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry in project onebusaway-application-modules by camsys.
the class ArrivalAndDepartureServiceImpl method applyPostInterpolateForFrequencyNoSchedule.
private void applyPostInterpolateForFrequencyNoSchedule(StopTimeInstance sti, long fromTime, long toTime, long frequencyOffsetTime, BlockInstance blockInstance, List<ArrivalAndDepartureInstance> results) {
if (results == null || results.size() == 0)
return;
// Find latest instance. Prefer realtime.
ArrivalAndDepartureInstance instance = findBestArrivalAndDepartureInstance(results);
// If no realtime data, don't make extrapolations.
if (instance.getBlockLocation() == null || !instance.getBlockLocation().isPredicted())
return;
BlockStopTimeEntry bst = sti.getStopTime();
// See similar calculation in
// FrequencyBlockStopTimeEntry.getStopTimeOffset()
int d0 = bst.getTrip().getDepartureTimeForIndex(0);
int d1 = bst.getStopTime().getDepartureTime();
int stopDelta = d1 - d0;
int stopEndTime = sti.getFrequency().getEndTime() + stopDelta;
long stopEndTimeExact = sti.getServiceDate() + stopEndTime * 1000;
int headwayMs = sti.getFrequency().getHeadwaySecs() * 1000;
/*
* TODO: if start_time is available from feed we should use it over this calculation
*/
long time = instance.getBestDepartureTime();
if (time == 0)
time = instance.getBestArrivalTime();
// Do not extrapolate trips starting at the headway change:
stopEndTimeExact -= headwayMs;
// Extrapolate future stop times.
while ((time += headwayMs) < Math.min(toTime, stopEndTimeExact)) {
ArrivalAndDepartureInstance newInstance = createArrivalAndDepartureForStopTimeInstanceWithTime(sti, time);
results.add(newInstance);
}
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry 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.transit_graph.BlockStopTimeEntry in project onebusaway-application-modules by camsys.
the class ArrivalAndDepartureServiceImpl method calculateArrivalDeviation.
private int calculateArrivalDeviation(BlockStopTimeEntry nextBlockStopTime, BlockStopTimeEntry targetBlockStopTime, int effectiveScheduleTime, int scheduleDeviation) {
if (nextBlockStopTime == null || nextBlockStopTime.getBlockSequence() > targetBlockStopTime.getBlockSequence()) {
return scheduleDeviation;
}
int a = targetBlockStopTime.getAccumulatedSlackTime();
int b = nextBlockStopTime.getAccumulatedSlackTime();
double slack = a - b;
StopTimeEntry nextStopTime = nextBlockStopTime.getStopTime();
if (nextStopTime.getArrivalTime() <= effectiveScheduleTime && effectiveScheduleTime <= nextStopTime.getDepartureTime()) {
slack -= (effectiveScheduleTime - nextStopTime.getArrivalTime());
}
slack = Math.max(slack, 0);
if (slack > 0 && scheduleDeviation > 0)
scheduleDeviation -= Math.min(scheduleDeviation, slack);
return scheduleDeviation;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry in project onebusaway-application-modules by camsys.
the class ArrivalAndDepartureServiceImpl method createArrivalAndDeparture.
private ArrivalAndDepartureInstance createArrivalAndDeparture(BlockInstance blockInstance, AgencyAndId tripId, AgencyAndId stopId, int stopSequence, long serviceDate, int timeOfServiceDate, long prevFrequencyTime) {
BlockTripInstance blockTripInstance = BlockTripInstanceLibrary.getBlockTripInstance(blockInstance, tripId);
if (blockTripInstance == null)
return null;
BlockStopTimeEntry blockStopTime = getBlockStopTime(blockTripInstance, stopId, stopSequence, timeOfServiceDate);
if (blockStopTime == null) {
_log.error("block stop time is null for stopid=" + stopId + " and blockTripInstance=" + blockTripInstance + " and timeOfServiceDate=" + timeOfServiceDate);
return null;
}
StopTimeInstance stopTimeInstance = new StopTimeInstance(blockStopTime, blockTripInstance.getState());
return createArrivalAndDeparture(stopTimeInstance, prevFrequencyTime, StopTimeInstance.UNSPECIFIED_FREQUENCY_OFFSET);
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry in project onebusaway-application-modules by camsys.
the class ArrivalAndDepartureServiceImpl method calculateDepartureDeviation.
private int calculateDepartureDeviation(BlockStopTimeEntry nextBlockStopTime, BlockStopTimeEntry targetBlockStopTime, int effectiveScheduleTime, int scheduleDeviation) {
// TargetStopTime
if (nextBlockStopTime == null || nextBlockStopTime.getBlockSequence() > targetBlockStopTime.getBlockSequence()) {
return scheduleDeviation;
}
StopTimeEntry nextStopTime = nextBlockStopTime.getStopTime();
StopTimeEntry targetStopTime = targetBlockStopTime.getStopTime();
double slack = targetBlockStopTime.getAccumulatedSlackTime() - nextBlockStopTime.getAccumulatedSlackTime();
slack += targetStopTime.getSlackTime();
if (nextStopTime.getArrivalTime() <= effectiveScheduleTime && effectiveScheduleTime <= nextStopTime.getDepartureTime()) {
slack -= (effectiveScheduleTime - nextStopTime.getArrivalTime());
}
slack = Math.max(slack, 0);
if (slack > 0 && scheduleDeviation > 0)
scheduleDeviation -= Math.min(scheduleDeviation, slack);
return scheduleDeviation;
}
Aggregations