Search in sources :

Example 11 with InstanceState

use of org.onebusaway.transit_data_federation.services.blocks.InstanceState in project onebusaway-application-modules by camsys.

the class BlockCalendarServiceImpl method getBlockInstance.

/**
 **
 * {@link BlockCalendarService} Interface
 ***
 */
@Cacheable(isValueSerializable = false)
@Override
public BlockInstance getBlockInstance(AgencyAndId blockId, long serviceDate) {
    BlockEntry block = _transitGraphDao.getBlockEntryForId(blockId);
    if (block == null)
        throw new IllegalArgumentException("unknown block: " + blockId);
    List<BlockConfigurationEntry> configurations = block.getConfigurations();
    int index = 0;
    Date date = new Date(serviceDate);
    InstanceState state = new InstanceState(serviceDate);
    /**
     * See the specific contract for {@link BlockEntry#getConfigurations()}
     * about the sort order of configurations
     */
    for (BlockConfigurationEntry configuration : configurations) {
        if (allServiceIdsAreActiveForServiceDate(configuration, date)) {
            return new BlockInstance(configuration, state);
        }
        index++;
    }
    return null;
}
Also used : InstanceState(org.onebusaway.transit_data_federation.services.blocks.InstanceState) BlockEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) Date(java.util.Date) Cacheable(org.onebusaway.container.cache.Cacheable)

Example 12 with InstanceState

use of org.onebusaway.transit_data_federation.services.blocks.InstanceState in project onebusaway-application-modules by camsys.

the class BlockCalendarServiceImpl method findFrequencyBlockTripsInRange.

private void findFrequencyBlockTripsInRange(FrequencyServiceIntervalBlock serviceIntervalIndex, Date serviceDate, Date timeFrom, Date timeTo, List<BlockTripEntry> trips, List<FrequencyEntry> frequencies, Collection<BlockInstance> instances) {
    int scheduledTimeFrom = (int) ((timeFrom.getTime() - serviceDate.getTime()) / 1000);
    int scheduledTimeTo = (int) ((timeTo.getTime() - serviceDate.getTime()) / 1000);
    int indexFrom = index(Arrays.binarySearch(serviceIntervalIndex.getEndTimes(), scheduledTimeFrom));
    int indexTo = index(Arrays.binarySearch(serviceIntervalIndex.getStartTimes(), scheduledTimeTo));
    for (int in = indexFrom; in < indexTo; in++) {
        BlockTripEntry trip = trips.get(in);
        BlockConfigurationEntry block = trip.getBlockConfiguration();
        FrequencyEntry frequency = frequencies.get(in);
        InstanceState state = new InstanceState(serviceDate.getTime(), frequency);
        BlockInstance instance = new BlockInstance(block, state);
        instances.add(instance);
    }
}
Also used : InstanceState(org.onebusaway.transit_data_federation.services.blocks.InstanceState) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)

Example 13 with InstanceState

use of org.onebusaway.transit_data_federation.services.blocks.InstanceState in project onebusaway-application-modules by camsys.

the class BlockCalendarServiceImpl method findBlockLayoversInRange.

private void findBlockLayoversInRange(LayoverIntervalBlock intervals, Date serviceDate, Date timeFrom, Date timeTo, List<BlockTripEntry> trips, Collection<BlockInstance> instances) {
    int scheduledTimeFrom = (int) ((timeFrom.getTime() - serviceDate.getTime()) / 1000);
    int scheduledTimeTo = (int) ((timeTo.getTime() - serviceDate.getTime()) / 1000);
    int indexFrom = index(Arrays.binarySearch(intervals.getEndTimes(), scheduledTimeFrom));
    int indexTo = index(Arrays.binarySearch(intervals.getStartTimes(), scheduledTimeTo));
    InstanceState state = new InstanceState(serviceDate.getTime());
    for (int in = indexFrom; in < indexTo; in++) {
        BlockTripEntry trip = trips.get(in);
        BlockConfigurationEntry block = trip.getBlockConfiguration();
        BlockInstance instance = new BlockInstance(block, state);
        instances.add(instance);
    }
}
Also used : InstanceState(org.onebusaway.transit_data_federation.services.blocks.InstanceState) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)

Example 14 with InstanceState

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

Aggregations

InstanceState (org.onebusaway.transit_data_federation.services.blocks.InstanceState)14 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)8 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)8 StopTimeInstance (org.onebusaway.transit_data_federation.model.StopTimeInstance)7 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)7 Date (java.util.Date)5 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)5 FrequencyBlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry)5 FrequencyEntry (org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry)4 ArrayList (java.util.ArrayList)3 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)3 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)3 FrequencyBlockStopTimeIndex (org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex)3 ArrivalAndDepartureTime (org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureTime)3 ArrivalAndDepartureInstance (org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance)2 ServiceIdActivation (org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation)2 StopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry)2 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)2 HashSet (java.util.HashSet)1 Set (java.util.Set)1