Search in sources :

Example 26 with BlockStopTimeEntry

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

the class BlockSequenceIndex method toString.

@Override
public String toString() {
    BlockSequence first = _sequences.get(0);
    BlockConfigurationEntry blockConfig = first.getBlockConfig();
    BlockEntry block = blockConfig.getBlock();
    List<BlockStopTimeEntry> bsts = first.getStopTimes();
    BlockStopTimeEntry firstBst = bsts.get(0);
    BlockStopTimeEntry lastBst = bsts.get(bsts.size() - 1);
    StopEntry fromStop = firstBst.getStopTime().getStop();
    StopEntry toStop = lastBst.getStopTime().getStop();
    return "BlockSequenceIndex [ex: block=" + block.getId() + " fromStop=" + fromStop.getId() + " toStop=" + toStop.getId() + " serviceIds=" + getServiceIds() + "]";
}
Also used : BlockSequence(org.onebusaway.transit_data_federation.impl.blocks.BlockSequence) BlockEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Example 27 with BlockStopTimeEntry

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

the class ArrivalAndDepartureTime method getScheduledTime.

public static ArrivalAndDepartureTime getScheduledTime(long serviceDate, BlockStopTimeEntry blockStopTime, int offset) {
    if (blockStopTime == null) {
        _log.error("blockStopTime is null");
        return null;
    }
    StopTimeEntry stopTime = blockStopTime.getStopTime();
    long arrivalTime = serviceDate + (stopTime.getArrivalTime() + offset) * 1000;
    long departureTime = serviceDate + (stopTime.getDepartureTime() + offset) * 1000;
    return new ArrivalAndDepartureTime(arrivalTime, departureTime);
}
Also used : StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Example 28 with BlockStopTimeEntry

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

the class ArrivalAndDepartureServiceImpl method computePredictedDepartureTimeInterval.

private TimeIntervalBean computePredictedDepartureTimeInterval(ArrivalAndDepartureInstance instance, BlockLocation blockLocation, long targetTime) {
    BlockStopTimeEntry blockStopTime = instance.getBlockStopTime();
    StopTimeEntry stopTime = blockStopTime.getStopTime();
    // interval
    if (stopTime.getDepartureTime() <= blockLocation.getEffectiveScheduleTime())
        return null;
    ScheduleDeviationSamples samples = blockLocation.getScheduleDeviations();
    if (samples == null || samples.isEmpty())
        return null;
    double mu = InterpolationLibrary.interpolate(samples.getScheduleTimes(), samples.getScheduleDeviationMus(), stopTime.getDepartureTime(), EOutOfRangeStrategy.LAST_VALUE, EInRangeStrategy.INTERPOLATE);
    double sigma = InterpolationLibrary.interpolate(samples.getScheduleTimes(), samples.getScheduleDeviationSigmas(), stopTime.getDepartureTime(), EOutOfRangeStrategy.LAST_VALUE, EInRangeStrategy.INTERPOLATE);
    long from = (long) (instance.getScheduledDepartureTime() + (mu - sigma) * 1000);
    long to = (long) (instance.getScheduledDepartureTime() + (mu + sigma) * 1000);
    return new TimeIntervalBean(from, to);
}
Also used : StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) ScheduleDeviationSamples(org.onebusaway.transit_data_federation.services.realtime.ScheduleDeviationSamples) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) TimeIntervalBean(org.onebusaway.transit_data.model.TimeIntervalBean)

Example 29 with BlockStopTimeEntry

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

the class ArrivalAndDepartureServiceImpl method getBlockStopTime.

