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);
}
}
Aggregations