use of org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry in project onebusaway-application-modules by camsys.
the class ArrivalAndDepartureTime method getScheduledTime.
public static ArrivalAndDepartureTime getScheduledTime(long serviceDate, BlockStopTimeEntry blockStopTime, int offset) {
if (blockStopTime == null) {
_log.error("blockStopTime is null");
return null;
}
StopTimeEntry stopTime = blockStopTime.getStopTime();
long arrivalTime = serviceDate + (stopTime.getArrivalTime() + offset) * 1000;
long departureTime = serviceDate + (stopTime.getDepartureTime() + offset) * 1000;
return new ArrivalAndDepartureTime(arrivalTime, departureTime);
}
use of org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry in project onebusaway-application-modules by camsys.
the class AgencyServiceImpl method getAgencyIdsAndCoverageAreas.
@Cacheable
public Map<String, CoordinateBounds> getAgencyIdsAndCoverageAreas() {
Map<String, CoordinateBounds> boundsByAgencyId = new HashMap<String, CoordinateBounds>();
for (AgencyEntry agency : _graph.getAllAgencies()) {
CoordinateBounds bounds = new CoordinateBounds();
for (RouteCollectionEntry routeCollection : agency.getRouteCollections()) {
for (RouteEntry route : routeCollection.getChildren()) {
for (TripEntry trip : route.getTrips()) {
for (StopTimeEntry stopTime : trip.getStopTimes()) {
StopEntry stop = stopTime.getStop();
bounds.addPoint(stop.getStopLat(), stop.getStopLon());
}
}
}
}
boundsByAgencyId.put(agency.getId(), bounds);
}
return boundsByAgencyId;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry in project onebusaway-application-modules by camsys.
the class ArrivalAndDepartureServiceImpl method computePredictedDepartureTimeInterval.
private TimeIntervalBean computePredictedDepartureTimeInterval(ArrivalAndDepartureInstance instance, BlockLocation blockLocation, long targetTime) {
BlockStopTimeEntry blockStopTime = instance.getBlockStopTime();
StopTimeEntry stopTime = blockStopTime.getStopTime();
// interval
if (stopTime.getDepartureTime() <= blockLocation.getEffectiveScheduleTime())
return null;
ScheduleDeviationSamples samples = blockLocation.getScheduleDeviations();
if (samples == null || samples.isEmpty())
return null;
double mu = InterpolationLibrary.interpolate(samples.getScheduleTimes(), samples.getScheduleDeviationMus(), stopTime.getDepartureTime(), EOutOfRangeStrategy.LAST_VALUE, EInRangeStrategy.INTERPOLATE);
double sigma = InterpolationLibrary.interpolate(samples.getScheduleTimes(), samples.getScheduleDeviationSigmas(), stopTime.getDepartureTime(), EOutOfRangeStrategy.LAST_VALUE, EInRangeStrategy.INTERPOLATE);
long from = (long) (instance.getScheduledDepartureTime() + (mu - sigma) * 1000);
long to = (long) (instance.getScheduledDepartureTime() + (mu + sigma) * 1000);
return new TimeIntervalBean(from, to);
}
use of org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry in project onebusaway-application-modules by camsys.
the class ArrivalAndDepartureServiceImpl method getBlockStopTime.
private BlockStopTimeEntry getBlockStopTime(BlockTripInstance blockTripInstance, AgencyAndId stopId, int stopSequence, int timeOfServiceDate) {
/**
* We don't iterate over block stop times directly because there is
* performance penalty with instantiating each. Also note that this will
* currently miss the case where a stop is visited twice in the same trip.
*/
BlockTripEntry blockTrip = blockTripInstance.getBlockTrip();
TripEntry trip = blockTrip.getTrip();
List<StopTimeEntry> stopTimes = trip.getStopTimes();
if (stopSequence > -1) {
/**
* If a stop sequence has been specified, we start our search at the
* specified index, expanding our search until we find the target stop. We
* allow this flexibility in the case of a bookmarked arrival-departure
* where the stop sequence has changed slightly due to the addition or
* subtraction of a previous stop.
*/
int offset = 0;
while (true) {
int before = stopSequence - offset;
if (isMatch(stopTimes, stopId, before)) {
return blockTrip.getStopTimes().get(before);
}
int after = stopSequence + offset;
if (isMatch(stopTimes, stopId, after)) {
return blockTrip.getStopTimes().get(after);
}
if (before < 0 && after >= stopTimes.size())
return null;
offset++;
}
} else {
Min<BlockStopTimeEntry> m = new Min<BlockStopTimeEntry>();
int index = 0;
for (StopTimeEntry stopTime : stopTimes) {
if (stopTime.getStop().getId().equals(stopId)) {
int a = Math.abs(timeOfServiceDate - stopTime.getArrivalTime());
int b = Math.abs(timeOfServiceDate - stopTime.getDepartureTime());
int delta = Math.min(a, b);
m.add(delta, blockTrip.getStopTimes().get(index));
}
index++;
}
if (m.isEmpty())
return null;
return m.getMinElement();
}
}
use of org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry in project onebusaway-application-modules by camsys.
the class ArrivalAndDepartureServiceImpl method setPredictedTimesFromTimepointPredictionRecords.
private boolean setPredictedTimesFromTimepointPredictionRecords(ArrivalAndDepartureInstance instance, BlockLocation blockLocation, long targetTime) {
List<TimepointPredictionRecord> records = blockLocation.getTimepointPredictions();
if (records == null)
return false;
// Find the right timepoint prediction record. We need to make sure that
// there are the proper number of records if the trip loops and stopSequence
// is not set.
int stopSequence = instance.getBlockStopTime().getStopTime().getSequence();
int gtfsSequence = instance.getBlockStopTime().getStopTime().getGtfsSequence();
int totalCandidates = 0;
// index (with respect to stop sequence) among stops
int thisStopIndex = 0;
// with the same ID
List<BlockStopTimeEntry> stopTimes = instance.getBlockTrip().getStopTimes();
for (int i = 0; i < stopTimes.size(); i++) {
BlockStopTimeEntry stopTime = stopTimes.get(i);
StopTimeEntry stop = stopTime.getStopTime();
if (stop.getStop().getId().equals(instance.getStop().getId())) {
totalCandidates++;
if (stop.getSequence() < stopSequence)
thisStopIndex++;
}
}
int tprTotalCandidates = 0;
int tprStopIndex = 0;
boolean success = false;
for (TimepointPredictionRecord tpr : records) {
boolean tripMatches = tpr.getTripId().equals(instance.getBlockTrip().getTrip().getId());
boolean stopMatches = tpr.getTimepointId().equals(instance.getStop().getId());
boolean sequenceMatches = tpr.getStopSequence() > 0 && tpr.getStopSequence() == gtfsSequence;
if (!tripMatches || !stopMatches)
continue;
if (sequenceMatches || tprStopIndex == thisStopIndex) {
success = true;
long arrivalTime = tpr.getTimepointPredictedArrivalTime();
long departureTime = tpr.getTimepointPredictedDepartureTime();
if (departureTime <= 0) {
int slack = instance.getBlockStopTime().getStopTime().getSlackTime();
departureTime = arrivalTime + slack * 1000;
}
setPredictedDepartureTimeForInstance(instance, departureTime);
/*
* if arrivalTime is -1 be polite to clients and serve departureTime
*/
if (arrivalTime == -1) {
setPredictedArrivalTimeForInstance(instance, departureTime);
} else {
setPredictedArrivalTimeForInstance(instance, arrivalTime);
}
if (sequenceMatches)
return true;
} else if (tprStopIndex < thisStopIndex)
tprStopIndex++;
tprTotalCandidates++;
}
if (success && totalCandidates == tprTotalCandidates && tprStopIndex == thisStopIndex)
return true;
// Clear out prediction times if we didn't end up finding the proper number
// of records
setPredictedArrivalTimeForInstance(instance, 0);
setPredictedDepartureTimeForInstance(instance, 0);
return false;
}
Aggregations