Search in sources :

Example 56 with BlockTripEntry

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

the class BlockCalendarServiceImpl method findBlockLayoversInRange.

private void findBlockLayoversInRange(LayoverIntervalBlock intervals, Date serviceDate, Date timeFrom, Date timeTo, List<BlockTripEntry> trips, Collection<BlockInstance> instances) {
    int scheduledTimeFrom = (int) ((timeFrom.getTime() - serviceDate.getTime()) / 1000);
    int scheduledTimeTo = (int) ((timeTo.getTime() - serviceDate.getTime()) / 1000);
    int indexFrom = index(Arrays.binarySearch(intervals.getEndTimes(), scheduledTimeFrom));
    int indexTo = index(Arrays.binarySearch(intervals.getStartTimes(), scheduledTimeTo));
    InstanceState state = new InstanceState(serviceDate.getTime());
    for (int in = indexFrom; in < indexTo; in++) {
        BlockTripEntry trip = trips.get(in);
        BlockConfigurationEntry block = trip.getBlockConfiguration();
        BlockInstance instance = new BlockInstance(block, state);
        instances.add(instance);
    }
}
Also used : InstanceState(org.onebusaway.transit_data_federation.services.blocks.InstanceState) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)

Example 57 with BlockTripEntry

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

the class BlockLocationServiceImpl method getVehicleLocationRecordAsBlockLocationRecord.

private List<BlockLocationRecord> getVehicleLocationRecordAsBlockLocationRecord(BlockInstance blockInstance, VehicleLocationRecord record, ScheduledBlockLocation scheduledBlockLocation) {
    BlockLocationRecord.Builder builder = BlockLocationRecord.builder();
    if (scheduledBlockLocation != null) {
        BlockTripEntry activeTrip = scheduledBlockLocation.getActiveTrip();
        builder.setTripId(activeTrip.getTrip().getId());
        builder.setBlockId(activeTrip.getBlockConfiguration().getBlock().getId());
        // store the vehicleType for later retrieval
        builder.setVehicleType(EVehicleType.toEnum(activeTrip.getTrip().getRoute().getType()));
        double distanceAlongBlock = scheduledBlockLocation.getDistanceAlongBlock();
        builder.setDistanceAlongBlock(distanceAlongBlock);
        double distanceAlongTrip = distanceAlongBlock - activeTrip.getDistanceAlongBlock();
        builder.setDistanceAlongTrip(distanceAlongTrip);
    }
    if (record.getBlockId() != null)
        builder.setBlockId(record.getBlockId());
    if (record.getTripId() != null)
        builder.setTripId(record.getTripId());
    builder.setTime(record.getTimeOfRecord());
    builder.setServiceDate(record.getServiceDate());
    if (record.isScheduleDeviationSet())
        builder.setScheduleDeviation(record.getScheduleDeviation());
    if (record.isDistanceAlongBlockSet()) {
        double distanceAlongBlock = record.getDistanceAlongBlock();
        builder.setDistanceAlongBlock(distanceAlongBlock);
        AgencyAndId tripId = record.getTripId();
        if (tripId != null) {
            BlockConfigurationEntry block = blockInstance.getBlock();
            for (BlockTripEntry blockTrip : block.getTrips()) {
                TripEntry trip = blockTrip.getTrip();
                if (trip.getId().equals(tripId)) {
                    double distanceAlongTrip = distanceAlongBlock - blockTrip.getDistanceAlongBlock();
                    builder.setDistanceAlongTrip(distanceAlongTrip);
                }
            }
        }
    }
    if (record.isCurrentLocationSet()) {
        builder.setLocationLat(record.getCurrentLocationLat());
        builder.setLocationLon(record.getCurrentLocationLon());
    }
    if (record.isCurrentOrientationSet())
        builder.setOrientation(record.getCurrentOrientation());
    builder.setPhase(record.getPhase());
    builder.setStatus(record.getStatus());
    builder.setVehicleId(record.getVehicleId());
    List<TimepointPredictionRecord> predictions = record.getTimepointPredictions();
    if (predictions == null || predictions.isEmpty())
        return Arrays.asList(builder.create());
    List<BlockLocationRecord> results = new ArrayList<BlockLocationRecord>();
    for (TimepointPredictionRecord tpr : predictions) {
        builder.setTimepointId(tpr.getTimepointId());
        builder.setTimepointScheduledTime(tpr.getTimepointScheduledTime());
        builder.setTimepointPredictedArrivalTime(tpr.getTimepointPredictedArrivalTime());
        builder.setTimepointPredictedDepartureTime(tpr.getTimepointPredictedDepartureTime());
        results.add(builder.create());
    }
    return results;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) ArrayList(java.util.ArrayList) TimepointPredictionRecord(org.onebusaway.realtime.api.TimepointPredictionRecord) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)

Example 58 with BlockTripEntry

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

the class GtfsRealtimeTripLibrary method getBlockStartTimeForTripStartTime.

private int getBlockStartTimeForTripStartTime(BlockInstance instance, AgencyAndId tripId, int tripStartTime) {
    BlockConfigurationEntry block = instance.getBlock();
    Map<AgencyAndId, BlockTripEntry> blockTripsById = MappingLibrary.mapToValue(block.getTrips(), "trip.id");
    int rawBlockStartTime = block.getDepartureTimeForIndex(0);
    int rawTripStartTime = blockTripsById.get(tripId).getDepartureTimeForIndex(0);
    int adjustedBlockStartTime = rawBlockStartTime + (tripStartTime - rawTripStartTime);
    return adjustedBlockStartTime;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint)

