use of org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry in project onebusaway-application-modules by camsys.
the class ArrivalAndDepartureServiceImpl method getArrivalsAndDeparturesForStopInTimeRange.
@Override
public List<ArrivalAndDepartureInstance> getArrivalsAndDeparturesForStopInTimeRange(StopEntry stop, TargetTime targetTime, long fromTime, long toTime) {
// We add a buffer before and after to catch late and early buses
Date fromTimeBuffered = new Date(fromTime - _blockStatusService.getRunningLateWindow() * 1000);
Date toTimeBuffered = new Date(toTime + _blockStatusService.getRunningEarlyWindow() * 1000);
List<StopTimeInstance> stis = _stopTimeService.getStopTimeInstancesInTimeRange(stop, fromTimeBuffered, toTimeBuffered, EFrequencyStopTimeBehavior.INCLUDE_UNSPECIFIED);
long frequencyOffsetTime = Math.max(targetTime.getTargetTime(), fromTime);
Map<BlockInstance, List<StopTimeInstance>> stisByBlockId = getStopTimeInstancesByBlockInstance(stis);
List<ArrivalAndDepartureInstance> instances = new ArrayList<ArrivalAndDepartureInstance>();
for (Map.Entry<BlockInstance, List<StopTimeInstance>> entry : stisByBlockId.entrySet()) {
BlockInstance blockInstance = entry.getKey();
List<BlockLocation> locations = _blockLocationService.getLocationsForBlockInstance(blockInstance, targetTime);
List<StopTimeInstance> stisForBlock = entry.getValue();
for (StopTimeInstance sti : stisForBlock) {
applyRealTimeToStopTimeInstance(sti, targetTime, fromTime, toTime, frequencyOffsetTime, blockInstance, locations, instances);
if (sti.getFrequency() != null && sti.getFrequency().getExactTimes() == 0) {
/*
* adjust following schedule times relative to current realtime data
*/
applyPostInterpolateForFrequencyNoSchedule(sti, fromTime, toTime, frequencyOffsetTime, blockInstance, instances);
}
}
}
if (removeFuturePredictionsWithoutRealtime) {
List<ArrivalAndDepartureInstance> filteredInstances = new ArrayList<ArrivalAndDepartureInstance>();
for (ArrivalAndDepartureInstance instance : instances) {
FrequencyEntry entry = instance.getFrequency();
boolean toAdd = // not a frequency-based instance
(entry == null) || // frequency interval has started
(instance.getServiceDate() + (entry.getStartTime() * 1000) < targetTime.getTargetTime()) || // instance has realtime data
(instance.getBlockLocation() != null && instance.getBlockLocation().isPredicted());
if (toAdd)
filteredInstances.add(instance);
}
return filteredInstances;
}
return instances;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry in project onebusaway-application-modules by camsys.
the class FrequencyEntriesFactory method processRawFrequency.
private void processRawFrequency(TransitGraphImpl graph, Frequency frequency, Map<AgencyAndId, List<FrequencyEntry>> frequenciesByTripId, Map<AgencyAndId, Integer> exactTimesValueByTrip) {
AgencyAndId tripId = frequency.getTrip().getId();
/**
* The value of frequencies.txt exact_times is expected to be the same
* across all entries for the same trip id.
*/
Integer exactTimesValue = exactTimesValueByTrip.get(tripId);
if (exactTimesValue == null) {
exactTimesValue = frequency.getExactTimes();
exactTimesValueByTrip.put(tripId, exactTimesValue);
} else if (exactTimesValue != frequency.getExactTimes()) {
throw new IllegalStateException("The value of frequencies.txt exact_times differed for frequency entries with tripId=" + tripId);
}
FrequencyEntryImpl entry = new FrequencyEntryImpl(frequency.getStartTime(), frequency.getEndTime(), frequency.getHeadwaySecs(), frequency.getExactTimes());
List<FrequencyEntry> frequencies = frequenciesByTripId.get(tripId);
if (frequencies == null) {
frequencies = new ArrayList<FrequencyEntry>();
frequenciesByTripId.put(tripId, frequencies);
}
frequencies.add(entry);
}
use of org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry in project onebusaway-application-modules by camsys.
the class FrequencyEntriesFactory method computeBlockFrequencies.
private List<FrequencyEntry> computeBlockFrequencies(BlockEntryImpl block, List<BlockTripEntry> trips, Map<AgencyAndId, List<FrequencyEntry>> frequenciesAlongBlock) {
List<FrequencyEntry> frequencies = null;
for (BlockTripEntry blockTrip : trips) {
TripEntry trip = blockTrip.getTrip();
List<FrequencyEntry> potentialFrequencies = frequenciesAlongBlock.get(trip.getId());
if (frequencies == null) {
frequencies = potentialFrequencies;
} else {
if (!frequencies.equals(potentialFrequencies)) {
throw new IllegalStateException("frequency-based trips in same block don't have same frequencies: blockId=" + block.getId());
}
}
}
return frequencies;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry in project onebusaway-application-modules by camsys.
the class FrequencyEntriesFactory method applyFrequenciesToBlockTrips.
private void applyFrequenciesToBlockTrips(List<TripEntryImpl> tripsInBlock, Map<AgencyAndId, List<FrequencyEntry>> frequenciesAlongBlockByTripId) {
BlockEntryImpl blockEntry = tripsInBlock.get(0).getBlock();
List<BlockConfigurationEntry> configurations = blockEntry.getConfigurations();
for (int i = 0; i < configurations.size(); i++) {
BlockConfigurationEntryImpl blockConfig = (BlockConfigurationEntryImpl) configurations.get(i);
List<FrequencyEntry> frequencies = computeBlockFrequencies(blockEntry, blockConfig.getTrips(), frequenciesAlongBlockByTripId);
blockConfig.setFrequencies(frequencies);
}
}
use of org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry in project onebusaway-application-modules by camsys.
the class StopTimeInstance method toString.
@Override
public String toString() {
long serviceDate = _state.getServiceDate();
FrequencyEntry frequency = _state.getFrequency();
if (frequency != null) {
long start = serviceDate + frequency.getStartTime() * 1000;
long end = serviceDate + frequency.getEndTime() * 1000;
StringBuilder b = new StringBuilder();
b.append("StopTimeInstance(stop=");
b.append(_stopTime.getStopTime().getStop().getId());
b.append(" trip=");
b.append(getTrip());
b.append(" service=");
b.append(DAY_FORMAT.format(serviceDate));
b.append(" start=");
b.append(TIME_FORMAT.format(start));
b.append(" end=");
b.append(TIME_FORMAT.format(end));
if (isFrequencyOffsetSpecified()) {
b.append(" arrival=");
b.append(TIME_FORMAT.format(getArrivalTime()));
b.append(" departure=");
b.append(TIME_FORMAT.format(getDepartureTime()));
}
b.append(")");
return b.toString();
} else {
return "StopTimeInstance(stop=" + _stopTime.getStopTime().getStop().getId() + " trip=" + getTrip() + " service=" + DAY_FORMAT.format(serviceDate) + " arrival=" + TIME_FORMAT.format(getArrivalTime()) + " departure=" + TIME_FORMAT.format(getDepartureTime()) + ")";
}
}
Aggregations