Search in sources :

Example 11 with BlockStopTimeEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry in project onebusaway-application-modules by camsys.

the class ScheduledBlockLocationServiceImpl method getScheduledBlockLocationBeforeStartOfBlock.

private ScheduledBlockLocation getScheduledBlockLocationBeforeStartOfBlock(List<BlockStopTimeEntry> stopTimes, int scheduleTime) {
    /**
     * The first block stop time
     */
    BlockStopTimeEntry blockStopTime = stopTimes.get(0);
    StopTimeEntry stopTime = blockStopTime.getStopTime();
    double distanceAlongBlock = Double.NaN;
    boolean inService = false;
    /**
     * If we have more than one stop time in the block (we'd hope!), then we
     * attempt to interpolate the distance along the block
     */
    if (stopTimes.size() > 1) {
        BlockStopTimeEntry secondBlockStopTime = stopTimes.get(1);
        StopTimeEntry secondStopTime = secondBlockStopTime.getStopTime();
        distanceAlongBlock = InterpolationLibrary.interpolatePair(stopTime.getDepartureTime(), blockStopTime.getDistanceAlongBlock(), secondStopTime.getArrivalTime(), secondBlockStopTime.getDistanceAlongBlock(), scheduleTime);
        if (distanceAlongBlock >= 0)
            inService = true;
        else
            distanceAlongBlock = 0.0;
    }
    PointAndOrientation po = null;
    if (!Double.isNaN(distanceAlongBlock))
        po = getLocationAlongShape(blockStopTime.getTrip(), distanceAlongBlock, 0, nextShapePointIndex(stopTime));
    ScheduledBlockLocation result = new ScheduledBlockLocation();
    if (po != null) {
        result.setLocation(po.getPoint());
        result.setOrientation(po.getOrientation());
    }
    result.setClosestStop(blockStopTime);
    result.setClosestStopTimeOffset(stopTime.getArrivalTime() - scheduleTime);
    result.setPreviousStop(null);
    result.setNextStop(blockStopTime);
    result.setNextStopTimeOffset(stopTime.getArrivalTime() - scheduleTime);
    result.setScheduledTime(scheduleTime);
    result.setDistanceAlongBlock(distanceAlongBlock);
    result.setActiveTrip(blockStopTime.getTrip());
    result.setInService(inService);
    result.setStopTimeIndex(0);
    return result;
}
Also used : ScheduledBlockLocation(org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) PointAndOrientation(org.onebusaway.transit_data_federation.impl.shapes.PointAndOrientation) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Example 12 with BlockStopTimeEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry in project onebusaway-application-modules by camsys.

the class BlockIndexFactoryServiceImpl method computeDirectionOfTravel.

private double computeDirectionOfTravel(List<BlockStopTimeEntry> bsts) {
    BlockStopTimeEntry fromBst = bsts.get(0);
    BlockStopTimeEntry toBst = bsts.get(bsts.size() - 1);
    StopEntry fromStop = fromBst.getStopTime().getStop();
    StopEntry toStop = toBst.getStopTime().getStop();
    return SphericalGeometryLibrary.getOrientation(fromStop.getStopLat(), fromStop.getStopLon(), toStop.getStopLat(), toStop.getStopLon());
}
Also used : StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Example 13 with BlockStopTimeEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry in project onebusaway-application-modules by camsys.

the class BlockIndexFactoryServiceImpl method getBlockStopTimesAsBlockInterval.

/**
 **
 *
 ***
 */
private <T extends HasBlockStopTimes> ServiceIntervalBlock getBlockStopTimesAsBlockInterval(List<T> entries) {
    int n = entries.size();
    int[] minArrivals = new int[n];
    int[] minDepartures = new int[n];
    int[] maxArrivals = new int[n];
    int[] maxDepartures = new int[n];
    int index = 0;
    for (T entry : entries) {
        ServiceInterval interval = null;
        List<BlockStopTimeEntry> stopTimes = entry.getStopTimes();
        StopTimeEntry first = stopTimes.get(0).getStopTime();
        StopTimeEntry last = stopTimes.get(stopTimes.size() - 1).getStopTime();
        interval = extend(interval, first);
        interval = extend(interval, last);
        minArrivals[index] = interval.getMinArrival();
        minDepartures[index] = interval.getMinDeparture();
        maxArrivals[index] = interval.getMaxArrival();
        maxDepartures[index] = interval.getMaxDeparture();
        index++;
    }
    return new ServiceIntervalBlock(minArrivals, minDepartures, maxArrivals, maxDepartures);
}
Also used : ServiceIntervalBlock(org.onebusaway.transit_data_federation.services.blocks.ServiceIntervalBlock) FrequencyServiceIntervalBlock(org.onebusaway.transit_data_federation.services.blocks.FrequencyServiceIntervalBlock) StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) ServiceInterval(org.onebusaway.gtfs.model.calendar.ServiceInterval) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Example 14 with BlockStopTimeEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry in project onebusaway-application-modules by camsys.

