Search in sources :

Example 6 with BlockStopTimeEntry

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

the class StopTimeServiceImpl method getNextBlockSequenceDeparturesForStop.

@Override
public List<StopTimeInstance> getNextBlockSequenceDeparturesForStop(StopEntry stopEntry, long time, boolean includePrivateSerivce) {
    List<StopTimeInstance> stopTimeInstances = new ArrayList<StopTimeInstance>();
    List<BlockStopSequenceIndex> blockStopTripIndices = _blockIndexService.getStopSequenceIndicesForStop(stopEntry);
    for (BlockStopSequenceIndex index : blockStopTripIndices) {
        List<Date> serviceDates = _calendarService.getNextServiceDatesForDepartureInterval(index.getServiceIds(), index.getServiceInterval(), time);
        for (Date serviceDate : serviceDates) {
            int relativeFrom = effectiveTime(serviceDate.getTime(), time);
            int fromIndex = GenericBinarySearch.search(index, index.size(), relativeFrom, IndexAdapters.BLOCK_STOP_TIME_DEPARTURE_INSTANCE);
            if (fromIndex < index.size()) {
                BlockStopTimeEntry blockStopTime = index.getBlockStopTimeForIndex(fromIndex);
                InstanceState state = new InstanceState(serviceDate.getTime());
                StopTimeInstance sti = new StopTimeInstance(blockStopTime, state);
                stopTimeInstances.add(sti);
            }
        }
    }
    List<FrequencyBlockStopTimeIndex> frequencyIndices = _blockIndexService.getFrequencyStopTimeIndicesForStop(stopEntry);
    for (FrequencyBlockStopTimeIndex index : frequencyIndices) {
        List<Date> serviceDates = _calendarService.getNextServiceDatesForDepartureInterval(index.getServiceIds(), index.getServiceInterval(), time);
        for (Date serviceDate : serviceDates) {
            int relativeFrom = effectiveTime(serviceDate.getTime(), time);
            int fromIndex = GenericBinarySearch.search(index, index.size(), relativeFrom, IndexAdapters.FREQUENCY_END_TIME_INSTANCE);
            List<FrequencyBlockStopTimeEntry> frequencyStopTimes = index.getFrequencyStopTimes();
            if (fromIndex < index.size()) {
                FrequencyBlockStopTimeEntry entry = frequencyStopTimes.get(fromIndex);
                BlockStopTimeEntry bst = entry.getStopTime();
                FrequencyEntry frequency = entry.getFrequency();
                InstanceState state = new InstanceState(serviceDate.getTime(), frequency);
                int stopTimeOffset = entry.getStopTimeOffset();
                int frequencyOffset = computeFrequencyOffset(relativeFrom, bst, frequency, stopTimeOffset, true);
                StopTimeInstance sti = new StopTimeInstance(bst, state, frequencyOffset);
                stopTimeInstances.add(sti);
            }
        }
    }
    return stopTimeInstances;
}
Also used : StopTimeInstance(org.onebusaway.transit_data_federation.model.StopTimeInstance) FrequencyBlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex) ArrayList(java.util.ArrayList) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry) Date(java.util.Date) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) FrequencyBlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry) BlockStopSequenceIndex(org.onebusaway.transit_data_federation.services.blocks.BlockStopSequenceIndex) InstanceState(org.onebusaway.transit_data_federation.services.blocks.InstanceState) FrequencyBlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Example 7 with BlockStopTimeEntry

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

the class ArrivalsAndDeparturesBeanServiceImpl method applyBlockLocationToBean.

private void applyBlockLocationToBean(ArrivalAndDepartureInstance instance, ArrivalAndDepartureBean bean, long targetTime) {
    boolean hasFrequency = instance.getFrequency() != null;
    if (instance.isPredictedArrivalTimeSet()) {
        bean.setPredictedArrivalTime(instance.getPredictedArrivalTime());
        if (hasFrequency)
            bean.setScheduledArrivalTime(bean.getPredictedArrivalTime());
    }
    if (instance.isPredictedDepartureTimeSet()) {
        bean.setPredictedDepartureTime(instance.getPredictedDepartureTime());
        if (hasFrequency)
            bean.setScheduledDepartureTime(bean.getPredictedDepartureTime());
    }
    BlockStopTimeEntry stopTime = instance.getBlockStopTime();
    BlockLocation blockLocation = instance.getBlockLocation();
    if (blockLocation == null)
        return;
    bean.setPredicted(blockLocation.isPredicted());
    // Distance from stop
    if (blockLocation.isDistanceAlongBlockSet()) {
        double distanceFromStop = stopTime.getDistanceAlongBlock() - blockLocation.getDistanceAlongBlock();
        bean.setDistanceFromStop(distanceFromStop);
    } else {
        double distanceFromStop = stopTime.getDistanceAlongBlock() - blockLocation.getScheduledDistanceAlongBlock();
        bean.setDistanceFromStop(distanceFromStop);
    }
    // Number of stops away
    if (blockLocation.getNextStop() != null) {
        BlockStopTimeEntry nextStopTime = blockLocation.getNextStop();
        bean.setNumberOfStopsAway(stopTime.getBlockSequence() - nextStopTime.getBlockSequence());
    }
    if (blockLocation.getLastUpdateTime() > 0)
        bean.setLastUpdateTime(blockLocation.getLastUpdateTime());
    if (blockLocation.getVehicleId() != null)
        bean.setVehicleId(AgencyAndIdLibrary.convertToString(blockLocation.getVehicleId()));
    TripStatusBean tripStatusBean = _tripDetailsBeanService.getBlockLocationAsStatusBean(blockLocation, targetTime);
    bean.setTripStatus(tripStatusBean);
}
Also used : TripStatusBean(org.onebusaway.transit_data.model.trips.TripStatusBean) BlockLocation(org.onebusaway.transit_data_federation.services.realtime.BlockLocation) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Example 8 with BlockStopTimeEntry

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

