Search in sources :

Example 11 with FrequencyEntry

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;
}
Also used : StopTimeInstance(org.onebusaway.transit_data_federation.model.StopTimeInstance) ArrayList(java.util.ArrayList) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry) BlockLocation(org.onebusaway.transit_data_federation.services.realtime.BlockLocation) Date(java.util.Date) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) ArrayList(java.util.ArrayList) List(java.util.List) ArrivalAndDepartureInstance(org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance) HashMap(java.util.HashMap) Map(java.util.Map) FactoryMap(org.onebusaway.collections.FactoryMap)

Example 12 with FrequencyEntry

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);
}
Also used : FrequencyEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.FrequencyEntryImpl) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry)

Example 13 with FrequencyEntry

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;
}
Also used : BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)

Example 14 with FrequencyEntry

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);
    }
}
Also used : BlockConfigurationEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockConfigurationEntryImpl) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry) BlockEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)

Example 15 with FrequencyEntry

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()) + ")";
    }
}
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