use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry in project onebusaway-application-modules by camsys.
the class ScheduledServiceServiceImpl method stopHasUpcomingScheduledService.
@Override
public Boolean stopHasUpcomingScheduledService(String stopAgencyId, long time, String stopId, String routeId, String directionId) {
AgencyAndId stopAndId = null;
if (stopId != null && stopId.contains("_"))
stopAndId = AgencyAndIdLibrary.convertFromString(stopId);
else if (stopId != null)
stopAndId = new AgencyAndId(stopAgencyId, stopId);
StopEntry stopEntry = _transitGraphDao.getStopEntryForId(stopAndId);
if (stopEntry == null) {
return null;
}
Date serviceStart = new Date(time - SCHEDULE_WINDOW_BEFORE);
Date serviceEnd = new Date(time + SCHEDULE_WINDOW_AFTER);
List<StopTimeInstance> stis = _stopTimeService.getStopTimeInstancesInTimeRange(stopEntry, serviceStart, serviceEnd, EFrequencyStopTimeBehavior.INCLUDE_UNSPECIFIED);
if (stis.isEmpty()) {
return false;
}
for (StopTimeInstance stopTime : stis) {
BlockTripEntry blockTripEntry = stopTime.getTrip();
TripEntry tripEntry = blockTripEntry.getTrip();
if (tripEntry.getRoute().getId().toString().equals(routeId)) {
if (tripEntry.getDirectionId() == null || tripEntry.getDirectionId().equals(directionId)) {
return true;
}
}
}
return false;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry in project onebusaway-application-modules by camsys.
the class ScheduledServiceServiceImpl method stopHasRevenueServiceOnRoute.
@Override
public Boolean stopHasRevenueServiceOnRoute(String agencyId, String stopId, String routeId, String directionId) {
AgencyAndId stopAndId = null;
if (stopId != null && stopId.contains("_"))
stopAndId = AgencyAndIdLibrary.convertFromString(stopId);
else if (stopId != null)
stopAndId = new AgencyAndId(agencyId, stopId);
StopEntry stopEntry = _transitGraphDao.getStopEntryForId(stopAndId);
List<BlockStopTimeIndex> stopTimeIndicesForStop = _blockIndexService.getStopTimeIndicesForStop(stopEntry);
for (BlockStopTimeIndex bsti : stopTimeIndicesForStop) {
List<BlockStopTimeEntry> stopTimes = bsti.getStopTimes();
for (BlockStopTimeEntry bste : stopTimes) {
StopTimeEntry stopTime = bste.getStopTime();
TripEntry theTrip = stopTime.getTrip();
if (routeId != null && !theTrip.getRoute().getId().toString().equals(routeId)) {
continue;
}
if (directionId != null && theTrip.getDirectionId() != null) {
if (!theTrip.getDirectionId().equals(directionId)) {
continue;
}
}
/*
* If at least one stoptime on one trip (subject to the
* route and direction filters above) permits unrestricted
* pick-up or drop-off at this stop (type=0), then it is
* considered a 'revenue' stop.
*/
if (stopTime.getDropOffType() == 0 || stopTime.getPickupType() == 0) {
return true;
}
}
}
return false;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry in project onebusaway-application-modules by camsys.
the class BlockConfigurationEntryImpl method getStopTimeForIndex.
/**
***
* Private Methods
***
*/
private StopTimeEntry getStopTimeForIndex(int index) {
int tripIndex = tripIndices[index];
BlockTripEntry blockTrip = trips.get(tripIndex);
TripEntry trip = blockTrip.getTrip();
List<StopTimeEntry> stopTimes = trip.getStopTimes();
int stopTimeIndex = index - accumulatedStopTimeIndices[tripIndex];
StopTimeEntry stopTime = stopTimes.get(stopTimeIndex);
return stopTime;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry in project onebusaway-application-modules by camsys.
the class RealTimeHistoryServiceImpl method getScheduleDeviationHistogramForArrivalAndDepartureInstance.
@Override
public ScheduleDeviationHistogram getScheduleDeviationHistogramForArrivalAndDepartureInstance(ArrivalAndDepartureInstance instance, int stepSizeInSeconds) {
BlockTripEntry blockTrip = instance.getBlockTrip();
TripEntry trip = blockTrip.getTrip();
AgencyAndId tripId = trip.getId();
ScheduleDeviationHistory history = _scheduleDeviationHistoryDao.getScheduleDeviationHistoryForTripId(tripId);
if (history == null)
return null;
BlockStopTimeEntry blockStopTime = instance.getBlockStopTime();
StopTimeEntry stopTime = blockStopTime.getStopTime();
double[] values = getScheduleDeviationsForScheduleTime(history, stopTime.getDepartureTime());
return createHistogramFromValues(values, stepSizeInSeconds);
}
use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry in project onebusaway-application-modules by camsys.
the class RealTimeHistoryServiceImpl method sampleScheduleDeviationsForVehicle.
@Override
public ScheduleDeviationSamples sampleScheduleDeviationsForVehicle(BlockInstance instance, VehicleLocationRecord record, ScheduledBlockLocation scheduledBlockLocation) {
if (scheduledBlockLocation == null)
return null;
BlockTripEntry blockTrip = scheduledBlockLocation.getActiveTrip();
TripEntry trip = blockTrip.getTrip();
ScheduleDeviationHistory history = _scheduleDeviationHistoryDao.getScheduleDeviationHistoryForTripId(trip.getId());
if (history == null)
return null;
ScheduleDeviationHistory resampledHistory = resampleHistory(history, scheduledBlockLocation.getScheduledTime(), record.getScheduleDeviation());
DoubleArrayList scheduleTimes = new DoubleArrayList();
DoubleArrayList mus = new DoubleArrayList();
DoubleArrayList sigmas = new DoubleArrayList();
for (int t = 0; t <= _predictionLookahead; t += 5 * 60) {
int scheduleTime = scheduledBlockLocation.getScheduledTime() + t;
double[] deviations = getScheduleDeviationsForScheduleTime(resampledHistory, scheduleTime);
deviations = noNans(deviations);
DoubleArrayList values = new DoubleArrayList(deviations);
double mu = Descriptive.mean(values);
double var = Descriptive.sampleVariance(values, mu);
double sigma = Descriptive.sampleStandardDeviation(values.size(), var);
scheduleTimes.add(scheduleTime);
mus.add(mu);
sigmas.add(sigma);
}
scheduleTimes.trimToSize();
mus.trimToSize();
sigmas.trimToSize();
return new ScheduleDeviationSamples(scheduleTimes.elements(), mus.elements(), sigmas.elements());
}
Aggregations