Search in sources :

Example 26 with TripBean

use of org.onebusaway.transit_data.model.trips.TripBean in project onebusaway-application-modules by camsys.

the class ArrivalsAndDeparturesAction method filterArrivalsAndDeparturesByRoute.

private void filterArrivalsAndDeparturesByRoute(String[] tokens) {
    // Filter by route
    Set<String> routes = new HashSet<String>();
    for (String token : tokens) {
        String[] routeNames = token.split(",");
        for (String routeName : routeNames) routes.add(routeName);
    }
    StopsWithArrivalsAndDeparturesBean result = _model.getResult();
    Iterator<ArrivalAndDepartureBean> it = result.getArrivalsAndDepartures().iterator();
    while (it.hasNext()) {
        ArrivalAndDepartureBean bean = it.next();
        TripBean trip = bean.getTrip();
        RouteBean route = trip.getRoute();
        String routeName = RoutePresenter.getNameForRoute(route);
        if (!routes.contains(routeName))
            it.remove();
    }
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsWithArrivalsAndDeparturesBean(org.onebusaway.transit_data.model.StopsWithArrivalsAndDeparturesBean) TripBean(org.onebusaway.transit_data.model.trips.TripBean) ArrivalAndDepartureBean(org.onebusaway.transit_data.model.ArrivalAndDepartureBean) HashSet(java.util.HashSet)

Example 27 with TripBean

use of org.onebusaway.transit_data.model.trips.TripBean in project onebusaway-application-modules by camsys.

the class RouteNameComponent method end.

@Override
public boolean end(Writer writer, String body) {
    if (_value == null)
        _value = "top";
    Object obj = findValue(_value);
    if (obj instanceof TripBean) {
        TripBean trip = (TripBean) obj;
        String routeShortName = trip.getRouteShortName();
        if (routeShortName != null) {
            try {
                writer.write(routeShortName);
            } catch (IOException e) {
                LOG.error("Could not write out Text tag", e);
            }
        } else {
            obj = trip.getRoute();
        }
    }
    if (obj instanceof RouteBean) {
        RouteBean route = (RouteBean) obj;
        String name = RoutePresenter.getNameForRoute(route);
        try {
            writer.write(name);
        } catch (IOException e) {
            LOG.error("Could not write out Text tag", e);
        }
    }
    return super.end(writer, "");
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) TripBean(org.onebusaway.transit_data.model.trips.TripBean) IOException(java.io.IOException)

Example 28 with TripBean

use of org.onebusaway.transit_data.model.trips.TripBean in project onebusaway-application-modules by camsys.

the class TripStatusBeanServiceImpl method getBlockLocationAsStatusBean.

@Override
public TripStatusBean getBlockLocationAsStatusBean(BlockLocation blockLocation, long time) {
    TripStatusBean bean = new TripStatusBean();
    bean.setStatus("default");
    BlockInstance blockInstance = blockLocation.getBlockInstance();
    long serviceDate = blockInstance.getServiceDate();
    bean.setServiceDate(serviceDate);
    bean.setLastUpdateTime(blockLocation.getLastUpdateTime());
    bean.setLastLocationUpdateTime(blockLocation.getLastLocationUpdateTime());
    bean.setLastKnownLocation(blockLocation.getLastKnownLocation());
    bean.setLastKnownOrientation(blockLocation.getLastKnownOrientation());
    bean.setLocation(blockLocation.getLocation());
    bean.setOrientation(blockLocation.getOrientation());
    bean.setLastKnownLocation(blockLocation.getLastKnownLocation());
    if (blockLocation.isLastKnownOrientationSet())
        bean.setLastKnownOrientation(blockLocation.getLastKnownOrientation());
    bean.setScheduleDeviation(blockLocation.getScheduleDeviation());
    BlockTripInstance activeTripInstance = blockLocation.getActiveTripInstance();
    if (activeTripInstance != null) {
        BlockTripEntry activeBlockTrip = activeTripInstance.getBlockTrip();
        bean.setScheduledDistanceAlongTrip(blockLocation.getScheduledDistanceAlongBlock() - activeBlockTrip.getDistanceAlongBlock());
        bean.setDistanceAlongTrip(blockLocation.getDistanceAlongBlock() - activeBlockTrip.getDistanceAlongBlock());
        TripEntry activeTrip = activeBlockTrip.getTrip();
        bean.setTotalDistanceAlongTrip(activeTrip.getTotalTripDistance());
        TripBean activeTripBean = _tripBeanService.getTripForId(activeTrip.getId());
        bean.setActiveTrip(activeTripBean);
        bean.setBlockTripSequence(activeBlockTrip.getSequence());
        if (blockLocation.isLastKnownDistanceAlongBlockSet()) {
            bean.setLastKnownDistanceAlongTrip(blockLocation.getLastKnownDistanceAlongBlock() - activeBlockTrip.getDistanceAlongBlock());
        }
        FrequencyEntry frequencyLabel = activeTripInstance.getFrequencyLabel();
        if (frequencyLabel != null) {
            FrequencyBean fb = FrequencyBeanLibrary.getBeanForFrequency(serviceDate, frequencyLabel);
            bean.setFrequency(fb);
        }
    } else {
        _log.warn("no active block trip for block location: blockInstance=" + blockLocation.getBlockInstance() + " time=" + time);
    }
    BlockStopTimeEntry closestStop = blockLocation.getClosestStop();
    if (closestStop != null) {
        StopTimeEntry stopTime = closestStop.getStopTime();
        StopBean stopBean = _stopBeanService.getStopForId(stopTime.getStop().getId());
        bean.setClosestStop(stopBean);
        bean.setClosestStopTimeOffset(blockLocation.getClosestStopTimeOffset());
    }
    BlockStopTimeEntry nextStop = blockLocation.getNextStop();
    if (nextStop != null) {
        StopTimeEntry stopTime = nextStop.getStopTime();
        StopBean stopBean = _stopBeanService.getStopForId(stopTime.getStop().getId());
        bean.setNextStop(stopBean);
        bean.setNextStopTimeOffset(blockLocation.getNextStopTimeOffset());
        bean.setNextStopDistanceFromVehicle(blockLocation.getNextStop().getDistanceAlongBlock() - blockLocation.getDistanceAlongBlock());
    }
    BlockStopTimeEntry previousStop = blockLocation.getPreviousStop();
    if (previousStop != null) {
        StopTimeEntry stopTime = previousStop.getStopTime();
        StopBean stopBean = _stopBeanService.getStopForId(stopTime.getStop().getId());
        bean.setPreviousStop(stopBean);
        bean.setPreviousStopTimeOffset(blockLocation.getPreviousStopTimeOffset());
        bean.setPreviousStopDistanceFromVehicle(blockLocation.getPreviousStop().getDistanceAlongBlock() - blockLocation.getDistanceAlongBlock());
    }
    EVehiclePhase phase = blockLocation.getPhase();
    if (phase != null)
        bean.setPhase(phase.toLabel());
    String status = blockLocation.getStatus();
    if (status != null)
        bean.setStatus(status);
    if (blockLocation.getVehicleType() != null)
        bean.setVehicleType(blockLocation.getVehicleType().toLabel());
    bean.setPredicted(blockLocation.isPredicted());
    AgencyAndId vid = blockLocation.getVehicleId();
    if (vid != null)
        bean.setVehicleId(ApplicationBeanLibrary.getId(vid));
    if (activeTripInstance != null) {
        List<ServiceAlertBean> situations = _serviceAlertBeanService.getServiceAlertsForVehicleJourney(time, activeTripInstance, blockLocation.getVehicleId());
        if (!situations.isEmpty())
            bean.setSituations(situations);
    }
    if (blockLocation.getTimepointPredictions() != null && blockLocation.getTimepointPredictions().size() > 0) {
        List<TimepointPredictionBean> timepointPredictions = new ArrayList<TimepointPredictionBean>();
        for (TimepointPredictionRecord tpr : blockLocation.getTimepointPredictions()) {
            TimepointPredictionBean tpb = new TimepointPredictionBean();
            tpb.setTimepointId(tpr.getTimepointId().toString());
            tpb.setTripId(tpr.getTripId().toString());
            tpb.setStopSequence(tpr.getStopSequence());
            tpb.setTimepointPredictedArrivalTime(tpr.getTimepointPredictedArrivalTime());
            tpb.setTimepointPredictedDepartureTime(tpr.getTimepointPredictedDepartureTime());
            timepointPredictions.add(tpb);
        }
        bean.setTimepointPredictions(timepointPredictions);
    }
    return bean;
}
Also used : TimepointPredictionBean(org.onebusaway.transit_data.model.trips.TimepointPredictionBean) BlockTripInstance(org.onebusaway.transit_data_federation.services.blocks.BlockTripInstance) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) ArrayList(java.util.ArrayList) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) TripBean(org.onebusaway.transit_data.model.trips.TripBean) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry) EVehiclePhase(org.onebusaway.realtime.api.EVehiclePhase) FrequencyBean(org.onebusaway.transit_data.model.schedule.FrequencyBean) StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) TimepointPredictionRecord(org.onebusaway.realtime.api.TimepointPredictionRecord) StopBean(org.onebusaway.transit_data.model.StopBean) TripStatusBean(org.onebusaway.transit_data.model.trips.TripStatusBean) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Aggregations

TripBean (org.onebusaway.transit_data.model.trips.TripBean)28 RouteBean (org.onebusaway.transit_data.model.RouteBean)14 TripStatusBean (org.onebusaway.transit_data.model.trips.TripStatusBean)12 ArrayList (java.util.ArrayList)11 ArrivalAndDepartureBean (org.onebusaway.transit_data.model.ArrivalAndDepartureBean)8 StopBean (org.onebusaway.transit_data.model.StopBean)8 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)6 BlockTripBean (org.onebusaway.transit_data.model.blocks.BlockTripBean)6 FrequencyBean (org.onebusaway.transit_data.model.schedule.FrequencyBean)6 Date (java.util.Date)5 ServiceAlertBean (org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)5 FeedEntity (com.google.transit.realtime.GtfsRealtime.FeedEntity)4 Test (org.junit.Test)4 VehicleStatusBean (org.onebusaway.transit_data.model.VehicleStatusBean)4 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)4 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)4 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)4 TimepointPredictionRecord (org.onebusaway.realtime.api.TimepointPredictionRecord)3 TripStopTimesBean (org.onebusaway.transit_data.model.TripStopTimesBean)3 FrequencyEntry (org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry)3