private BlockStopTimeEntry getBlockStopTime(BlockTripInstance blockTripInstance, AgencyAndId stopId, int stopSequence, int timeOfServiceDate) {
    /**
     * We don't iterate over block stop times directly because there is
     * performance penalty with instantiating each. Also note that this will
     * currently miss the case where a stop is visited twice in the same trip.
     */
    BlockTripEntry blockTrip = blockTripInstance.getBlockTrip();
    TripEntry trip = blockTrip.getTrip();
    List<StopTimeEntry> stopTimes = trip.getStopTimes();
    if (stopSequence > -1) {
        /**
         * If a stop sequence has been specified, we start our search at the
         * specified index, expanding our search until we find the target stop. We
         * allow this flexibility in the case of a bookmarked arrival-departure
         * where the stop sequence has changed slightly due to the addition or
         * subtraction of a previous stop.
         */
        int offset = 0;
        while (true) {
            int before = stopSequence - offset;
            if (isMatch(stopTimes, stopId, before)) {
                return blockTrip.getStopTimes().get(before);
            }
            int after = stopSequence + offset;
            if (isMatch(stopTimes, stopId, after)) {
                return blockTrip.getStopTimes().get(after);
            }
            if (before < 0 && after >= stopTimes.size())
                return null;
            offset++;
        }
    } else {
        Min<BlockStopTimeEntry> m = new Min<BlockStopTimeEntry>();
        int index = 0;
        for (StopTimeEntry stopTime : stopTimes) {
            if (stopTime.getStop().getId().equals(stopId)) {
                int a = Math.abs(timeOfServiceDate - stopTime.getArrivalTime());
                int b = Math.abs(timeOfServiceDate - stopTime.getDepartureTime());
                int delta = Math.min(a, b);
                m.add(delta, blockTrip.getStopTimes().get(index));
            }
            index++;
        }
        if (m.isEmpty())
            return null;
        return m.getMinElement();
    }
}
Also used : Min(org.onebusaway.collections.Min) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) 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 30 with BlockStopTimeEntry

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

the class ArrivalAndDepartureServiceImpl method setPredictedTimesFromTimepointPredictionRecords.

private boolean setPredictedTimesFromTimepointPredictionRecords(ArrivalAndDepartureInstance instance, BlockLocation blockLocation, long targetTime) {
    List<TimepointPredictionRecord> records = blockLocation.getTimepointPredictions();
    if (records == null)
        return false;
    // Find the right timepoint prediction record. We need to make sure that
    // there are the proper number of records if the trip loops and stopSequence
    // is not set.
    int stopSequence = instance.getBlockStopTime().getStopTime().getSequence();
    int gtfsSequence = instance.getBlockStopTime().getStopTime().getGtfsSequence();
    int totalCandidates = 0;
    // index (with respect to stop sequence) among stops
    int thisStopIndex = 0;
    // with the same ID
    List<BlockStopTimeEntry> stopTimes = instance.getBlockTrip().getStopTimes();
    for (int i = 0; i < stopTimes.size(); i++) {
        BlockStopTimeEntry stopTime = stopTimes.get(i);
        StopTimeEntry stop = stopTime.getStopTime();
        if (stop.getStop().getId().equals(instance.getStop().getId())) {
            totalCandidates++;
            if (stop.getSequence() < stopSequence)
                thisStopIndex++;
        }
    }
    int tprTotalCandidates = 0;
    int tprStopIndex = 0;
    boolean success = false;
    for (TimepointPredictionRecord tpr : records) {
        boolean tripMatches = tpr.getTripId().equals(instance.getBlockTrip().getTrip().getId());
        boolean stopMatches = tpr.getTimepointId().equals(instance.getStop().getId());
        boolean sequenceMatches = tpr.getStopSequence() > 0 && tpr.getStopSequence() == gtfsSequence;
        if (!tripMatches || !stopMatches)
            continue;
        if (sequenceMatches || tprStopIndex == thisStopIndex) {
            success = true;
            long arrivalTime = tpr.getTimepointPredictedArrivalTime();
            long departureTime = tpr.getTimepointPredictedDepartureTime();
            if (departureTime <= 0) {
                int slack = instance.getBlockStopTime().getStopTime().getSlackTime();
                departureTime = arrivalTime + slack * 1000;
            }
            setPredictedDepartureTimeForInstance(instance, departureTime);
            /*
         * if arrivalTime is -1 be polite to clients and serve departureTime
         */
            if (arrivalTime == -1) {
                setPredictedArrivalTimeForInstance(instance, departureTime);
            } else {
                setPredictedArrivalTimeForInstance(instance, arrivalTime);
            }
            if (sequenceMatches)
                return true;
        } else if (tprStopIndex < thisStopIndex)
            tprStopIndex++;
        tprTotalCandidates++;
    }
    if (success && totalCandidates == tprTotalCandidates && tprStopIndex == thisStopIndex)
        return true;
    // Clear out prediction times if we didn't end up finding the proper number
    // of records
    setPredictedArrivalTimeForInstance(instance, 0);
    setPredictedDepartureTimeForInstance(instance, 0);
    return false;
}
Also used : StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) TimepointPredictionRecord(org.onebusaway.realtime.api.TimepointPredictionRecord) 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