Search in sources :

Example 1 with BlockEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry in project onebusaway-application-modules by camsys.

the class TripBeanServiceImpl method getTripForId.

@Cacheable
public TripBean getTripForId(AgencyAndId tripId) {
    TripEntry tripEntry = _graph.getTripEntryForId(tripId);
    if (tripEntry == null)
        return null;
    AgencyAndId routeId = tripEntry.getRouteCollection().getId();
    RouteBean routeBean = _routeBeanService.getRouteForId(routeId);
    TripNarrative tripNarrative = _narrativeService.getTripForId(tripId);
    TripBean tripBean = new TripBean();
    tripBean.setId(ApplicationBeanLibrary.getId(tripId));
    tripBean.setTripShortName(tripNarrative.getTripShortName());
    tripBean.setTripHeadsign(tripNarrative.getTripHeadsign());
    tripBean.setRoute(routeBean);
    tripBean.setRouteShortName(tripNarrative.getRouteShortName());
    tripBean.setServiceId(ApplicationBeanLibrary.getId(tripEntry.getServiceId().getId()));
    AgencyAndId shapeId = tripEntry.getShapeId();
    if (shapeId != null && shapeId.hasValues())
        tripBean.setShapeId(ApplicationBeanLibrary.getId(shapeId));
    tripBean.setDirectionId(tripEntry.getDirectionId());
    tripBean.setTotalTripDistance(tripEntry.getTotalTripDistance());
    BlockEntry block = tripEntry.getBlock();
    tripBean.setBlockId(ApplicationBeanLibrary.getId(block.getId()));
    return tripBean;
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) BlockEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) TripBean(org.onebusaway.transit_data.model.trips.TripBean) TripNarrative(org.onebusaway.transit_data_federation.model.narrative.TripNarrative) Cacheable(org.onebusaway.container.cache.Cacheable)

Example 2 with BlockEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry in project onebusaway-application-modules by camsys.

the class GtfsRealtimeTripLibrary method getTripDescriptorAsBlockDescriptor.

private BlockDescriptor getTripDescriptorAsBlockDescriptor(MonitoredResult result, TripDescriptor trip, long currentTime) {
    if (!trip.hasTripId()) {
        return null;
    }
    TripEntry tripEntry = _entitySource.getTrip(trip.getTripId());
    if (tripEntry == null) {
        if (result != null) {
            _log.debug("reporting unmatched trip with id=" + trip.getTripId());
            result.addUnmatchedTripId(trip.getTripId());
        } else {
            _log.warn("no trip found with id=" + trip.getTripId());
        }
        return null;
    }
    ServiceDate serviceDate = null;
    BlockInstance instance;
    BlockEntry block = tripEntry.getBlock();
    if (trip.hasStartDate() && !"0".equals(trip.getStartDate())) {
        try {
            serviceDate = ServiceDate.parseString(trip.getStartDate());
        } catch (ParseException ex) {
            _log.warn("Could not parse service date " + trip.getStartDate(), ex);
        }
    }
    if (serviceDate != null) {
        instance = _blockCalendarService.getBlockInstance(block.getId(), serviceDate.getAsDate().getTime());
        if (instance == null) {
            _log.warn("block " + block.getId() + " does not exist on service date " + serviceDate);
            return null;
        }
    } else {
        long timeFrom = currentTime - 30 * 60 * 1000;
        long timeTo = currentTime + 30 * 60 * 1000;
        List<BlockInstance> instances = _blockCalendarService.getActiveBlocks(block.getId(), timeFrom, timeTo);
        if (instances.isEmpty()) {
            instances = _blockCalendarService.getClosestActiveBlocks(block.getId(), currentTime);
        }
        if (instances.isEmpty()) {
            _log.warn("could not find any active instances for the specified block=" + block.getId() + " trip=" + trip);
            return null;
        }
        instance = instances.get(0);
    }
    if (serviceDate == null) {
        serviceDate = new ServiceDate(new Date(instance.getServiceDate()));
    }
    BlockDescriptor blockDescriptor = new BlockDescriptor();
    blockDescriptor.setBlockInstance(instance);
    blockDescriptor.setStartDate(serviceDate);
    if (trip.hasScheduleRelationship()) {
        blockDescriptor.setScheduleRelationshipValue(trip.getScheduleRelationship().toString());
    }
    int tripStartTime = 0;
    int blockStartTime = 0;
    if (trip.hasStartTime() && !"0".equals(trip.getStartTime())) {
        try {
            tripStartTime = StopTimeFieldMappingFactory.getStringAsSeconds(trip.getStartTime());
        } catch (InvalidStopTimeException iste) {
            _log.error("invalid stopTime of " + trip.getStartTime() + " for trip " + trip);
        }
        blockStartTime = getBlockStartTimeForTripStartTime(instance, tripEntry.getId(), tripStartTime);
        blockDescriptor.setStartTime(blockStartTime);
    }
    return blockDescriptor;
}
Also used : ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) BlockEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry) InvalidStopTimeException(org.onebusaway.gtfs.serialization.mappings.InvalidStopTimeException) 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) ParseException(java.text.ParseException) Date(java.util.Date) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint)

