Search in sources :

Example 31 with BlockStopTimeEntry

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);
    }
}
Also used : ArrivalAndDepartureInstance(org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Example 32 with BlockStopTimeEntry

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);
}
Also used : InstanceState(org.onebusaway.transit_data_federation.services.blocks.InstanceState) ArrivalAndDepartureTime(org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureTime) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Example 33 with BlockStopTimeEntry

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;
}
Also used : StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Example 34 with BlockStopTimeEntry

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);
}
Also used : BlockTripInstance(org.onebusaway.transit_data_federation.services.blocks.BlockTripInstance) StopTimeInstance(org.onebusaway.transit_data_federation.model.StopTimeInstance) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Example 35 with BlockStopTimeEntry

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;
}
Also used : StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Aggregations

BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)71 StopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry)32 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)29 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)23 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)20 StopTimeInstance (org.onebusaway.transit_data_federation.model.StopTimeInstance)16 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)15 ArrayList (java.util.ArrayList)14 FrequencyBlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry)14 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)11 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)11 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)10 ScheduledBlockLocation (org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation)9 ArrivalAndDepartureInstance (org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance)9 Date (java.util.Date)8 BlockEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl)8 InstanceState (org.onebusaway.transit_data_federation.services.blocks.InstanceState)8 BlockLocation (org.onebusaway.transit_data_federation.services.realtime.BlockLocation)8 BlockStopTimeIndex (org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex)7 FrequencyBlockStopTimeIndex (org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex)7