Search in sources :

Example 26 with StopBean

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

the class BeanFactoryV2 method getStopsForRoute.

public StopsForRouteV2Bean getStopsForRoute(StopsForRouteBean stopsForRoute, boolean includePolylines) {
    StopsForRouteV2Bean bean = new StopsForRouteV2Bean();
    RouteBean route = stopsForRoute.getRoute();
    if (route != null) {
        addToReferences(route);
        bean.setRouteId(route.getId());
    }
    List<String> stopIds = new ArrayList<String>();
    for (StopBean stop : stopsForRoute.getStops()) {
        stopIds.add(stop.getId());
        addToReferences(stop);
    }
    bean.setStopIds(stopIds);
    bean.setStopGroupings(stopsForRoute.getStopGroupings());
    if (!includePolylines) {
        for (StopGroupingBean grouping : stopsForRoute.getStopGroupings()) {
            for (StopGroupBean group : grouping.getStopGroups()) group.setPolylines(null);
        }
    }
    if (includePolylines)
        bean.setPolylines(stopsForRoute.getPolylines());
    return bean;
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) ArrayList(java.util.ArrayList) StopBean(org.onebusaway.transit_data.model.StopBean)

Example 27 with StopBean

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

the class BeanFactoryV2 method getStopSchedule.

public StopScheduleV2Bean getStopSchedule(StopScheduleBean stopSchedule) {
    StopScheduleV2Bean bean = new StopScheduleV2Bean();
    StopBean stop = stopSchedule.getStop();
    if (stop != null) {
        addToReferences(stop);
        bean.setStopId(stop.getId());
    }
    bean.setDate(stopSchedule.getDate().getTime());
    List<StopRouteScheduleV2Bean> stopRouteScheduleBeans = new ArrayList<StopRouteScheduleV2Bean>();
    for (StopRouteScheduleBean stopRouteSchedule : stopSchedule.getRoutes()) {
        StopRouteScheduleV2Bean stopRouteScheduleBean = getStopRouteSchedule(stopRouteSchedule);
        stopRouteScheduleBeans.add(stopRouteScheduleBean);
    }
    bean.setStopRouteSchedules(stopRouteScheduleBeans);
    return bean;
}
Also used : StopRouteScheduleBean(org.onebusaway.transit_data.model.StopRouteScheduleBean) ArrayList(java.util.ArrayList) StopBean(org.onebusaway.transit_data.model.StopBean)

Example 28 with StopBean

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

the class BeanFactoryV2 method getArrivalAndDeparture.

public ArrivalAndDepartureV2Bean getArrivalAndDeparture(ArrivalAndDepartureBean ad) {
    TripBean trip = ad.getTrip();
    RouteBean route = trip.getRoute();
    StopBean stop = ad.getStop();
    ArrivalAndDepartureV2Bean bean = new ArrivalAndDepartureV2Bean();
    bean.setTripId(trip.getId());
    addToReferences(trip);
    bean.setServiceDate(ad.getServiceDate());
    bean.setVehicleId(ad.getVehicleId());
    bean.setStopId(stop.getId());
    addToReferences(stop);
    bean.setStopSequence(ad.getStopSequence());
    bean.setBlockTripSequence(ad.getBlockTripSequence());
    bean.setTotalStopsInTrip(ad.getTotalStopsInTrip());
    bean.setRouteId(route.getId());
    addToReferences(route);
    String routeShortName = ad.getRouteShortName();
    if (routeShortName == null || routeShortName.isEmpty())
        routeShortName = trip.getRouteShortName();
    if (routeShortName == null || routeShortName.isEmpty())
        routeShortName = route.getShortName();
    bean.setRouteShortName(routeShortName);
    bean.setRouteLongName(route.getLongName());
    String tripHeadsign = ad.getTripHeadsign();
    if (tripHeadsign == null || tripHeadsign.isEmpty())
        tripHeadsign = trip.getTripHeadsign();
    bean.setTripHeadsign(tripHeadsign);
    bean.setArrivalEnabled(ad.isArrivalEnabled());
    bean.setDepartureEnabled(ad.isDepartureEnabled());
    bean.setScheduledArrivalTime(ad.getScheduledArrivalTime());
    bean.setScheduledDepartureTime(ad.getScheduledDepartureTime());
    bean.setPredictedArrivalTime(ad.getPredictedArrivalTime());
    bean.setPredictedDepartureTime(ad.getPredictedDepartureTime());
    bean.setScheduledArrivalInterval(getTimeInterval(ad.getScheduledArrivalInterval()));
    bean.setScheduledDepartureInterval(getTimeInterval(ad.getScheduledDepartureInterval()));
    bean.setPredictedArrivalInterval(getTimeInterval(ad.getPredictedArrivalInterval()));
    bean.setPredictedDepartureInterval(getTimeInterval(ad.getPredictedDepartureInterval()));
    if (ad.getFrequency() != null)
        bean.setFrequency(getFrequency(ad.getFrequency()));
    bean.setStatus(ad.getStatus());
    if (ad.isDistanceFromStopSet())
        bean.setDistanceFromStop(ad.getDistanceFromStop());
    bean.setNumberOfStopsAway(ad.getNumberOfStopsAway());
    TripStatusBean tripStatus = ad.getTripStatus();
    if (tripStatus != null)
        bean.setTripStatus(getTripStatus(tripStatus));
    bean.setPredicted(ad.isPredicted());
    bean.setLastUpdateTime(ad.getLastUpdateTime());
    List<ServiceAlertBean> situations = ad.getSituations();
    if (situations != null && !situations.isEmpty()) {
        List<String> situationIds = new ArrayList<String>();
        for (ServiceAlertBean situation : situations) {
            situationIds.add(situation.getId());
            addToReferences(situation);
        }
        bean.setSituationIds(situationIds);
    }
    return bean;
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) ArrayList(java.util.ArrayList) BlockTripBean(org.onebusaway.transit_data.model.blocks.BlockTripBean) TripBean(org.onebusaway.transit_data.model.trips.TripBean) StopBean(org.onebusaway.transit_data.model.StopBean) TripStatusBean(org.onebusaway.transit_data.model.trips.TripStatusBean) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)