the class ArrivalsAndDeparturesBeanServiceImpl method getStopTimeInstanceAsBean.

/**
 **
 * Private Methods
 ***
 */
private ArrivalAndDepartureBean getStopTimeInstanceAsBean(long time, ArrivalAndDepartureInstance instance, Map<AgencyAndId, StopBean> stopBeanCache) {
    ArrivalAndDepartureBean pab = new ArrivalAndDepartureBean();
    pab.setServiceDate(instance.getServiceDate());
    BlockStopTimeEntry blockStopTime = instance.getBlockStopTime();
    BlockTripEntry blockTrip = blockStopTime.getTrip();
    StopTimeEntry stopTime = blockStopTime.getStopTime();
    StopEntry stop = stopTime.getStop();
    TripEntry trip = stopTime.getTrip();
    TripBean tripBean = _tripBeanService.getTripForId(trip.getId());
    pab.setTrip(tripBean);
    pab.setBlockTripSequence(blockTrip.getSequence());
    pab.setArrivalEnabled(stopTime.getSequence() > 0);
    pab.setDepartureEnabled(stopTime.getSequence() + 1 < trip.getStopTimes().size());
    StopTimeNarrative stopTimeNarrative = _narrativeService.getStopTimeForEntry(stopTime);
    pab.setRouteShortName(stopTimeNarrative.getRouteShortName());
    pab.setTripHeadsign(stopTimeNarrative.getStopHeadsign());
    StopBean stopBean = stopBeanCache.get(stop.getId());
    if (stopBean == null) {
        stopBean = _stopBeanService.getStopForId(stop.getId());
        stopBeanCache.put(stop.getId(), stopBean);
    }
    pab.setStop(stopBean);
    pab.setStopSequence(stopTime.getSequence());
    pab.setTotalStopsInTrip(stopTime.getTotalStopsInTrip());
    pab.setStatus("default");
    pab.setScheduledArrivalTime(instance.getScheduledArrivalTime());
    pab.setScheduledDepartureTime(instance.getScheduledDepartureTime());
    FrequencyEntry frequency = instance.getFrequencyLabel();
    pab.setFrequency(null);
    if (frequency != null) {
        FrequencyBean fb = FrequencyBeanLibrary.getBeanForFrequency(instance.getServiceDate(), frequency);
        pab.setFrequency(fb);
    }
    return pab;
}
Also used : StopTimeNarrative(org.onebusaway.transit_data_federation.model.narrative.StopTimeNarrative) FrequencyBean(org.onebusaway.transit_data.model.schedule.FrequencyBean) 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) 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) TripBean(org.onebusaway.transit_data.model.trips.TripBean) StopBean(org.onebusaway.transit_data.model.StopBean) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry) ArrivalAndDepartureBean(org.onebusaway.transit_data.model.ArrivalAndDepartureBean) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Example 9 with BlockStopTimeEntry

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

the class ScheduledBlockLocationServiceImpl method getScheduledBlockLocationFromScheduledTime.

@Override
public ScheduledBlockLocation getScheduledBlockLocationFromScheduledTime(ScheduledBlockLocation previousLocation, int scheduleTime) {
    if (previousLocation.getScheduledTime() > scheduleTime)
        throw new IllegalStateException("previousLocation's scheduledTime must be before the requested scheduleTime");
    BlockTripEntry trip = previousLocation.getActiveTrip();
    BlockConfigurationEntry blockConfig = trip.getBlockConfiguration();
    List<BlockStopTimeEntry> stopTimes = blockConfig.getStopTimes();
    int index = previousLocation.getStopTimeIndex();
    while (index < stopTimes.size()) {
        int t = blockConfig.getDepartureTimeForIndex(index);
        if (scheduleTime <= t)
            break;
        index++;
    }
    return getScheduledBlockLocationFromScheduleTimeAndStopTimeIndex(stopTimes, scheduleTime, index);
}
Also used : BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint)

Example 10 with BlockStopTimeEntry

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

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