Example 3 with BlockEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry in project onebusaway-application-modules by camsys.

the class VehicleStatusServiceImpl method handleVehicleLocationRecord.

/**
 **
 * {@link VehicleLocationListener} Interface
 ***
 */
@Override
public void handleVehicleLocationRecord(VehicleLocationRecord record) {
    if (record.getPhase() == null) {
        // if we've received a report, assume it is in progress/in service
        record.setPhase(EVehiclePhase.IN_PROGRESS);
    }
    if (record.getTimeOfRecord() == 0)
        throw new IllegalArgumentException("you must specify a record time");
    if (record.getVehicleId() != null)
        _vehicleRecordsById.put(record.getVehicleId(), record);
    AgencyAndId blockId = record.getBlockId();
    if (blockId == null) {
        AgencyAndId tripId = record.getTripId();
        if (tripId != null) {
            TripEntry tripEntry = _transitGraphDao.getTripEntryForId(tripId);
            if (tripEntry == null)
                throw new IllegalArgumentException("trip not found with id=" + tripId);
            BlockEntry block = tripEntry.getBlock();
            blockId = block.getId();
        }
    }
    // TODO : Maybe not require service date?
    if (blockId != null && record.getServiceDate() != 0)
        _blockVehicleLocationService.handleVehicleLocationRecord(record);
    else // if vehicle has no block or has lost it, remove it from the block VLS.
    {
        if (record.getVehicleId() != null) {
            _blockVehicleLocationService.resetVehicleLocation(record.getVehicleId());
        }
    }
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) BlockEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)

Example 4 with BlockEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry in project onebusaway-application-modules by camsys.

the class BlockIndexFactoryServiceImpl method createSequenceIndices.

