Search in sources :

Example 46 with StopTimeEntry

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

the class ScheduledBlockLocationServiceImpl method getScheduledBlockLocationFromScheduleTimeAndStopTimeIndex.

private ScheduledBlockLocation getScheduledBlockLocationFromScheduleTimeAndStopTimeIndex(List<BlockStopTimeEntry> stopTimes, int scheduleTime, int stopTimeIndex) {
    // Did we have a direct hit?
    if (0 <= stopTimeIndex && stopTimeIndex < stopTimes.size()) {
        BlockStopTimeEntry blockStopTime = stopTimes.get(stopTimeIndex);
        StopTimeEntry stopTime = blockStopTime.getStopTime();
        BlockStopTimeEntry previousBlockStopTime = null;
        if (stopTimeIndex > 0) {
            previousBlockStopTime = stopTimes.get(stopTimeIndex - 1);
        }
        /**
         * Is the vehicle currently at a layover at the stop?
         */
        if (stopTime.getArrivalTime() <= scheduleTime && scheduleTime <= stopTime.getDepartureTime()) {
            return getScheduledBlockLocationWhenAtStopTime(blockStopTime, previousBlockStopTime, stopTime, scheduleTime, stopTimeIndex);
        }
    }
    /**
     * If the stopTimeIndex is zero, and we weren't at a layover at the first
     * block stop time (see above), then we are looking for the scheduled
     * location before the scheduled start of the block
     */
    if (stopTimeIndex == 0) {
        return getScheduledBlockLocationBeforeStartOfBlock(stopTimes, scheduleTime);
    }
    /**
     * If the stopTimeIndex is beyond the last stop time, we don't attempt to
     * determine a scheduled location, since we're beyond the end of the block
     */
    if (stopTimeIndex == stopTimes.size()) {
        // Out of bounds for these stop times
        return null;
    }
    return getScheduledBlockLocationBetweenStopTimes(stopTimes, scheduleTime, stopTimeIndex);
}
Also used : BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Example 47 with StopTimeEntry

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

the class ScheduledBlockLocationServiceImpl method interpolateLocation.

private ScheduledBlockLocation interpolateLocation(BlockStopTimeEntry blockPrevious, BlockStopTimeEntry blockFrom, BlockStopTimeEntry blockTo, double distanceAlongBlock, int stopTimeIndex) {
    if (distanceAlongBlock < 0.0)
        return null;
    StopTimeEntry from = blockFrom.getStopTime();
    StopTimeEntry to = blockTo.getStopTime();
    double r = (distanceAlongBlock - blockFrom.getDistanceAlongBlock()) / (blockTo.getDistanceAlongBlock() - blockFrom.getDistanceAlongBlock());
    int scheduledTime = (int) (r * (to.getArrivalTime() - from.getDepartureTime()) + from.getDepartureTime());
    if (r > 1)
        scheduledTime += to.getSlackTime();
    BlockTripEntry activeTrip = distanceAlongBlock < blockTo.getDistanceAlongBlock() ? blockFrom.getTrip() : blockTo.getTrip();
    BlockStopTimeEntry closestStop = r < 0.5 ? blockFrom : blockTo;
    BlockStopTimeEntry previousStop = null;
    BlockStopTimeEntry nextStop = null;
    int shapePointIndexFrom = -1;
    int shapePointIndexTo = -1;
    if (r <= 0) {
        /**
         * Location along the block is before the two stop times
         */
        previousStop = blockPrevious;
        nextStop = blockFrom;
        shapePointIndexFrom = 0;
        shapePointIndexTo = nextShapePointIndex(from);
    } else if (r <= 1.0) {
        /**
         * Location along the block is between the two stop times
         */
        previousStop = blockFrom;
        nextStop = blockTo;
        shapePointIndexFrom = from.getShapePointIndex();
        shapePointIndexTo = nextShapePointIndex(to);
    } else {
        /**
         * Location along the block is after the two stop times
         */
        shapePointIndexFrom = to.getShapePointIndex();
        shapePointIndexTo = Integer.MAX_VALUE;
    }
    ScheduledBlockLocation location = new ScheduledBlockLocation();
    location.setActiveTrip(activeTrip);
    location.setClosestStop(closestStop);
    location.setClosestStopTimeOffset(closestStop.getStopTime().getArrivalTime() - scheduledTime);
    location.setPreviousStop(previousStop);
    location.setNextStop(nextStop);
    if (nextStop != null)
        location.setNextStopTimeOffset(nextStop.getStopTime().getArrivalTime() - scheduledTime);
    location.setInService(nextStop != null);
    location.setStopTimeIndex(stopTimeIndex);
    location.setDistanceAlongBlock(distanceAlongBlock);
    location.setScheduledTime(scheduledTime);
    /**
     * In this case, distance along block and distance along trip are the same
     * because we are still in the first trip of the block
     */
    PointAndOrientation po = getLocationAlongShape(activeTrip, distanceAlongBlock, shapePointIndexFrom, shapePointIndexTo);
    if (po != null) {
        location.setLocation(po.getPoint());
        location.setOrientation(po.getOrientation());
    }
    return location;
}
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) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) PointAndOrientation(org.onebusaway.transit_data_federation.impl.shapes.PointAndOrientation) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Example 48 with StopTimeEntry

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

