Search in sources :

Example 46 with RouteBean

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

the class ArrivalsAndDeparturesTemplate method buildPredictedArrivalsTemplate.

protected void buildPredictedArrivalsTemplate(List<ArrivalAndDepartureBean> arrivals) {
    if (arrivals.isEmpty()) {
        addMessage(Messages.ARRIVAL_INFO_NO_SCHEDULED_ARRIVALS);
    }
    Collections.sort(arrivals, new ArrivalAndDepartureComparator());
    long now = SystemTime.currentTimeMillis();
    for (ArrivalAndDepartureBean adb : arrivals) {
        TripBean trip = adb.getTrip();
        RouteBean route = trip.getRoute();
        addMessage(Messages.ROUTE);
        String routeNumber = RoutePresenter.getNameForRoute(route);
        addText(_routeNumberPronunciation.modify(routeNumber));
        String headsign = trip.getTripHeadsign();
        if (headsign != null) {
            addMessage(Messages.TO);
            String destination = _destinationPronunciation.modify(headsign);
            addText(destination);
        }
        if (TransitDataConstants.STATUS_LEGACY_CANCELLED.equalsIgnoreCase(adb.getStatus())) {
            addText("is currently not in service");
            continue;
        }
        long t = adb.computeBestDepartureTime();
        boolean isPrediction = adb.hasPredictedDepartureTime();
        int min = (int) ((t - now) / 1000 / 60);
        if (min < 0) {
            min = -min;
            if (min > 60) {
                String message = isPrediction ? Messages.PREDICTED_AT_PAST_DATE : Messages.SCHEDULED_AT_PAST_DATE;
                addMessage(message, new Date(t));
            } else {
                String message = isPrediction ? Messages.PREDICTED_IN_PAST : Messages.SCHEDULED_IN_PAST;
                addMessage(message, min);
            }
        } else {
            if (min > 60) {
                String message = isPrediction ? Messages.PREDICTED_AT_FUTURE_DATE : Messages.SCHEDULED_AT_FUTURE_DATE;
                addMessage(message, new Date(t));
            } else {
                String message = isPrediction ? Messages.PREDICTED_IN_FUTURE : Messages.SCHEDULED_IN_FUTURE;
                addMessage(message, min);
            }
        }
        if (TransitDataConstants.STATUS_REROUTE.equals(adb.getStatus()))
            addText("but is currently on adverse weather re-route.");
    }
    addMessage(Messages.ARRIVAL_INFO_DISCLAIMER);
    List<AgencyBean> agencies = AgencyPresenter.getAgenciesForArrivalAndDepartures(arrivals);
    if (!agencies.isEmpty()) {
        addMessage(Messages.ARRIVAL_INFO_DATA_PROVIDED_BY);
        for (int i = 0; i < agencies.size(); i++) {
            AgencyBean agency = agencies.get(i);
            if (i == agencies.size() - 1 && agencies.size() > 1)
                addText(Messages.AND);
            addText(agency.getName());
            addText(",");
        }
    }
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) ArrivalAndDepartureComparator(org.onebusaway.presentation.impl.ArrivalAndDepartureComparator) TripBean(org.onebusaway.transit_data.model.trips.TripBean) ArrivalAndDepartureBean(org.onebusaway.transit_data.model.ArrivalAndDepartureBean) Date(java.util.Date) AgencyBean(org.onebusaway.transit_data.model.AgencyBean)

Example 47 with RouteBean

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

the class StopBeanServiceImplTest method testGetStopForId.

