Search in sources :

Example 11 with StopTimeInstance

use of org.onebusaway.transit_data_federation.model.StopTimeInstance in project onebusaway-application-modules by camsys.

the class StopTimeServiceImplTest method test03.

@Test
public void test03() {
    Date dayA = getTimeAsDay(date("2009-09-02 00:00"));
    Date dayB = getTimeAsDay(date("2009-09-03 00:00"));
    StopTimeEntryImpl stA = stopTime(0, _stop, trip("A", "sA"), time(10, 00), time(10, 30), 0);
    StopTimeEntryImpl stB = stopTime(1, _stop, trip("B", "sA"), time(25, 0), time(25, 30), 0);
    StopTimeEntryImpl stC = stopTime(2, _stop, trip("C", "sB"), time(10, 00), time(10, 30), 0);
    StopTimeEntryImpl stD = stopTime(3, _stop, trip("D", "sB"), time(25, 0), time(25, 30), 0);
    BlockConfigurationEntry bA = linkBlockTrips("bA", stA.getTrip());
    BlockConfigurationEntry bB = linkBlockTrips("bB", stB.getTrip());
    BlockConfigurationEntry bC = linkBlockTrips("bC", stC.getTrip());
    BlockConfigurationEntry bD = linkBlockTrips("bD", stD.getTrip());
    addFirstStopToBlockIndex(bA, bB);
    addFirstStopToBlockIndex(bC, bD);
    /**
     **
     *
     ***
     */
    Date from = date("2009-09-02 10:10");
    Date to = date("2009-09-02 10:40");
    List<StopTimeInstance> results = _service.getStopTimeInstancesInTimeRange(_stopId, from, to);
    sort(results);
    assertEquals(1, results.size());
    StopTimeInstance sti = results.get(0);
    assertEquals(dayA.getTime(), sti.getServiceDate());
    assertEquals(date("2009-09-02 10:00").getTime(), sti.getArrivalTime());
    assertEquals(date("2009-09-02 10:30").getTime(), sti.getDepartureTime());
    /**
     **
     *
     ***
     */
    from = date("2009-09-03 10:10");
    to = date("2009-09-03 10:40");
    results = _service.getStopTimeInstancesInTimeRange(_stopId, from, to);
    sort(results);
    assertEquals(1, results.size());
    sti = results.get(0);
    assertEquals(dayB.getTime(), sti.getServiceDate());
    assertEquals(date("2009-09-03 10:00").getTime(), sti.getArrivalTime());
    assertEquals(date("2009-09-03 10:30").getTime(), sti.getDepartureTime());
    /**
     **
     *
     ***
     */
    from = date("2009-09-02 10:10");
    to = date("2009-09-03 10:40");
    results = _service.getStopTimeInstancesInTimeRange(_stopId, from, to);
    sort(results);
    assertEquals(3, results.size());
    sti = results.get(0);
    assertEquals(dayA.getTime(), sti.getServiceDate());
    assertEquals(date("2009-09-02 10:00").getTime(), sti.getArrivalTime());
    assertEquals(date("2009-09-02 10:30").getTime(), sti.getDepartureTime());
    sti = results.get(1);
    assertEquals(dayA.getTime(), sti.getServiceDate());
    assertEquals(date("2009-09-03 01:00").getTime(), sti.getArrivalTime());
    assertEquals(date("2009-09-03 01:30").getTime(), sti.getDepartureTime());
    sti = results.get(2);
    assertEquals(dayB.getTime(), sti.getServiceDate());
    assertEquals(date("2009-09-03 10:00").getTime(), sti.getArrivalTime());
    assertEquals(date("2009-09-03 10:30").getTime(), sti.getDepartureTime());
    /**
     **
     *
     ***
     */
    from = date("2009-09-02 12:00");
    to = date("2009-09-03 12:00");
    results = _service.getStopTimeInstancesInTimeRange(_stopId, from, to);
    sort(results);
    assertEquals(2, results.size());
    sti = results.get(0);
    assertEquals(dayA.getTime(), sti.getServiceDate());
    assertEquals(date("2009-09-03 01:00").getTime(), sti.getArrivalTime());
    assertEquals(date("2009-09-03 01:30").getTime(), sti.getDepartureTime());
    sti = results.get(1);
    assertEquals(dayB.getTime(), sti.getServiceDate());
    assertEquals(date("2009-09-03 10:00").getTime(), sti.getArrivalTime());
    assertEquals(date("2009-09-03 10:30").getTime(), sti.getDepartureTime());
    /**
     **
     *
     ***
     */
    from = date("2009-09-03 12:00");
    to = date("2009-09-04 12:00");
    results = _service.getStopTimeInstancesInTimeRange(_stopId, from, to);
    sort(results);
    assertEquals(1, results.size());
    sti = results.get(0);
    assertEquals(dayB.getTime(), sti.getServiceDate());
    assertEquals(date("2009-09-04 01:00").getTime(), sti.getArrivalTime());
    assertEquals(date("2009-09-04 01:30").getTime(), sti.getDepartureTime());
}
Also used : StopTimeInstance(org.onebusaway.transit_data_federation.model.StopTimeInstance) StopTimeEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) Date(java.util.Date) Test(org.junit.Test)

Example 12 with StopTimeInstance

use of org.onebusaway.transit_data_federation.model.StopTimeInstance 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 13 with StopTimeInstance

use of org.onebusaway.transit_data_federation.model.StopTimeInstance in project onebusaway-application-modules by camsys.

the class ArrivalAndDepartureServiceImpl method createArrivalAndDeparture.

