Search in sources :

Example 6 with StopTimeEntry

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

the class BlockLocationServiceImpl method isLastPrediction.

/**
 * @param stopTime is the current stop
 * @param timepointPredictions is the all time-point predictions in the block
 * @param timepointPredictionRecord is the current tpr for the stop
 * @param index is the index of the current tpr in timepointPredictions
 * @return return true if the given tpr is the last prediction for the trip
 */
private boolean isLastPrediction(StopTimeEntry stopTime, List<TimepointPredictionRecord> timepointPredictions, TimepointPredictionRecord timepointPredictionRecord, int index) {
    List<StopTimeEntry> stopTimes = stopTime.getTrip().getStopTimes();
    AgencyAndId lastStopId = stopTimes.get(stopTimes.size() - 1).getStop().getId();
    if (lastStopId.equals(timepointPredictionRecord.getTimepointId()) && stopTime.getTrip().getId().equals(timepointPredictionRecord.getTripId())) {
        return index + 1 == timepointPredictions.size() || (index < timepointPredictions.size() && !timepointPredictions.get(index + 1).getTripId().equals(timepointPredictionRecord.getTripId()));
    }
    return false;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Example 7 with StopTimeEntry

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

the class BlockLocationServiceImpl method isFirstOrLastStopInTrip.

/**
 * @param stopTime
 * @return true if the given stop is the first or the last stop in given trip
 */
private boolean isFirstOrLastStopInTrip(StopTimeEntry stopTime) {
    List<StopTimeEntry> stopTimes = stopTime.getTrip().getStopTimes();
    AgencyAndId firstStopId = stopTimes.get(0).getStop().getId();
    AgencyAndId lastStopId = stopTimes.get(stopTimes.size() - 1).getStop().getId();
    AgencyAndId currentStopId = stopTime.getStop().getId();
    return firstStopId.equals(currentStopId) || lastStopId.equals(currentStopId);
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Example 8 with StopTimeEntry

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

the class ScheduledBlockLocationServiceImpl method getScheduledBlockLocationFromDistanceAlongBlockAndStopTimeIndex.

/**
 **
 * Private Methods
 ***
 */
private ScheduledBlockLocation getScheduledBlockLocationFromDistanceAlongBlockAndStopTimeIndex(List<BlockStopTimeEntry> stopTimes, double distanceAlongBlock, int stopTimeIndex) {
    int n = stopTimes.size();
    // Are we out beyond our last stop-time?
    if (stopTimeIndex == n) {
        // If we only have one stop time, we can't interpolate the schedule time
        if (n == 1)
            return null;
        BlockStopTimeEntry blockFrom = stopTimes.get(n - 2);
        BlockStopTimeEntry blockTo = stopTimes.get(n - 1);
        if (n == 2)
            return interpolateLocation(blockFrom, blockTo, distanceAlongBlock, stopTimeIndex);
        BlockStopTimeEntry previousBlock = stopTimes.get(n - 3);
        return interpolateLocation(previousBlock, blockFrom, blockTo, distanceAlongBlock, stopTimeIndex);
    }
    // Are we before out first stop-time?
    if (stopTimeIndex == 0) {
        // If we only have one stop time, we can't interpolate the schedule time
        if (n == 1)
            return null;
        BlockStopTimeEntry blockFrom = stopTimes.get(0);
        BlockStopTimeEntry blockTo = stopTimes.get(1);
        return interpolateLocation(blockFrom, blockTo, distanceAlongBlock, stopTimeIndex);
    }
    BlockStopTimeEntry blockBefore = stopTimes.get(stopTimeIndex - 1);
    BlockStopTimeEntry blockAfter = stopTimes.get(stopTimeIndex);
    StopTimeEntry before = blockBefore.getStopTime();
    StopTimeEntry after = blockAfter.getStopTime();
    double ratio = (distanceAlongBlock - blockBefore.getDistanceAlongBlock()) / (blockAfter.getDistanceAlongBlock() - blockBefore.getDistanceAlongBlock());
    int scheduleTime = (int) (before.getDepartureTime() + (after.getArrivalTime() - before.getDepartureTime()) * ratio);
    return getScheduledBlockLocationFromScheduleTimeAndStopTimeIndex(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) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Example 9 with StopTimeEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry 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 10 with StopTimeEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry 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)

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