the class BlockStopTimeIndicesFactory method getBlockStopTimeAsKey.

private BlockStopTimeKey getBlockStopTimeAsKey(BlockStopTimeEntry blockStopTime) {
    BlockTripEntry blockTrip = blockStopTime.getTrip();
    BlockConfigurationEntry blockConfig = blockTrip.getBlockConfiguration();
    StopTimeEntry stopTime = blockStopTime.getStopTime();
    StopEntry stop = stopTime.getStop();
    return new BlockStopTimeKey(blockConfig.getServiceIds(), stop.getId());
}
Also used : BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) FrequencyBlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)

Example 49 with StopTimeEntry

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

the class BlockStopTimeStrictComparator method compare.

@Override
public int compare(BlockStopTimeEntry o1, BlockStopTimeEntry o2) {
    StopTimeEntry stA = o1.getStopTime();
    StopTimeEntry stB = o2.getStopTime();
    if (stA.getArrivalTime() == stB.getArrivalTime() && stA.getDepartureTime() == stB.getDepartureTime()) {
        return 0;
    } else if (stA.getArrivalTime() <= stB.getArrivalTime() && stA.getDepartureTime() <= stB.getDepartureTime()) {
        return -1;
    }
    return 1;
}
Also used : StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Example 50 with StopTimeEntry

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

the class BlockTripLayoverTimeComparator method getLayoverEndTimeForTrip.

public static int getLayoverEndTimeForTrip(BlockTripEntry blockTrip) {
    List<BlockStopTimeEntry> stopTimes = blockTrip.getStopTimes();
    BlockStopTimeEntry blockStopTime = stopTimes.get(0);
    StopTimeEntry stopTime = blockStopTime.getStopTime();
    return stopTime.getArrivalTime();
}
Also used : StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Aggregations

StopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry)50 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)40 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)18 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)15 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)15 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)12 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)10 ArrayList (java.util.ArrayList)6 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)6 ServiceInterval (org.onebusaway.gtfs.model.calendar.ServiceInterval)4 TimepointPredictionRecord (org.onebusaway.realtime.api.TimepointPredictionRecord)4 RouteEntry (org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry)4 HashMap (java.util.HashMap)3 Min (org.onebusaway.collections.Min)3 Cacheable (org.onebusaway.container.cache.Cacheable)3 StopBean (org.onebusaway.transit_data.model.StopBean)3 PointAndOrientation (org.onebusaway.transit_data_federation.impl.shapes.PointAndOrientation)3 ScheduledBlockLocation (org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation)3 HashSet (java.util.HashSet)2 TimeIntervalBean (org.onebusaway.transit_data.model.TimeIntervalBean)2