Example 29 with StopBean

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

the class TripUpdatesForAgencyAction method fillFeedMessage.

@Override
protected void fillFeedMessage(FeedMessage.Builder feed, String agencyId, long timestamp) {
    ListBean<VehicleStatusBean> vehicles = _service.getAllVehiclesForAgency(agencyId, timestamp);
    for (VehicleStatusBean vehicle : vehicles.getList()) {
        TripStatusBean tripStatus = vehicle.getTripStatus();
        if (tripStatus == null) {
            continue;
        }
        TripBean activeTrip = tripStatus.getActiveTrip();
        RouteBean route = activeTrip.getRoute();
        FeedEntity.Builder entity = feed.addEntityBuilder();
        entity.setId(Integer.toString(feed.getEntityCount()));
        TripUpdate.Builder tripUpdate = entity.getTripUpdateBuilder();
        TripDescriptor.Builder tripDesc = tripUpdate.getTripBuilder();
        tripDesc.setTripId(normalizeId(activeTrip.getId()));
        tripDesc.setRouteId(normalizeId(route.getId()));
        VehicleDescriptor.Builder vehicleDesc = tripUpdate.getVehicleBuilder();
        vehicleDesc.setId(normalizeId(vehicle.getVehicleId()));
        if (tripStatus.getTimepointPredictions() != null && tripStatus.getTimepointPredictions().size() > 0) {
            for (TimepointPredictionBean timepointPrediction : tripStatus.getTimepointPredictions()) {
                AgencyAndId stopId = modifiedStopId(agencyId, timepointPrediction.getTimepointId());
                if (!stopId.getAgencyId().equals(agencyId))
                    continue;
                TripUpdate.StopTimeUpdate.Builder stopTimeUpdate = tripUpdate.addStopTimeUpdateBuilder();
                stopTimeUpdate.setStopId(normalizeId(stopId.toString()));
                TripUpdate.StopTimeEvent.Builder arrival = stopTimeUpdate.getArrivalBuilder();
                if (timepointPrediction.getTimepointPredictedArrivalTime() != -1) {
                    arrival.setTime(timepointPrediction.getTimepointPredictedArrivalTime() / 1000L);
                }
                TripUpdate.StopTimeEvent.Builder departure = stopTimeUpdate.getDepartureBuilder();
                if (timepointPrediction.getTimepointPredictedDepartureTime() != -1) {
                    departure.setTime(timepointPrediction.getTimepointPredictedDepartureTime() / 1000L);
                }
            }
            tripUpdate.setTimestamp(vehicle.getLastUpdateTime() / 1000);
        } else {
            StopBean nextStop = tripStatus.getNextStop();
            if (nextStop != null) {
                AgencyAndId stopId = modifiedStopId(agencyId, nextStop.getId());
                if (stopId.getAgencyId().equals(agencyId)) {
                    TripUpdate.StopTimeUpdate.Builder stopTimeUpdate = tripUpdate.addStopTimeUpdateBuilder();
                    stopTimeUpdate.setStopId(normalizeId(stopId.toString()));
                    TripUpdate.StopTimeEvent.Builder departure = stopTimeUpdate.getDepartureBuilder();
                    departure.setTime(timestamp / 1000 + tripStatus.getNextStopTimeOffset());
                }
            }
        }
        tripUpdate.setDelay((int) tripStatus.getScheduleDeviation());
        tripUpdate.setTimestamp(vehicle.getLastUpdateTime() / 1000);
    }
}
Also used : TimepointPredictionBean(org.onebusaway.transit_data.model.trips.TimepointPredictionBean) TripUpdate(com.google.transit.realtime.GtfsRealtime.TripUpdate) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TripBean(org.onebusaway.transit_data.model.trips.TripBean) VehicleStatusBean(org.onebusaway.transit_data.model.VehicleStatusBean) RouteBean(org.onebusaway.transit_data.model.RouteBean) TripDescriptor(com.google.transit.realtime.GtfsRealtime.TripDescriptor) StopBean(org.onebusaway.transit_data.model.StopBean) TripStatusBean(org.onebusaway.transit_data.model.trips.TripStatusBean) FeedEntity(com.google.transit.realtime.GtfsRealtime.FeedEntity) VehicleDescriptor(com.google.transit.realtime.GtfsRealtime.VehicleDescriptor)