public List<BlockSequenceIndex> createSequenceIndices(Iterable<BlockEntry> blocks) {
    List<BlockSequenceIndex> allIndices = new ArrayList<BlockSequenceIndex>();
    Map<BlockSequenceKey, List<BlockSequence>> blockSequencesByKey = new FactoryMap<BlockSequenceKey, List<BlockSequence>>(new ArrayList<BlockSequence>());
    if (_verbose)
        _log.info("grouping block trips into sequence indices");
    int sequenceCount = 0;
    int blockTripCount = 0;
    for (BlockEntry block : blocks) {
        if (block.getConfigurations().isEmpty()) {
            _log.warn("block has no active configurations: " + block.getId());
            continue;
        }
        if (BlockLibrary.isFrequencyBased(block))
            continue;
        for (BlockConfigurationEntry blockConfiguration : block.getConfigurations()) {
            blockTripCount += blockConfiguration.getTrips().size();
            List<BlockSequence> sequences = groupTrips(blockConfiguration);
            for (BlockSequence sequence : sequences) {
                BlockSequenceKey key = getBlockSequenceAsSequenceKey(sequence);
                blockSequencesByKey.get(key).add(sequence);
                sequenceCount++;
            }
        }
    }
    if (_verbose)
        _log.info("groups found: " + blockSequencesByKey.size() + " out of sequences: " + sequenceCount + " and trips: " + blockTripCount);
    for (List<BlockSequence> sequences : blockSequencesByKey.values()) {
        List<List<BlockSequence>> groupedBlocks = BlockLibrary.createStrictlyOrderedGroups(sequences, _blockSequenceLooseComparator, _blockSequenceStrictComparator);
        for (List<BlockSequence> group : groupedBlocks) {
            BlockSequenceIndex index = createSequenceIndexForGroupOfBlockSequences(group);
            allIndices.add(index);
        }
    }
    return allIndices;
}
Also used : FactoryMap(org.onebusaway.collections.FactoryMap) BlockSequenceIndex(org.onebusaway.transit_data_federation.services.blocks.BlockSequenceIndex) ArrayList(java.util.ArrayList) BlockEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry) ArrayList(java.util.ArrayList) List(java.util.List) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)

Example 5 with BlockEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry in project onebusaway-application-modules by camsys.

the class BlockStopTimeIndicesFactory method groupBlockStopTimes.

/**
 **
 *
 ***
 */
private Map<BlockStopTimeKey, List<BlockStopTimeEntry>> groupBlockStopTimes(Iterable<BlockEntry> blocks, boolean frequencyBased) {
    Map<BlockStopTimeKey, List<BlockStopTimeEntry>> stopTimesByKey = new FactoryMap<BlockStopTimeKey, List<BlockStopTimeEntry>>(new ArrayList<BlockStopTimeEntry>());
    if (_verbose)
        _log.info("grouping block stop times by key");
    int stopTimeCount = 0;
    for (BlockEntry block : blocks) {
        List<BlockConfigurationEntry> configurations = block.getConfigurations();
        if (configurations.isEmpty()) {
            _log.warn("block is not referred to in calendars (no active configurations): " + block.getId());
            continue;
        }
        if (BlockLibrary.isFrequencyBased(block) != frequencyBased)
            continue;
        for (BlockConfigurationEntry blockConfiguration : configurations) {
            List<BlockStopTimeEntry> blockStopTimes = blockConfiguration.getStopTimes();
            for (BlockStopTimeEntry blockStopTime : blockStopTimes) {
                BlockStopTimeKey key = getBlockStopTimeAsKey(blockStopTime);
                List<BlockStopTimeEntry> stopTimesForKey = stopTimesByKey.get(key);
                stopTimesForKey.add(blockStopTime);
                stopTimeCount++;
            }
        }
    }
    if (_verbose)
        _log.info("groups found: " + stopTimesByKey.size() + " out of stopTimes: " + stopTimeCount);
    return stopTimesByKey;
}
Also used : FactoryMap(org.onebusaway.collections.FactoryMap) BlockEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry) ArrayList(java.util.ArrayList) List(java.util.List) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) FrequencyBlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry)

Aggregations

BlockEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry)31 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)13 ArrayList (java.util.ArrayList)11 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)10 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)9 List (java.util.List)8 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)8 Test (org.junit.Test)7 Date (java.util.Date)6 BlockEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl)6 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)6 FrequencyBlockTripIndex (org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex)6 ServiceIdActivation (org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation)6 FactoryMap (org.onebusaway.collections.FactoryMap)5 StopEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)5 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)5 Cacheable (org.onebusaway.container.cache.Cacheable)3 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)3 BlockLayoverIndex (org.onebusaway.transit_data_federation.services.blocks.BlockLayoverIndex)3 BlockTripIndex (org.onebusaway.transit_data_federation.services.blocks.BlockTripIndex)3