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