private ArrivalAndDepartureInstance createArrivalAndDeparture(BlockInstance blockInstance, AgencyAndId tripId, AgencyAndId stopId, int stopSequence, long serviceDate, int timeOfServiceDate, long prevFrequencyTime) {
    BlockTripInstance blockTripInstance = BlockTripInstanceLibrary.getBlockTripInstance(blockInstance, tripId);
    if (blockTripInstance == null)
        return null;
    BlockStopTimeEntry blockStopTime = getBlockStopTime(blockTripInstance, stopId, stopSequence, timeOfServiceDate);
    if (blockStopTime == null) {
        _log.error("block stop time is null for stopid=" + stopId + " and blockTripInstance=" + blockTripInstance + " and timeOfServiceDate=" + timeOfServiceDate);
        return null;
    }
    StopTimeInstance stopTimeInstance = new StopTimeInstance(blockStopTime, blockTripInstance.getState());
    return createArrivalAndDeparture(stopTimeInstance, prevFrequencyTime, StopTimeInstance.UNSPECIFIED_FREQUENCY_OFFSET);
}
Also used : BlockTripInstance(org.onebusaway.transit_data_federation.services.blocks.BlockTripInstance) StopTimeInstance(org.onebusaway.transit_data_federation.model.StopTimeInstance) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Example 14 with StopTimeInstance

use of org.onebusaway.transit_data_federation.model.StopTimeInstance in project onebusaway-application-modules by camsys.

the class ArrivalAndDepartureServiceImpl method getScheduledArrivalsAndDeparturesForStopInTimeRange.

@Override
public List<ArrivalAndDepartureInstance> getScheduledArrivalsAndDeparturesForStopInTimeRange(StopEntry stop, long currentTime, long fromTime, long toTime) {
    List<StopTimeInstance> stis = _stopTimeService.getStopTimeInstancesInTimeRange(stop, new Date(fromTime), new Date(toTime), EFrequencyStopTimeBehavior.INCLUDE_UNSPECIFIED);
    List<ArrivalAndDepartureInstance> instances = new ArrayList<ArrivalAndDepartureInstance>();
    long prevFrequencyTime = Math.max(currentTime, fromTime);
    for (StopTimeInstance sti : stis) {
        BlockInstance blockInstance = sti.getBlockInstance();
        ArrivalAndDepartureInstance instance = createArrivalAndDepartureForStopTimeInstance(sti, prevFrequencyTime);
        if (sti.getFrequency() == null) {
            /**
             * We don't need to get the scheduled location of a vehicle unless its
             * in our arrival window
             */
            if (isArrivalAndDepartureBeanInRange(instance, fromTime, toTime)) {
                BlockLocation scheduledLocation = _blockLocationService.getScheduledLocationForBlockInstance(blockInstance, currentTime);
                if (scheduledLocation != null)
                    applyBlockLocationToInstance(instance, scheduledLocation, currentTime);
                instances.add(instance);
            }
        } else {
            if (isFrequencyBasedArrivalInRange(blockInstance, sti.getFrequency(), fromTime, toTime)) {
                instances.add(instance);
            }
        }
    }
    return instances;
}
Also used : StopTimeInstance(org.onebusaway.transit_data_federation.model.StopTimeInstance) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) ArrayList(java.util.ArrayList) ArrivalAndDepartureInstance(org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance) BlockLocation(org.onebusaway.transit_data_federation.services.realtime.BlockLocation) Date(java.util.Date)

Example 15 with StopTimeInstance

use of org.onebusaway.transit_data_federation.model.StopTimeInstance in project onebusaway-application-modules by camsys.

the class ArrivalAndDepartureServiceImpl method getStopTimeInstancesByBlockInstance.

private Map<BlockInstance, List<StopTimeInstance>> getStopTimeInstancesByBlockInstance(List<StopTimeInstance> stopTimes) {
    Map<BlockInstance, List<StopTimeInstance>> r = new FactoryMap<BlockInstance, List<StopTimeInstance>>(new ArrayList<StopTimeInstance>());
    for (StopTimeInstance stopTime : stopTimes) {
        BlockStopTimeEntry blockStopTime = stopTime.getStopTime();
        BlockTripEntry blockTrip = blockStopTime.getTrip();
        BlockConfigurationEntry blockConfiguration = blockTrip.getBlockConfiguration();
        long serviceDate = stopTime.getServiceDate();
        BlockInstance blockInstance = new BlockInstance(blockConfiguration, serviceDate, stopTime.getFrequency());
        r.get(blockInstance).add(stopTime);
    }
    return r;
}
Also used : FactoryMap(org.onebusaway.collections.FactoryMap) StopTimeInstance(org.onebusaway.transit_data_federation.model.StopTimeInstance) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) ArrayList(java.util.ArrayList) List(java.util.List) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Aggregations

StopTimeInstance (org.onebusaway.transit_data_federation.model.StopTimeInstance)25 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)16 Date (java.util.Date)15 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)13 ArrivalAndDepartureInstance (org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance)12 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)10 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)9 ArrayList (java.util.ArrayList)8 BlockLocation (org.onebusaway.transit_data_federation.services.realtime.BlockLocation)8 InstanceState (org.onebusaway.transit_data_federation.services.blocks.InstanceState)7 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)7 BlockEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl)6 TargetTime (org.onebusaway.transit_data_federation.model.TargetTime)6 FrequencyBlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry)6 VehicleLocationRecord (org.onebusaway.realtime.api.VehicleLocationRecord)5 ScheduledBlockLocationServiceImpl (org.onebusaway.transit_data_federation.impl.blocks.ScheduledBlockLocationServiceImpl)5 VehicleLocationRecordCacheImpl (org.onebusaway.transit_data_federation.impl.realtime.VehicleLocationRecordCacheImpl)5 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)5 Test (org.junit.Test)4 FactoryMap (org.onebusaway.collections.FactoryMap)4