@Test
public void testGetStopForId() {
    AgencyAndId stopId = new AgencyAndId("29", "1109");
    StopEntryImpl stopEntry = new StopEntryImpl(stopId, 47.1, -122.1);
    Mockito.when(_transitGraphDao.getStopEntryForId(stopId)).thenReturn(stopEntry);
    StopNarrative.Builder builder = StopNarrative.builder();
    builder.setCode("1109-b");
    builder.setDescription("stop description");
    builder.setLocationType(0);
    builder.setName("stop name");
    builder.setUrl("http://some/url");
    builder.setDirection("N");
    StopNarrative stop = builder.create();
    Mockito.when(_narrativeService.getStopForId(stopId)).thenReturn(stop);
    AgencyAndId routeId = new AgencyAndId("1", "route");
    Set<AgencyAndId> routeIds = new HashSet<AgencyAndId>();
    routeIds.add(routeId);
    Mockito.when(_routeService.getRouteCollectionIdsForStop(stopId)).thenReturn(routeIds);
    RouteBean.Builder routeBuilder = RouteBean.builder();
    routeBuilder.setId(AgencyAndIdLibrary.convertToString(routeId));
    RouteBean route = routeBuilder.create();
    Mockito.when(_routeBeanService.getRouteForId(routeId)).thenReturn(route);
    StopBean stopBean = _service.getStopForId(stopId);
    assertNotNull(stopBean);
    assertEquals(stopId.toString(), stopBean.getId());
    assertEquals(stop.getName(), stopBean.getName());
    assertEquals(stopEntry.getStopLat(), stopBean.getLat(), 0.0);
    assertEquals(stopEntry.getStopLon(), stopBean.getLon(), 0.0);
    assertEquals(stop.getCode(), stopBean.getCode());
    assertEquals(stop.getLocationType(), stopBean.getLocationType());
    List<RouteBean> routes = stopBean.getRoutes();
    assertEquals(1, routes.size());
    assertSame(route, routes.get(0));
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) StopBean(org.onebusaway.transit_data.model.StopBean) StopNarrative(org.onebusaway.transit_data_federation.model.narrative.StopNarrative) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 48 with RouteBean

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

the class RouteForNameAction method execute.

public String execute() throws Exception {
    _log.debug("in RouteForName with routeName " + _routeName);
    CoordinateBounds bounds = getDefaultSearchArea();
    if (bounds == null) {
        return NEEDS_DEFAULT_SEARCH_LOCATION;
    }
    if (_routeName == null || _routeName.length() == 0) {
        return INPUT;
    }
    SearchQueryBean routesQuery = new SearchQueryBean();
    routesQuery.setBounds(bounds);
    routesQuery.setMaxCount(10);
    routesQuery.setQuery(_routeName);
    routesQuery.setType(EQueryType.BOUNDS_OR_CLOSEST);
    RoutesBean routesBean = _transitDataService.getRoutes(routesQuery);
    List<RouteBean> routes = routesBean.getRoutes();
    sessionMap.put("navState", new Integer(DISPLAY_DATA));
    logUserInteraction("route", _routeName);
    if (routes.size() == 0) {
        sessionMap.put("messageFromAction", getText(Messages.NO_ROUTES_WERE_FOUND));
        sessionMap.put("backAction", "search-index");
        return "noRoutesFound";
    } else if (routes.size() == 1) {
        _route = routes.get(0);
        return SUCCESS;
    } else {
        _routes = routes;
        return "multipleRoutesFound";
    }
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) SearchQueryBean(org.onebusaway.transit_data.model.SearchQueryBean) RoutesBean(org.onebusaway.transit_data.model.RoutesBean) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds)

Example 49 with RouteBean

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

the class RealtimeServiceV2Impl method getAnnotatedLineStructures.

@Override
public Map<Boolean, List<AnnotatedLineStructure>> getAnnotatedLineStructures(List<String> agencyIds, List<AgencyAndId> routeIds, DetailLevel detailLevel, long currentTime, Map<Filters, String> filters) {
    // Store processed StopBean as AnnotatedStopPointStructure
    List<AnnotatedLineStructure> annotatedLines = new ArrayList<AnnotatedLineStructure>();
    // AnnotatedStopPointStructures List with hasUpcomingScheduledService
    Map<Boolean, List<AnnotatedLineStructure>> output = new HashMap<Boolean, List<AnnotatedLineStructure>>();
    Boolean upcomingServiceAllStops = null;
    for (AgencyAndId rteId : routeIds) {
        String routeId = AgencyAndId.convertToString(rteId);
        RouteBean routeBean = _transitDataService.getRouteForId(routeId);
        // Filter By AgencyID
        if (routeBean.getAgency() == null || !agencyIds.contains(routeBean.getAgency().getId()))
            continue;
        AnnotatedLineStructure annotatedLineStructure = new AnnotatedLineStructure();
        RouteResult routeResult = getRouteResult(routeBean, filters);
        // Skip Routes with no stops
        if (routeResult.getDirections() == null || routeResult.getDirections().size() == 0)
            continue;
        boolean isValid = SiriSupportV2.fillAnnotatedLineStructure(annotatedLineStructure, routeResult, filters, detailLevel, currentTime);
        if (isValid)
            annotatedLines.add(annotatedLineStructure);
    }
    output.put(upcomingServiceAllStops, annotatedLines);
    return output;
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) HashMap(java.util.HashMap) RouteResult(org.onebusaway.api.actions.siri.model.RouteResult) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) AnnotatedLineStructure(uk.org.siri.siri_2.AnnotatedLineStructure)

