use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry in project onebusaway-application-modules by camsys.
the class RouteServiceImpl method getRouteCollectionIdsForStop.
@Override
@Cacheable
public Set<AgencyAndId> getRouteCollectionIdsForStop(AgencyAndId stopId) {
StopEntry stopEntry = _transitGraphDao.getStopEntryForId(stopId);
if (stopEntry == null)
throw new InternalErrorServiceException("no such stop: id=" + stopId);
Set<AgencyAndId> routeCollectionIds = new HashSet<AgencyAndId>();
List<BlockStopTimeIndex> indices = _blockIndexService.getStopTimeIndicesForStop(stopEntry);
for (BlockStopTimeIndex blockStopTimeIndex : indices) {
for (BlockTripEntry blockTrip : blockStopTimeIndex.getTrips()) {
TripEntry trip = blockTrip.getTrip();
routeCollectionIds.add(trip.getRouteCollection().getId());
}
}
List<FrequencyBlockStopTimeIndex> frequencyIndices = _blockIndexService.getFrequencyStopTimeIndicesForStop(stopEntry);
for (FrequencyBlockStopTimeIndex blockStopTimeIndex : frequencyIndices) {
for (BlockTripEntry blockTrip : blockStopTimeIndex.getTrips()) {
TripEntry trip = blockTrip.getTrip();
routeCollectionIds.add(trip.getRouteCollection().getId());
}
}
return routeCollectionIds;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry in project onebusaway-application-modules by camsys.
the class SiriService method handleVehicleMonitoring.
/**
**
* Private Methods
***
*/
private void handleVehicleMonitoring(ServiceDelivery serviceDelivery, VehicleMonitoringDeliveryStructure deliveryForModule, SiriEndpointDetails endpointDetails) {
List<VehicleLocationRecord> records = new ArrayList<VehicleLocationRecord>();
Date now = new Date();
long timeFrom = now.getTime() - _blockInstanceSearchWindow * 60 * 1000;
long timeTo = now.getTime() + _blockInstanceSearchWindow * 60 * 1000;
for (VehicleActivityStructure vehicleActivity : deliveryForModule.getVehicleActivity()) {
Date time = vehicleActivity.getRecordedAtTime();
if (time == null)
time = now;
MonitoredVehicleJourney mvj = vehicleActivity.getMonitoredVehicleJourney();
Duration delay = mvj.getDelay();
if (delay == null)
continue;
VehicleRefStructure vehicleRef = mvj.getVehicleRef();
if (vehicleRef == null || vehicleRef.getValue() == null)
continue;
BlockEntry block = getBlockForMonitoredVehicleJourney(mvj, endpointDetails);
if (block == null) {
TripEntry trip = getTripForMonitoredVehicleJourney(mvj, endpointDetails);
if (trip != null)
block = trip.getBlock();
}
if (block == null)
continue;
List<BlockInstance> instances = _blockCalendarService.getActiveBlocks(block.getId(), timeFrom, timeTo);
// TODO : We currently assume that a block won't overlap with itself
if (instances.size() != 1)
continue;
BlockInstance instance = instances.get(0);
VehicleLocationRecord r = new VehicleLocationRecord();
r.setTimeOfRecord(time.getTime());
r.setServiceDate(instance.getServiceDate());
r.setBlockId(block.getId());
String agencyId = block.getId().getAgencyId();
r.setVehicleId(new AgencyAndId(agencyId, vehicleRef.getValue()));
r.setScheduleDeviation(delay.getTimeInMillis(now) / 1000);
LocationStructure location = mvj.getVehicleLocation();
if (location != null) {
r.setCurrentLocationLat(location.getLatitude().doubleValue());
r.setCurrentLocationLon(location.getLongitude().doubleValue());
}
records.add(r);
}
if (!records.isEmpty())
_vehicleLocationListener.handleVehicleLocationRecords(records);
}
use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry in project onebusaway-application-modules by camsys.
the class SiriService method getTripForMonitoredVehicleJourney.
private TripEntry getTripForMonitoredVehicleJourney(MonitoredVehicleJourney mvj, SiriEndpointDetails endpointDetails) {
FramedVehicleJourneyRefStructure fvjRef = mvj.getFramedVehicleJourneyRef();
if (fvjRef == null || fvjRef.getDatedVehicleJourneyRef() == null)
return null;
for (String agencyId : endpointDetails.getDefaultAgencyIds()) {
AgencyAndId tripId = new AgencyAndId(agencyId, fvjRef.getDatedVehicleJourneyRef());
TripEntry tripEntry = _transitGraphDao.getTripEntryForId(tripId);
if (tripEntry != null)
return tripEntry;
}
/**
* Try parsing the id itself
*/
try {
AgencyAndId tripId = AgencyAndId.convertFromString(fvjRef.getDatedVehicleJourneyRef());
return _transitGraphDao.getTripEntryForId(tripId);
} catch (IllegalArgumentException ex) {
return null;
}
}
use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry in project onebusaway-application-modules by camsys.
the class UserReportingServiceImpl method reportProblemWithTrip.
@Override
public void reportProblemWithTrip(TripProblemReportBean problem) {
AgencyAndId tripId = AgencyAndIdLibrary.convertFromString(problem.getTripId());
TripEntry trip = _graph.getTripEntryForId(tripId);
if (trip == null)
return;
BlockEntry block = trip.getBlock();
TripProblemReportRecord record = new TripProblemReportRecord();
record.setCode(problem.getCode());
record.setServiceDate(problem.getServiceDate());
String vehicleId = problem.getVehicleId();
if (vehicleId != null)
record.setVehicleId(AgencyAndIdLibrary.convertFromString(vehicleId));
String stopId = problem.getStopId();
if (stopId != null)
record.setStopId(AgencyAndIdLibrary.convertFromString(stopId));
record.setTime(problem.getTime());
record.setTripId(tripId);
record.setBlockId(block.getId());
record.setUserComment(problem.getUserComment());
if (problem.getUserLat() != null && !Double.isNaN(problem.getUserLat()))
record.setUserLat(problem.getUserLat());
if (problem.getUserLon() != null && !Double.isNaN(problem.getUserLon()))
record.setUserLon(problem.getUserLon());
if (problem.getUserLocationAccuracy() != null && !Double.isNaN(problem.getUserLocationAccuracy()))
record.setUserLocationAccuracy(problem.getUserLocationAccuracy());
record.setUserOnVehicle(problem.isUserOnVehicle());
record.setUserVehicleNumber(problem.getUserVehicleNumber());
Map<BlockInstance, List<BlockLocation>> locationsByInstance = _blockStatusService.getBlocks(block.getId(), problem.getServiceDate(), record.getVehicleId(), problem.getTime());
BlockInstance blockInstance = getBestBlockInstance(locationsByInstance.keySet());
if (blockInstance != null) {
List<BlockLocation> blockLocations = locationsByInstance.get(blockInstance);
BlockLocation blockLocation = getBestLocation(blockLocations, problem);
if (blockLocation != null) {
record.setPredicted(blockLocation.isPredicted());
if (blockLocation.isDistanceAlongBlockSet())
record.setDistanceAlongBlock(blockLocation.getDistanceAlongBlock());
if (blockLocation.isScheduleDeviationSet())
record.setScheduleDeviation(blockLocation.getScheduleDeviation());
CoordinatePoint p = blockLocation.getLocation();
if (p != null) {
record.setVehicleLat(p.getLat());
record.setVehicleLon(p.getLon());
}
record.setMatchedVehicleId(blockLocation.getVehicleId());
}
}
record.setStatus(problem.getStatus());
_userReportingDao.saveOrUpdate(record);
}
use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry in project onebusaway-application-modules by camsys.
the class ScheduledServiceServiceImpl method routeHasUpcomingScheduledService.
@Override
public Boolean routeHasUpcomingScheduledService(String agencyId, long time, String routeId, String directionId) {
long serviceStart = time - SCHEDULE_WINDOW_BEFORE;
long serviceEnd = time + SCHEDULE_WINDOW_AFTER;
AgencyAndId routeAndId;
if (routeId != null && routeId.contains("_"))
routeAndId = AgencyAndIdLibrary.convertFromString(routeId);
else
routeAndId = new AgencyAndId(agencyId, routeId);
List<BlockInstance> instances = _blockCalendarService.getActiveBlocksForRouteInTimeRange(routeAndId, serviceStart, serviceEnd);
if (instances.isEmpty()) {
return false;
}
for (BlockInstance instance : instances) {
List<BlockTripEntry> tripsInBlock = instance.getBlock().getTrips();
if (tripsInBlock.isEmpty()) {
continue;
}
for (BlockTripEntry blockTripEntry : tripsInBlock) {
TripEntry tripEntry = blockTripEntry.getTrip();
if (tripEntry.getRoute().getId().toString().equals(routeId)) {
if (tripEntry.getDirectionId() == null || tripEntry.getDirectionId().equals(directionId)) {
return true;
}
}
}
}
return false;
}
Aggregations