Search in sources :

Example 41 with TripEntry

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

the class ScheduledServiceServiceImpl method stopHasUpcomingScheduledService.

@Override
public Boolean stopHasUpcomingScheduledService(String stopAgencyId, long time, String stopId, String routeId, String directionId) {
    AgencyAndId stopAndId = null;
    if (stopId != null && stopId.contains("_"))
        stopAndId = AgencyAndIdLibrary.convertFromString(stopId);
    else if (stopId != null)
        stopAndId = new AgencyAndId(stopAgencyId, stopId);
    StopEntry stopEntry = _transitGraphDao.getStopEntryForId(stopAndId);
    if (stopEntry == null) {
        return null;
    }
    Date serviceStart = new Date(time - SCHEDULE_WINDOW_BEFORE);
    Date serviceEnd = new Date(time + SCHEDULE_WINDOW_AFTER);
    List<StopTimeInstance> stis = _stopTimeService.getStopTimeInstancesInTimeRange(stopEntry, serviceStart, serviceEnd, EFrequencyStopTimeBehavior.INCLUDE_UNSPECIFIED);
    if (stis.isEmpty()) {
        return false;
    }
    for (StopTimeInstance stopTime : stis) {
        BlockTripEntry blockTripEntry = stopTime.getTrip();
        TripEntry tripEntry = blockTripEntry.getTrip();
        if (tripEntry.getRoute().getId().toString().equals(routeId)) {
            if (tripEntry.getDirectionId() == null || tripEntry.getDirectionId().equals(directionId)) {
                return true;
            }
        }
    }
    return false;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) StopTimeInstance(org.onebusaway.transit_data_federation.model.StopTimeInstance) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) Date(java.util.Date)

Example 42 with TripEntry

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

the class ScheduledServiceServiceImpl method stopHasRevenueServiceOnRoute.

@Override
public Boolean stopHasRevenueServiceOnRoute(String agencyId, String stopId, String routeId, String directionId) {
    AgencyAndId stopAndId = null;
    if (stopId != null && stopId.contains("_"))
        stopAndId = AgencyAndIdLibrary.convertFromString(stopId);
    else if (stopId != null)
        stopAndId = new AgencyAndId(agencyId, stopId);
    StopEntry stopEntry = _transitGraphDao.getStopEntryForId(stopAndId);
    List<BlockStopTimeIndex> stopTimeIndicesForStop = _blockIndexService.getStopTimeIndicesForStop(stopEntry);
    for (BlockStopTimeIndex bsti : stopTimeIndicesForStop) {
        List<BlockStopTimeEntry> stopTimes = bsti.getStopTimes();
        for (BlockStopTimeEntry bste : stopTimes) {
            StopTimeEntry stopTime = bste.getStopTime();
            TripEntry theTrip = stopTime.getTrip();
            if (routeId != null && !theTrip.getRoute().getId().toString().equals(routeId)) {
                continue;
            }
            if (directionId != null && theTrip.getDirectionId() != null) {
                if (!theTrip.getDirectionId().equals(directionId)) {
                    continue;
                }
            }
            /*
               * If at least one stoptime on one trip (subject to the
               * route and direction filters above) permits unrestricted
               * pick-up or drop-off at this stop (type=0), then it is
               * considered a 'revenue' stop.
               */
            if (stopTime.getDropOffType() == 0 || stopTime.getPickupType() == 0) {
                return true;
            }
        }
    }
    return false;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) BlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) 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 43 with TripEntry

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

the class BlockConfigurationEntryImpl method getStopTimeForIndex.

/**
 ***
 * Private Methods
 ***
 */
private StopTimeEntry getStopTimeForIndex(int index) {
    int tripIndex = tripIndices[index];
    BlockTripEntry blockTrip = trips.get(tripIndex);
    TripEntry trip = blockTrip.getTrip();
    List<StopTimeEntry> stopTimes = trip.getStopTimes();
    int stopTimeIndex = index - accumulatedStopTimeIndices[tripIndex];
    StopTimeEntry stopTime = stopTimes.get(stopTimeIndex);
    return stopTime;
}
Also used : 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) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)