Example 50 with RouteBean

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

the class RealtimeServiceV2Impl method getStopRouteDirection.

private StopRouteDirection getStopRouteDirection(StopBean stop, List<StopsForRouteBean> stopsForRouteList, Map<Filters, String> filters) {
    // Filter Values
    String upcomingScheduledServiceFilter = filters.get(Filters.UPCOMING_SCHEDULED_SERVICE);
    String directionIdFilter = filters.get(Filters.DIRECTION_REF);
    StopRouteDirection stopRouteDirection = new StopRouteDirection(stop);
    for (StopsForRouteBean stopsForRoute : stopsForRouteList) // Check to see which stop group the specified stop exists in (usually 2 stop groups)
    for (StopGroupingBean stopGrouping : stopsForRoute.getStopGroupings()) {
        for (StopGroupBean stopGroup : stopGrouping.getStopGroups()) {
            NameBean name = stopGroup.getName();
            String type = name.getType();
            String directionId = stopGroup.getId();
            RouteBean route = stopsForRoute.getRoute();
            // Destination and DirectionId Filter
            if (!type.equals("destination") || !SiriSupportV2.passFilter(directionId, directionIdFilter))
                continue;
            // filter out route directions that don't stop at this stop
            if (!stopGroup.getStopIds().contains(stop.getId()))
                continue;
            // filter hasUpcomingScheduledService
            Boolean hasUpcomingScheduledService = _transitDataService.stopHasUpcomingScheduledService((route.getAgency() != null ? route.getAgency().getId() : null), SystemTime.currentTimeMillis(), stop.getId(), stopsForRoute.getRoute().getId(), directionId);
            String hasUpcomingScheduledServiceVal = String.valueOf(hasUpcomingScheduledService);
            if (!hasUpcomingScheduledServiceVal.trim().equals("false")) {
                hasUpcomingScheduledServiceVal = "true";
            }
            if (!SiriSupportV2.passFilter(hasUpcomingScheduledServiceVal, upcomingScheduledServiceFilter))
                continue;
            stopRouteDirection.addRouteDirection(new RouteForDirection(route.getId(), directionId, hasUpcomingScheduledService));
        }
    }
    return stopRouteDirection;
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) StopRouteDirection(org.onebusaway.api.actions.siri.model.StopRouteDirection) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) RouteForDirection(org.onebusaway.api.actions.siri.model.RouteForDirection) NameBean(org.onebusaway.transit_data.model.NameBean)

Aggregations

RouteBean (org.onebusaway.transit_data.model.RouteBean)63 ArrayList (java.util.ArrayList)35 StopsForRouteBean (org.onebusaway.transit_data.model.StopsForRouteBean)24 StopBean (org.onebusaway.transit_data.model.StopBean)22 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)18 TripBean (org.onebusaway.transit_data.model.trips.TripBean)14 StopGroupBean (org.onebusaway.transit_data.model.StopGroupBean)12 StopGroupingBean (org.onebusaway.transit_data.model.StopGroupingBean)12 List (java.util.List)9 HashMap (java.util.HashMap)7 HashSet (java.util.HashSet)7 CoordinateBounds (org.onebusaway.geospatial.model.CoordinateBounds)7 NameBean (org.onebusaway.transit_data.model.NameBean)7 Date (java.util.Date)6 Test (org.junit.Test)6 AgencyBean (org.onebusaway.transit_data.model.AgencyBean)6 ArrivalAndDepartureBean (org.onebusaway.transit_data.model.ArrivalAndDepartureBean)6 IOException (java.io.IOException)5 Matchers.anyString (org.mockito.Matchers.anyString)5 SearchQueryBean (org.onebusaway.transit_data.model.SearchQueryBean)5