Example 59 with BlockTripEntry

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

the class BlockBeanServiceImpl method getBlockConfigurationAsBean.

private BlockConfigurationBean getBlockConfigurationAsBean(BlockConfigurationEntry blockConfiguration) {
    BlockConfigurationBean bean = new BlockConfigurationBean();
    ServiceIdActivation serviceIds = blockConfiguration.getServiceIds();
    AgencyAndId blockId = blockConfiguration.getBlock().getId();
    bean.setBlockId(AgencyAndIdLibrary.convertToString(blockId));
    List<String> activeServiceIds = new ArrayList<String>();
    for (LocalizedServiceId lsid : serviceIds.getActiveServiceIds()) activeServiceIds.add(AgencyAndIdLibrary.convertToString(lsid.getId()));
    bean.setActiveServiceIds(activeServiceIds);
    List<String> inactiveServiceIds = new ArrayList<String>();
    for (LocalizedServiceId lsid : serviceIds.getInactiveServiceIds()) inactiveServiceIds.add(AgencyAndIdLibrary.convertToString(lsid.getId()));
    bean.setInactiveServiceIds(inactiveServiceIds);
    List<BlockTripBean> tripBeans = new ArrayList<BlockTripBean>();
    for (BlockTripEntry blockTrip : blockConfiguration.getTrips()) tripBeans.add(getBlockTripAsBean(blockTrip));
    bean.setTrips(tripBeans);
    TimeZone tz = _agencyService.getTimeZoneForAgencyId(blockId.getAgencyId());
    bean.setTimeZone(tz.getID());
    return bean;
}
Also used : BlockTripBean(org.onebusaway.transit_data.model.blocks.BlockTripBean) TimeZone(java.util.TimeZone) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) LocalizedServiceId(org.onebusaway.gtfs.model.calendar.LocalizedServiceId) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) ArrayList(java.util.ArrayList) ServiceIdActivation(org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation) BlockConfigurationBean(org.onebusaway.transit_data.model.blocks.BlockConfigurationBean)

Example 60 with BlockTripEntry

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

the class BlockStatusBeanServiceImpl method bean.

private BlockStatusBean bean(BlockLocation blockLocation) {
    if (blockLocation == null)
        return null;
    BlockInstance instance = blockLocation.getBlockInstance();
    BlockConfigurationEntry block = instance.getBlock();
    long serviceDate = instance.getServiceDate();
    BlockStatusBean bean = new BlockStatusBean();
    bean.setBlock(_blockBeanService.getBlockForId(block.getBlock().getId()));
    bean.setStatus("default");
    bean.setServiceDate(serviceDate);
    bean.setTotalDistanceAlongBlock(block.getTotalBlockDistance());
    bean.setInService(blockLocation.isInService());
    CoordinatePoint location = blockLocation.getLocation();
    bean.setLocation(location);
    bean.setScheduledDistanceAlongBlock(blockLocation.getScheduledDistanceAlongBlock());
    bean.setDistanceAlongBlock(blockLocation.getDistanceAlongBlock());
    BlockTripEntry activeTrip = blockLocation.getActiveTrip();
    if (activeTrip != null) {
        BlockTripBean activeTripBean = _blockBeanService.getBlockTripAsBean(activeTrip);
        bean.setActiveTrip(activeTripBean);
    }
    BlockStopTimeEntry stop = blockLocation.getClosestStop();
    if (stop != null) {
        StopBean stopBean = _stopBeanService.getStopForId(stop.getStopTime().getStop().getId());
        bean.setClosestStop(stopBean);
        bean.setClosestStopTimeOffset(blockLocation.getClosestStopTimeOffset());
    }
    bean.setPredicted(blockLocation.isPredicted());
    bean.setLastUpdateTime(blockLocation.getLastUpdateTime());
    bean.setScheduleDeviation(blockLocation.getScheduleDeviation());
    AgencyAndId vid = blockLocation.getVehicleId();
    if (vid != null)
        bean.setVehicleId(ApplicationBeanLibrary.getId(vid));
    return bean;
}
Also used : CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) BlockTripBean(org.onebusaway.transit_data.model.blocks.BlockTripBean) BlockStatusBean(org.onebusaway.transit_data.model.blocks.BlockStatusBean) 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) StopBean(org.onebusaway.transit_data.model.StopBean) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Aggregations

BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)72 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)30 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)27 ArrayList (java.util.ArrayList)26 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)25 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)23 StopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry)15 List (java.util.List)11 FrequencyEntry (org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry)10 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)10 FactoryMap (org.onebusaway.collections.FactoryMap)9 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)8 HashSet (java.util.HashSet)7 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)7 StopTimeInstance (org.onebusaway.transit_data_federation.model.StopTimeInstance)7 InstanceState (org.onebusaway.transit_data_federation.services.blocks.InstanceState)7 Date (java.util.Date)6 FrequencyBlockTripIndex (org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex)6 ServiceInterval (org.onebusaway.gtfs.model.calendar.ServiceInterval)5 StopSequence (org.onebusaway.transit_data_federation.model.StopSequence)5