Example 30 with StopBean

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

the class ArrivalsAndDeparturesForStopAction method getArrivalsAsV1.

private List<ArrivalAndDepartureBeanV1> getArrivalsAsV1(StopWithArrivalsAndDeparturesBean result) {
    List<ArrivalAndDepartureBeanV1> v1s = new ArrayList<ArrivalAndDepartureBeanV1>();
    for (ArrivalAndDepartureBean bean : result.getArrivalsAndDepartures()) {
        TripBean trip = bean.getTrip();
        RouteBean route = trip.getRoute();
        StopBean stop = bean.getStop();
        ArrivalAndDepartureBeanV1 v1 = new ArrivalAndDepartureBeanV1();
        v1.setPredictedArrivalTime(bean.getPredictedArrivalTime());
        v1.setPredictedDepartureTime(bean.getPredictedDepartureTime());
        v1.setRouteId(route.getId());
        if (trip.getRouteShortName() != null)
            v1.setRouteShortName(trip.getRouteShortName());
        else
            v1.setRouteShortName(route.getShortName());
        v1.setScheduledArrivalTime(bean.getScheduledArrivalTime());
        v1.setScheduledDepartureTime(bean.getScheduledDepartureTime());
        v1.setStatus(bean.getStatus());
        v1.setStopId(stop.getId());
        v1.setTripHeadsign(trip.getTripHeadsign());
        v1.setTripId(trip.getId());
        v1s.add(v1);
    }
    return v1s;
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) ArrivalAndDepartureBeanV1(org.onebusaway.api.model.where.ArrivalAndDepartureBeanV1) ArrayList(java.util.ArrayList) TripBean(org.onebusaway.transit_data.model.trips.TripBean) StopBean(org.onebusaway.transit_data.model.StopBean) ArrivalAndDepartureBean(org.onebusaway.transit_data.model.ArrivalAndDepartureBean)

Aggregations

StopBean (org.onebusaway.transit_data.model.StopBean)69 ArrayList (java.util.ArrayList)34 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)23 RouteBean (org.onebusaway.transit_data.model.RouteBean)22 StopsForRouteBean (org.onebusaway.transit_data.model.StopsForRouteBean)17 StopGroupBean (org.onebusaway.transit_data.model.StopGroupBean)15 StopGroupingBean (org.onebusaway.transit_data.model.StopGroupingBean)15 HashMap (java.util.HashMap)12 CoordinateBounds (org.onebusaway.geospatial.model.CoordinateBounds)9 ArrivalAndDepartureBean (org.onebusaway.transit_data.model.ArrivalAndDepartureBean)9 NameBean (org.onebusaway.transit_data.model.NameBean)9 ServiceAlertBean (org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)8 TripBean (org.onebusaway.transit_data.model.trips.TripBean)8 HashSet (java.util.HashSet)7 StopsBean (org.onebusaway.transit_data.model.StopsBean)7 List (java.util.List)6 BlockTripBean (org.onebusaway.transit_data.model.blocks.BlockTripBean)6 Test (org.junit.Test)5 SearchQueryBean (org.onebusaway.transit_data.model.SearchQueryBean)5 TripStatusBean (org.onebusaway.transit_data.model.trips.TripStatusBean)5