Search in sources :

Example 16 with StopTimeEntry

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

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

the class AgencyServiceImpl method getAgencyIdsAndCoverageAreas.

@Cacheable
public Map<String, CoordinateBounds> getAgencyIdsAndCoverageAreas() {
    Map<String, CoordinateBounds> boundsByAgencyId = new HashMap<String, CoordinateBounds>();
    for (AgencyEntry agency : _graph.getAllAgencies()) {
        CoordinateBounds bounds = new CoordinateBounds();
        for (RouteCollectionEntry routeCollection : agency.getRouteCollections()) {
            for (RouteEntry route : routeCollection.getChildren()) {
                for (TripEntry trip : route.getTrips()) {
                    for (StopTimeEntry stopTime : trip.getStopTimes()) {
                        StopEntry stop = stopTime.getStop();
                        bounds.addPoint(stop.getStopLat(), stop.getStopLon());
                    }
                }
            }
        }
        boundsByAgencyId.put(agency.getId(), bounds);
    }
    return boundsByAgencyId;
}
Also used : RouteEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry) HashMap(java.util.HashMap) StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) RouteCollectionEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteCollectionEntry) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds) AgencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.AgencyEntry) Cacheable(org.onebusaway.container.cache.Cacheable)

Example 18 with StopTimeEntry

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

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

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

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