Search in sources :

Example 6 with FrequencyEntry

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

the class BlockIndexFactoryServiceImpl method ensureFrequencyTripGroups.

private List<FrequencyTripGroup> ensureFrequencyTripGroups(List<BlockTripEntry> tripsWithSameSequence) {
    List<BlockTripWithFrequency> btwfs = new ArrayList<BlockTripWithFrequency>();
    for (BlockTripEntry trip : tripsWithSameSequence) {
        BlockConfigurationEntry blockConfig = trip.getBlockConfiguration();
        for (FrequencyEntry frequency : blockConfig.getFrequencies()) btwfs.add(new BlockTripWithFrequency(trip, frequency));
    }
    Collections.sort(btwfs);
    List<FrequencyTripGroup> lists = new ArrayList<FrequencyTripGroup>();
    for (BlockTripWithFrequency btwf : btwfs) {
        FrequencyTripGroup group = getBestFrequencyTripGroup(lists, btwf);
        if (group == null) {
            group = new FrequencyTripGroup();
            lists.add(group);
        }
        group.addEntry(btwf);
    }
    return lists;
}
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)

Example 7 with FrequencyEntry

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

the class BlockIndexFactoryServiceImpl method getBlockTripsAsFrequencyBlockInterval.

private FrequencyServiceIntervalBlock getBlockTripsAsFrequencyBlockInterval(List<BlockTripEntry> trips, List<FrequencyEntry> frequencies) {
    int n = trips.size();
    int[] startTimes = new int[n];
    int[] endTimes = new int[n];
    for (int index = 0; index < n; index++) {
        FrequencyEntry freq = frequencies.get(index);
        startTimes[index] = freq.getStartTime();
        endTimes[index] = freq.getEndTime();
    }
    return new FrequencyServiceIntervalBlock(startTimes, endTimes);
}
Also used : FrequencyServiceIntervalBlock(org.onebusaway.transit_data_federation.services.blocks.FrequencyServiceIntervalBlock) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry)

Example 8 with FrequencyEntry

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

the class BlockStatusServiceImpl method getBlockInstances.

/**
 **
 * Private Methods
 ***
 */
private List<BlockInstance> getBlockInstances(AgencyAndId blockId, long serviceDate, long time) {
    if (serviceDate != 0) {
        BlockInstance blockInstance = _blockCalendarService.getBlockInstance(blockId, serviceDate);
        if (blockInstance == null)
            return Collections.emptyList();
        BlockConfigurationEntry blockConfig = blockInstance.getBlock();
        if (blockConfig.getFrequencies() == null)
            return Arrays.asList(blockInstance);
        List<BlockInstance> instances = new ArrayList<BlockInstance>();
        for (FrequencyEntry frequency : blockConfig.getFrequencies()) instances.add(new BlockInstance(blockConfig, blockInstance.getServiceDate(), frequency));
        return instances;
    } else {
        List<BlockInstance> instances = _blockCalendarService.getActiveBlocks(blockId, time, time);
        if (instances.isEmpty()) {
            instances = _blockCalendarService.getClosestActiveBlocks(blockId, time);
        }
        return instances;
    }
}
Also used : BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) ArrayList(java.util.ArrayList) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)

Example 9 with FrequencyEntry

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

the class BlockStopTimeIndicesFactory method createFrequencyBlockStopTimeIndexForGroup.

private FrequencyBlockStopTimeIndex createFrequencyBlockStopTimeIndexForGroup(List<FrequencyBlockStopTimeEntry> group) {
    int n = group.size();
    List<FrequencyEntry> frequencies = new ArrayList<FrequencyEntry>(n);
    List<BlockConfigurationEntry> blockConfigs = new ArrayList<BlockConfigurationEntry>(n);
    int[] stopIndices = new int[n];
    ServiceInterval interval = null;
    for (int i = 0; i < n; i++) {
        FrequencyBlockStopTimeEntry frequencyBlockStopTime = group.get(i);
        FrequencyEntry frequency = frequencyBlockStopTime.getFrequency();
        frequencies.add(frequency);
        BlockStopTimeEntry blockStopTime = frequencyBlockStopTime.getStopTime();
        blockConfigs.add(blockStopTime.getTrip().getBlockConfiguration());
        stopIndices[i] = blockStopTime.getBlockSequence();
        interval = ServiceInterval.extend(interval, frequency.getStartTime(), frequency.getStartTime());
        interval = ServiceInterval.extend(interval, frequency.getEndTime(), frequency.getEndTime());
    }
    return new FrequencyBlockStopTimeIndex(frequencies, blockConfigs, stopIndices, interval);
}
Also used : ServiceInterval(org.onebusaway.gtfs.model.calendar.ServiceInterval) FrequencyBlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex) 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) FrequencyBlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry)

Example 10 with FrequencyEntry

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

the class FrequencyBlockStopTimeComparator method compare.

@Override
public int compare(FrequencyBlockStopTimeEntry o1, FrequencyBlockStopTimeEntry o2) {
    FrequencyEntry f1 = o1.getFrequency();
    FrequencyEntry f2 = o2.getFrequency();
    int c = f1.getStartTime() - f2.getStartTime();
    if (c != 0)
        return c;
    return f1.getEndTime() - f2.getEndTime();
}
Also used : FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry)

Aggregations

FrequencyEntry (org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry)28 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)12 ArrayList (java.util.ArrayList)10 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)8 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)7 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)7 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)6 BlockEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl)5 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)5 FrequencyBlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry)5 Date (java.util.Date)4 Test (org.junit.Test)4 FrequencyBean (org.onebusaway.transit_data.model.schedule.FrequencyBean)4 TripBean (org.onebusaway.transit_data.model.trips.TripBean)4 StopTimeInstance (org.onebusaway.transit_data_federation.model.StopTimeInstance)4 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)4 FrequencyBlockStopTimeIndex (org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex)4 FrequencyServiceIntervalBlock (org.onebusaway.transit_data_federation.services.blocks.FrequencyServiceIntervalBlock)4 InstanceState (org.onebusaway.transit_data_federation.services.blocks.InstanceState)4 HashMap (java.util.HashMap)3