Example 44 with TripEntry

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

the class RealTimeHistoryServiceImpl method getScheduleDeviationHistogramForArrivalAndDepartureInstance.

@Override
public ScheduleDeviationHistogram getScheduleDeviationHistogramForArrivalAndDepartureInstance(ArrivalAndDepartureInstance instance, int stepSizeInSeconds) {
    BlockTripEntry blockTrip = instance.getBlockTrip();
    TripEntry trip = blockTrip.getTrip();
    AgencyAndId tripId = trip.getId();
    ScheduleDeviationHistory history = _scheduleDeviationHistoryDao.getScheduleDeviationHistoryForTripId(tripId);
    if (history == null)
        return null;
    BlockStopTimeEntry blockStopTime = instance.getBlockStopTime();
    StopTimeEntry stopTime = blockStopTime.getStopTime();
    double[] values = getScheduleDeviationsForScheduleTime(history, stopTime.getDepartureTime());
    return createHistogramFromValues(values, stepSizeInSeconds);
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) 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) 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 45 with TripEntry

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

the class RealTimeHistoryServiceImpl method sampleScheduleDeviationsForVehicle.

@Override
public ScheduleDeviationSamples sampleScheduleDeviationsForVehicle(BlockInstance instance, VehicleLocationRecord record, ScheduledBlockLocation scheduledBlockLocation) {
    if (scheduledBlockLocation == null)
        return null;
    BlockTripEntry blockTrip = scheduledBlockLocation.getActiveTrip();
    TripEntry trip = blockTrip.getTrip();
    ScheduleDeviationHistory history = _scheduleDeviationHistoryDao.getScheduleDeviationHistoryForTripId(trip.getId());
    if (history == null)
        return null;
    ScheduleDeviationHistory resampledHistory = resampleHistory(history, scheduledBlockLocation.getScheduledTime(), record.getScheduleDeviation());
    DoubleArrayList scheduleTimes = new DoubleArrayList();
    DoubleArrayList mus = new DoubleArrayList();
    DoubleArrayList sigmas = new DoubleArrayList();
    for (int t = 0; t <= _predictionLookahead; t += 5 * 60) {
        int scheduleTime = scheduledBlockLocation.getScheduledTime() + t;
        double[] deviations = getScheduleDeviationsForScheduleTime(resampledHistory, scheduleTime);
        deviations = noNans(deviations);
        DoubleArrayList values = new DoubleArrayList(deviations);
        double mu = Descriptive.mean(values);
        double var = Descriptive.sampleVariance(values, mu);
        double sigma = Descriptive.sampleStandardDeviation(values.size(), var);
        scheduleTimes.add(scheduleTime);
        mus.add(mu);
        sigmas.add(sigma);
    }
    scheduleTimes.trimToSize();
    mus.trimToSize();
    sigmas.trimToSize();
    return new ScheduleDeviationSamples(scheduleTimes.elements(), mus.elements(), sigmas.elements());
}
Also used : BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) ScheduleDeviationSamples(org.onebusaway.transit_data_federation.services.realtime.ScheduleDeviationSamples) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) DoubleArrayList(cern.colt.list.DoubleArrayList)

Aggregations

TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)73 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)46 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)39 ArrayList (java.util.ArrayList)20 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)18 StopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry)15 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)14 HashSet (java.util.HashSet)13 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)10 BlockEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry)10 List (java.util.List)9 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)9 Date (java.util.Date)7 Test (org.junit.Test)7 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)7 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)7 FrequencyEntry (org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry)7 Cacheable (org.onebusaway.container.cache.Cacheable)6 RouteEntry (org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry)6 ServiceIdActivation (org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation)6