Search in sources :

Example 1 with FrequencyComparator

use of org.onebusaway.transit_data_federation.impl.blocks.FrequencyComparator in project onebusaway-application-modules by camsys.

the class FrequencyEntriesFactory method processFrequencies.

public void processFrequencies(TransitGraphImpl graph) {
    Map<AgencyAndId, List<FrequencyEntry>> frequenciesByTripId = new HashMap<AgencyAndId, List<FrequencyEntry>>();
    Collection<Frequency> allFrequencies = _gtfsDao.getAllFrequencies();
    int logInterval = LoggingIntervalUtil.getAppropriateLoggingInterval(allFrequencies.size());
    int frequencyIndex = 0;
    Map<AgencyAndId, Integer> exactTimesValueByTrip = new HashMap<AgencyAndId, Integer>();
    for (Frequency frequency : allFrequencies) {
        if (frequencyIndex % logInterval == 0)
            _log.info("frequencies: " + (frequencyIndex++) + "/" + allFrequencies.size());
        frequencyIndex++;
        processRawFrequency(graph, frequency, frequenciesByTripId, exactTimesValueByTrip);
    }
    FrequencyComparator comparator = new FrequencyComparator();
    for (List<FrequencyEntry> list : frequenciesByTripId.values()) {
        Collections.sort(list, comparator);
    }
    int blockIndex = 0;
    Map<AgencyAndId, List<TripEntryImpl>> tripsByBlockId = MappingLibrary.mapToValueList(graph.getTrips(), "block.id");
    for (Map.Entry<AgencyAndId, List<TripEntryImpl>> entry : tripsByBlockId.entrySet()) {
        if (blockIndex % 10 == 0)
            _log.info("block: " + blockIndex + "/" + tripsByBlockId.size());
        blockIndex++;
        AgencyAndId blockId = entry.getKey();
        List<TripEntryImpl> tripsInBlock = entry.getValue();
        Map<AgencyAndId, List<FrequencyEntry>> frequenciesAlongBlockByTripId = new HashMap<AgencyAndId, List<FrequencyEntry>>();
        for (TripEntryImpl trip : tripsInBlock) {
            List<FrequencyEntry> frequencies = frequenciesByTripId.get(trip.getId());
            if (frequencies != null) {
                frequenciesAlongBlockByTripId.put(trip.getId(), frequencies);
            }
        }
        checkForInvalidFrequencyConfigurations(blockId, tripsInBlock, frequenciesAlongBlockByTripId);
        applyFrequenciesToBlockTrips(tripsInBlock, frequenciesAlongBlockByTripId);
    }
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) HashMap(java.util.HashMap) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) Frequency(org.onebusaway.gtfs.model.Frequency) ArrayList(java.util.ArrayList) List(java.util.List) FrequencyComparator(org.onebusaway.transit_data_federation.impl.blocks.FrequencyComparator) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)1 Frequency (org.onebusaway.gtfs.model.Frequency)1 FrequencyComparator (org.onebusaway.transit_data_federation.impl.blocks.FrequencyComparator)1 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)1 FrequencyEntry (org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry)1