Search in sources :

Example 86 with BlockConfigurationEntry

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

the class BlockStatusServiceImpl method getBlockInstancesForIndexAndTimestamps.

private List<BlockInstance> getBlockInstancesForIndexAndTimestamps(BlockSequenceIndex index, List<Date> timestamps) {
    Date tFrom = timestamps.get(0);
    Date tTo = timestamps.get(timestamps.size() - 1);
    ServiceIntervalBlock serviceIntervalBlock = index.getServiceIntervalBlock();
    List<BlockSequence> sequences = index.getSequences();
    Collection<Date> serviceDates = _extendedCalendarService.getServiceDatesWithinRange(index.getServiceIds(), serviceIntervalBlock.getRange(), tFrom, tTo);
    List<BlockInstance> instances = new ArrayList<BlockInstance>();
    for (Date serviceDate : serviceDates) {
        int effectiveFromTime = (int) ((tFrom.getTime() - serviceDate.getTime()) / 1000);
        int effectiveToTime = (int) ((tTo.getTime() - serviceDate.getTime()) / 1000);
        int indexFrom = Arrays.binarySearch(serviceIntervalBlock.getMaxArrivals(), effectiveFromTime);
        int indexTo = Arrays.binarySearch(serviceIntervalBlock.getMinDepartures(), effectiveToTime);
        if (indexFrom < 0)
            indexFrom = -(indexFrom + 1);
        if (indexTo < 0)
            indexTo = -(indexTo + 1);
        InstanceState state = new InstanceState(serviceDate.getTime());
        for (int i = indexFrom; i < indexTo; i++) {
            BlockSequence sequence = sequences.get(i);
            BlockConfigurationEntry blockConfig = sequence.getBlockConfig();
            BlockInstance instance = new BlockInstance(blockConfig, state);
            instances.add(instance);
        }
    }
    return instances;
}
Also used : ServiceIntervalBlock(org.onebusaway.transit_data_federation.services.blocks.ServiceIntervalBlock) InstanceState(org.onebusaway.transit_data_federation.services.blocks.InstanceState) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) ArrayList(java.util.ArrayList) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) Date(java.util.Date) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint)

Example 87 with BlockConfigurationEntry

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

the class ScheduledBlockLocationServiceImpl method getScheduledBlockLocationFromDistanceAlongBlock.

@Override
public ScheduledBlockLocation getScheduledBlockLocationFromDistanceAlongBlock(ScheduledBlockLocation previousLocation, double distanceAlongBlock) {
    if (previousLocation.getDistanceAlongBlock() > distanceAlongBlock)
        throw new IllegalStateException("previousLocation's distanceAlongBlock must be before the requested distanceAlongBlock");
    BlockTripEntry trip = previousLocation.getActiveTrip();
    BlockConfigurationEntry blockConfig = trip.getBlockConfiguration();
    List<BlockStopTimeEntry> stopTimes = blockConfig.getStopTimes();
    int indexFrom = previousLocation.getStopTimeIndex();
    int indexTo = indexFrom + 1;
    while (indexTo < stopTimes.size()) {
        double d = blockConfig.getDistanceAlongBlockForIndex(indexTo);
        if (distanceAlongBlock <= d)
            break;
        indexTo++;
    }
    int stopTimeIndex = GenericBinarySearch.searchRange(blockConfig, indexFrom, indexTo, distanceAlongBlock, IndexAdapters.BLOCK_CONFIG_DISTANCE_INSTANCE);
    return getScheduledBlockLocationFromDistanceAlongBlockAndStopTimeIndex(stopTimes, distanceAlongBlock, stopTimeIndex);
}
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 88 with BlockConfigurationEntry

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

the class BlockStopTimeIndicesFactory method getStopTimesAsFrequencyStopTimes.

private List<FrequencyBlockStopTimeEntry> getStopTimesAsFrequencyStopTimes(List<BlockStopTimeEntry> stopTimes) {
    List<FrequencyBlockStopTimeEntry> frequencyStopTimes = new ArrayList<FrequencyBlockStopTimeEntry>();
    for (BlockStopTimeEntry blockStopTime : stopTimes) {
        BlockTripEntry trip = blockStopTime.getTrip();
        BlockConfigurationEntry blockConfig = trip.getBlockConfiguration();
        for (FrequencyEntry frequency : blockConfig.getFrequencies()) {
            FrequencyBlockStopTimeEntry frequencyStopTime = new FrequencyBlockStopTimeEntryImpl(blockStopTime, frequency);
            frequencyStopTimes.add(frequencyStopTime);
        }
    }
    return frequencyStopTimes;
}
Also used : BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) ArrayList(java.util.ArrayList) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) FrequencyBlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry) FrequencyBlockStopTimeEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.FrequencyBlockStopTimeEntryImpl) FrequencyBlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry)

Example 89 with BlockConfigurationEntry

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

the class BlockStopTimeIndicesFactory method getBlockStopTimeAsKey.

private BlockStopTimeKey getBlockStopTimeAsKey(BlockStopTimeEntry blockStopTime) {
    BlockTripEntry blockTrip = blockStopTime.getTrip();
    BlockConfigurationEntry blockConfig = blockTrip.getBlockConfiguration();
    StopTimeEntry stopTime = blockStopTime.getStopTime();
    StopEntry stop = stopTime.getStop();
    return new BlockStopTimeKey(blockConfig.getServiceIds(), stop.getId());
}
Also used : 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) FrequencyBlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)

Aggregations

BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)89 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)36 BlockEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl)34 Test (org.junit.Test)30 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)29 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)27 ArrayList (java.util.ArrayList)23 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)23 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)18 VehicleLocationRecord (org.onebusaway.realtime.api.VehicleLocationRecord)17 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)14 StopTimeInstance (org.onebusaway.transit_data_federation.model.StopTimeInstance)13 BlockEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry)13 Date (java.util.Date)12 List (java.util.List)11 StopEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)11 TripUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate)10 ScheduledBlockLocation (org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation)10 StopTimeUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate)8 FactoryMap (org.onebusaway.collections.FactoryMap)8