Search in sources :

Example 36 with TripEntry

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;
}
Also used : InternalErrorServiceException(org.onebusaway.exceptions.InternalErrorServiceException) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) FrequencyBlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex) BlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) FrequencyBlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) HashSet(java.util.HashSet) Cacheable(org.onebusaway.container.cache.Cacheable)

Example 37 with TripEntry

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);
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ArrayList(java.util.ArrayList) Duration(javax.xml.datatype.Duration) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) Date(java.util.Date) MonitoredVehicleJourney(uk.org.siri.siri.VehicleActivityStructure.MonitoredVehicleJourney) BlockEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) VehicleLocationRecord(org.onebusaway.realtime.api.VehicleLocationRecord)

Example 38 with TripEntry

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;
    }
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)

Example 39 with TripEntry

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);
}
Also used : CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) BlockEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) ArrayList(java.util.ArrayList) List(java.util.List) BlockLocation(org.onebusaway.transit_data_federation.services.realtime.BlockLocation)

Example 40 with TripEntry

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;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)

Aggregations

TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)73 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)46 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)39 ArrayList (java.util.ArrayList)20 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)18 StopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry)15 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)14 HashSet (java.util.HashSet)13 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)10 BlockEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry)10 List (java.util.List)9 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)9 Date (java.util.Date)7 Test (org.junit.Test)7 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)7 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)7 FrequencyEntry (org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry)7 Cacheable (org.onebusaway.container.cache.Cacheable)6 RouteEntry (org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry)6 ServiceIdActivation (org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation)6