the class BlockIndexFactoryServiceImpl method areBlockTripsContinuous.

private boolean areBlockTripsContinuous(BlockTripEntry prevBlockTrip, BlockTripEntry nextBlockTrip) {
    List<BlockStopTimeEntry> prevStopTimes = prevBlockTrip.getStopTimes();
    List<BlockStopTimeEntry> nextStopTimes = nextBlockTrip.getStopTimes();
    BlockStopTimeEntry from = prevStopTimes.get(prevStopTimes.size() - 1);
    BlockStopTimeEntry to = nextStopTimes.get(0);
    int slack = to.getAccumulatedSlackTime() - (from.getAccumulatedSlackTime() + from.getStopTime().getSlackTime());
    int schedTime = to.getStopTime().getArrivalTime() - from.getStopTime().getDepartureTime();
    /**
     * If the slack time is too much, the trips are not continuous
     */
    if (slack >= _maxSlackBetweenConsecutiveTrips)
        return false;
    /**
     * If the sched time is too much, the trips are not continuous
     */
    if (schedTime >= _maxScheduledTimeBetweenConsecutiveTrips)
        return false;
    TripEntry prevTrip = prevBlockTrip.getTrip();
    TripEntry nextTrip = nextBlockTrip.getTrip();
    AgencyAndId lineIdA = prevTrip.getRouteCollection().getId();
    AgencyAndId lineIdB = nextTrip.getRouteCollection().getId();
    String directionA = prevTrip.getDirectionId();
    String directionB = nextTrip.getDirectionId();
    /**
     * If the route has not changed, but the direction has, the trips are not
     * continuous
     */
    if (lineIdA.equals(lineIdB) && (directionA == null || !directionA.equals(directionB)))
        return false;
    double prevOrientation = computeDirectionOfTravel(prevStopTimes);
    double nextOrientation = computeDirectionOfTravel(nextStopTimes);
    double delta = GeometryLibrary.getAngleDifference(prevOrientation, nextOrientation);
    return true;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Example 15 with BlockStopTimeEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry in project onebusaway-application-modules by camsys.

the class BlockStopTimeIndicesFactory method createFrequencyBlockStopTimeIndexForGroup.

private FrequencyBlockStopTimeIndex createFrequencyBlockStopTimeIndexForGroup(List<FrequencyBlockStopTimeEntry> group) {
    int n = group.size();
    List<FrequencyEntry> frequencies = new ArrayList<FrequencyEntry>(n);
    List<BlockConfigurationEntry> blockConfigs = new ArrayList<BlockConfigurationEntry>(n);
    int[] stopIndices = new int[n];
    ServiceInterval interval = null;
    for (int i = 0; i < n; i++) {
        FrequencyBlockStopTimeEntry frequencyBlockStopTime = group.get(i);
        FrequencyEntry frequency = frequencyBlockStopTime.getFrequency();
        frequencies.add(frequency);
        BlockStopTimeEntry blockStopTime = frequencyBlockStopTime.getStopTime();
        blockConfigs.add(blockStopTime.getTrip().getBlockConfiguration());
        stopIndices[i] = blockStopTime.getBlockSequence();
        interval = ServiceInterval.extend(interval, frequency.getStartTime(), frequency.getStartTime());
        interval = ServiceInterval.extend(interval, frequency.getEndTime(), frequency.getEndTime());
    }
    return new FrequencyBlockStopTimeIndex(frequencies, blockConfigs, stopIndices, interval);
}
Also used : ServiceInterval(org.onebusaway.gtfs.model.calendar.ServiceInterval) FrequencyBlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex) ArrayList(java.util.ArrayList) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) FrequencyBlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry) FrequencyBlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry)

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