Search in sources :

Example 16 with TripBean

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

the class ArrivalsAndDeparturesPresentaion method getTripHeadsign.

public String getTripHeadsign(ArrivalAndDepartureBean bean) {
    if (bean.getTripHeadsign() != null)
        return bean.getTripHeadsign();
    TripBean trip = bean.getTrip();
    if (trip.getTripHeadsign() != null)
        return trip.getTripHeadsign();
    RouteBean route = trip.getRoute();
    return RoutePresenter.getDescriptionForRoute(route);
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) TripBean(org.onebusaway.transit_data.model.trips.TripBean)

Example 17 with TripBean

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

the class PresentationServiceImpl method include.

/**
 * These rules are just for SIRI SM calls.
 */
@Override
public boolean include(ArrivalAndDepartureBean adBean, TripStatusBean status) {
    if (adBean == null || status == null) {
        _log.debug("null info");
        return false;
    }
    if (status.isPredicted()) {
        if (adBean.getPredictedArrivalTime() > 0 && adBean.getPredictedArrivalTime() < getTime() && adBean.getDistanceFromStop() != 0.0) {
            _log.debug(" prediction in past drop");
            return false;
        }
        // hide buses that are on detour from a-d queries
        if (isOnDetour(status)) {
            _log.debug(" detour drop");
            return false;
        }
    } else {
        if (adBean.getScheduledArrivalTime() > 0 && adBean.getScheduledArrivalTime() < getTime()) {
            _log.debug("shcheduled arrival in past drop");
            return false;
        }
    }
    // wrap-around logic
    String phase = status.getPhase();
    TripBean activeTrip = status.getActiveTrip();
    TripBean adTripBean = adBean.getTrip();
    // if ad is not on the trip this bus is on, or the previous trip, filter out
    if (!adTripBean.getId().equals(activeTrip.getId()) && !(adBean.getBlockTripSequence() - 1 == status.getBlockTripSequence())) {
        _log.debug("  " + status.getVehicleId() + " filtered out due to trip block sequence");
        return false;
    }
    // only buses that are on the same or previous trip as the a-d make it to this point:
    if (activeTrip != null && !adTripBean.getId().equals(activeTrip.getId())) {
        double distanceAlongTrip = status.getDistanceAlongTrip();
        double totalDistanceAlongTrip = status.getTotalDistanceAlongTrip();
        double distanceFromTerminalMeters = totalDistanceAlongTrip - distanceAlongTrip;
        if (distanceFromTerminalMeters > (_previousTripFilterDistanceMiles * 1609)) {
            _log.debug("  " + status.getVehicleId() + " filtered out due to distance from terminal on prev. trip " + distanceFromTerminalMeters + " > " + (_previousTripFilterDistanceMiles * 1609));
            return false;
        }
    }
    // filter out buses that are in layover at the beginning of the previous trip
    if (phase != null && (phase.toUpperCase().equals("LAYOVER_BEFORE") || phase.toUpperCase().equals("LAYOVER_DURING"))) {
        double distanceAlongTrip = status.getDistanceAlongTrip();
        double totalDistanceAlongTrip = status.getTotalDistanceAlongTrip();
        double ratio = distanceAlongTrip / totalDistanceAlongTrip;
        if (activeTrip != null && !adTripBean.getId().equals(activeTrip.getId()) && ratio < 0.50) {
            _log.debug("  " + status.getVehicleId() + " filtered out due to beginning of previous trip");
            return false;
        }
    }
    // only consider buses that are in layover
    if (phase != null && (phase.toUpperCase().equals("LAYOVER_BEFORE") || phase.toUpperCase().equals("LAYOVER_DURING"))) {
        double distanceAlongTrip = status.getDistanceAlongTrip();
        double totalDistanceAlongTrip = status.getTotalDistanceAlongTrip();
        double ratio = distanceAlongTrip / totalDistanceAlongTrip;
        // the trip this arrival and departure is for), filter that out.
        if (activeTrip != null && !adTripBean.getId().equals(activeTrip.getId()) && !((adBean.getBlockTripSequence() - 1) == status.getBlockTripSequence() && ratio > 0.50)) {
            _log.debug("  " + status.getVehicleId() + " filtered out due to at terminal/ratio");
            return false;
        }
    }
    /*else {
      // if the bus isn't serving the trip this arrival and departure is for, filter out--
      // since the bus is not in layover now.
      if (activeTrip != null
          && !adTripBean.getId().equals(activeTrip.getId())) {
        _log.debug("  " + status.getVehicleId() + " filtered out due to trip " + activeTrip.getId() + " not serving trip for A/D " + adTripBean.getId());
        //return false;
      }
    }*/
    _log.debug("include ad passed for " + status.getVehicleId());
    return true;
}
Also used : TripBean(org.onebusaway.transit_data.model.trips.TripBean)

Example 18 with TripBean

use of org.onebusaway.transit_data.model.trips.TripBean 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 19 with TripBean

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

the class ArrivalsAndDeparturesBeanServiceImplTest method test.

@Test
public void test() {
    long t = dateAsLong("2010-10-05 16:30");
    long serviceDate = dateAsLong("2010-10-05 00:00");
    int minutesBefore = 5;
    int minutesAfter = 30;
    StopEntryImpl stopA = stop("stopA", 47.0, -122.0);
    StopEntryImpl stopB = stop("stopB", 47.0, -122.0);
    Mockito.when(_transitGraphDao.getStopEntryForId(stopA.getId(), true)).thenReturn(stopA);
    Mockito.when(_transitGraphDao.getStopEntryForId(stopB.getId(), true)).thenReturn(stopB);
    /**
     **
     * Block A
     ***
     */
    BlockEntryImpl blockA = block("blockA");
    TripEntryImpl tripA = trip("tripA", "sA", 3000);
    stopTime(0, stopA, tripA, time(16, 30), time(16, 35), 1000);
    StopTimeEntryImpl stopTimeAB = stopTime(1, stopB, tripA, time(16, 40), time(16, 45), 2000);
    BlockConfigurationEntry blockConfigA = blockConfiguration(blockA, serviceIds(lsids("sA"), lsids()), tripA);
    BlockStopTimeEntry bstAA = blockConfigA.getStopTimes().get(0);
    BlockStopTimeEntry bstAB = blockConfigA.getStopTimes().get(1);
    /**
     **
     * Block B
     ***
     */
    BlockEntryImpl blockB = block("blockB");
    TripEntryImpl tripB = trip("tripB", "sA", 3000);
    stopTime(2, stopA, tripB, time(16, 40), time(16, 45), 1000);
    StopTimeEntryImpl stopTimeBB = stopTime(3, stopB, tripB, time(16, 50), time(16, 55), 2000);
    BlockConfigurationEntry blockConfigB = blockConfiguration(blockB, serviceIds(lsids("sA"), lsids()), tripB);
    BlockStopTimeEntry bstBA = blockConfigB.getStopTimes().get(0);
    BlockStopTimeEntry bstBB = blockConfigB.getStopTimes().get(1);
    /**
     **
     *
     ***
     */
    BlockInstance blockInstanceA = new BlockInstance(blockConfigA, serviceDate);
    long lastUpdateTime = dateAsLong("2010-10-05 16:15");
    BlockLocation blockLocationA = new BlockLocation();
    blockLocationA.setActiveTrip(bstAA.getTrip());
    blockLocationA.setBlockInstance(blockInstanceA);
    blockLocationA.setClosestStop(bstAA);
    blockLocationA.setDistanceAlongBlock(500);
    blockLocationA.setInService(true);
    blockLocationA.setLastUpdateTime(lastUpdateTime);
    blockLocationA.setNextStop(bstAA);
    blockLocationA.setPredicted(true);
    blockLocationA.setScheduledDistanceAlongBlock(600);
    blockLocationA.setScheduleDeviation(10 * 60);
    blockLocationA.setVehicleId(aid("vehicle"));
    /**
     **
     *
     ***
     */
    BlockInstance blockInstanceB = new BlockInstance(blockConfigB, serviceDate);
    BlockLocation blockLocationB = new BlockLocation();
    blockLocationB.setActiveTrip(bstBA.getTrip());
    blockLocationB.setBlockInstance(blockInstanceA);
    blockLocationB.setClosestStop(bstBA);
    blockLocationB.setDistanceAlongBlock(400);
    blockLocationB.setInService(true);
    blockLocationB.setNextStop(bstAA);
    blockLocationB.setPredicted(false);
    blockLocationB.setScheduledDistanceAlongBlock(400);
    /**
     **
     *
     ***
     */
    long stopTimeFrom = t - minutesBefore * 60 * 1000;
    long stopTimeTo = t + minutesAfter * 60 * 1000;
    StopTimeInstance sti1 = new StopTimeInstance(bstAB, blockInstanceA.getState());
    ArrivalAndDepartureInstance in1 = new ArrivalAndDepartureInstance(sti1);
    in1.setBlockLocation(blockLocationA);
    in1.setPredictedArrivalTime((long) (in1.getScheduledArrivalTime() + 5 * 60 * 1000));
    in1.setPredictedDepartureTime((long) (in1.getScheduledDepartureTime()));
    StopTimeInstance sti2 = new StopTimeInstance(bstBB, blockInstanceB.getState());
    ArrivalAndDepartureInstance in2 = new ArrivalAndDepartureInstance(sti2);
    in2.setBlockLocation(blockLocationB);
    TargetTime target = new TargetTime(t, t);
    Mockito.when(_arrivalAndDepartureService.getArrivalsAndDeparturesForStopInTimeRange(stopB, target, stopTimeFrom, stopTimeTo)).thenReturn(Arrays.asList(in1, in2));
    /**
     **
     *
     ***
     */
    Builder stopTimeNarrative = StopTimeNarrative.builder();
    stopTimeNarrative.setStopHeadsign("Downtown");
    Mockito.when(_narrativeService.getStopTimeForEntry(stopTimeAB)).thenReturn(stopTimeNarrative.create());
    stopTimeNarrative = StopTimeNarrative.builder();
    stopTimeNarrative.setRouteShortName("XX");
    Mockito.when(_narrativeService.getStopTimeForEntry(stopTimeBB)).thenReturn(stopTimeNarrative.create());
    /**
     **
     *
     ***
     */
    StopBean stopABean = new StopBean();
    stopABean.setId("1_stopA");
    Mockito.when(_stopBeanService.getStopForId(stopA.getId())).thenReturn(stopABean);
    StopBean stopBBean = new StopBean();
    stopBBean.setId("1_stopB");
    Mockito.when(_stopBeanService.getStopForId(stopB.getId())).thenReturn(stopBBean);
    /**
     **
     *
     ***
     */
    TripBean tripABean = new TripBean();
    Mockito.when(_tripBeanService.getTripForId(aid("tripA"))).thenReturn(tripABean);
    TripBean tripBBean = new TripBean();
    Mockito.when(_tripBeanService.getTripForId(aid("tripB"))).thenReturn(tripBBean);
    /**
     **
     *
     ***
     */
    TripStatusBean tripStatusBeanA = new TripStatusBean();
    TripStatusBean tripStatusBeanB = new TripStatusBean();
    Mockito.when(_tripDetailsBeanService.getBlockLocationAsStatusBean(blockLocationA, t)).thenReturn(tripStatusBeanA);
    Mockito.when(_tripDetailsBeanService.getBlockLocationAsStatusBean(blockLocationB, t)).thenReturn(tripStatusBeanB);
    /**
     **
     *
     ***
     */
    ArrivalsAndDeparturesQueryBean query = new ArrivalsAndDeparturesQueryBean();
    query.setTime(t);
    query.setMinutesBefore(minutesBefore);
    query.setMinutesAfter(minutesAfter);
    query.setFrequencyMinutesBefore(minutesBefore);
    query.setFrequencyMinutesAfter(minutesAfter);
    List<ArrivalAndDepartureBean> arrivalsAndDepartures = _service.getArrivalsAndDeparturesByStopId(stopB.getId(), query);
    assertEquals(2, arrivalsAndDepartures.size());
    ArrivalAndDepartureBean bean = arrivalsAndDepartures.get(0);
    assertEquals(1500, bean.getDistanceFromStop(), 0.0);
    assertEquals(lastUpdateTime, bean.getLastUpdateTime().longValue());
    assertEquals(1, bean.getNumberOfStopsAway());
    assertEquals(dateAsLong("2010-10-05 16:45"), bean.getPredictedArrivalTime());
    assertEquals(dateAsLong("2010-10-05 16:45"), bean.getPredictedDepartureTime());
    assertNull(bean.getRouteShortName());
    assertEquals(dateAsLong("2010-10-05 16:40"), bean.getScheduledArrivalTime());
    assertEquals(dateAsLong("2010-10-05 16:45"), bean.getScheduledDepartureTime());
    assertEquals(serviceDate, bean.getServiceDate());
    assertEquals("default", bean.getStatus());
    assertSame(stopBBean, bean.getStop());
    assertSame(tripABean, bean.getTrip());
    assertSame(tripStatusBeanA, bean.getTripStatus());
    assertEquals("Downtown", bean.getTripHeadsign());
    assertEquals("1_vehicle", bean.getVehicleId());
    bean = arrivalsAndDepartures.get(1);
    assertEquals(1600, bean.getDistanceFromStop(), 0.0);
    assertNull(bean.getLastUpdateTime());
    assertEquals(1, bean.getNumberOfStopsAway());
    assertEquals(0L, bean.getPredictedArrivalTime());
    assertEquals(0L, bean.getPredictedDepartureTime());
    assertEquals("XX", bean.getRouteShortName());
    assertEquals(dateAsLong("2010-10-05 16:50"), bean.getScheduledArrivalTime());
    assertEquals(dateAsLong("2010-10-05 16:55"), bean.getScheduledDepartureTime());
    assertEquals(serviceDate, bean.getServiceDate());
    assertEquals("default", bean.getStatus());
    assertSame(stopBBean, bean.getStop());
    assertSame(tripBBean, bean.getTrip());
    assertSame(tripStatusBeanB, bean.getTripStatus());
    assertNull(bean.getTripHeadsign());
    assertNull(bean.getVehicleId());
}
Also used : StopTimeInstance(org.onebusaway.transit_data_federation.model.StopTimeInstance) StopTimeEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl) Builder(org.onebusaway.transit_data_federation.model.narrative.StopTimeNarrative.Builder) TripBean(org.onebusaway.transit_data.model.trips.TripBean) ArrivalsAndDeparturesQueryBean(org.onebusaway.transit_data.model.ArrivalsAndDeparturesQueryBean) BlockLocation(org.onebusaway.transit_data_federation.services.realtime.BlockLocation) TargetTime(org.onebusaway.transit_data_federation.model.TargetTime) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) ArrivalAndDepartureBean(org.onebusaway.transit_data.model.ArrivalAndDepartureBean) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) ArrivalAndDepartureInstance(org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance) StopBean(org.onebusaway.transit_data.model.StopBean) TripStatusBean(org.onebusaway.transit_data.model.trips.TripStatusBean) BlockEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) Test(org.junit.Test)

Example 20 with TripBean

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

the class UserReportingServiceImplTest method test.

@SuppressWarnings("unchecked")
@Test
public void test() {
    TripProblemReportQueryBean query = new TripProblemReportQueryBean();
    AgencyAndId tripIdA = new AgencyAndId("1", "t-a");
    AgencyAndId tripIdB = new AgencyAndId("1", "t-b");
    TripBean tripA = new TripBean();
    TripBean tripB = new TripBean();
    Mockito.when(_dao.getTripProblemReportSummaries(query, ETripProblemGroupBy.TRIP)).thenReturn(Arrays.asList(Tuples.tuple((Object) tripIdA, 7), Tuples.tuple((Object) tripIdB, 3)));
    Mockito.when(_tripBeanService.getTripForId(tripIdA)).thenReturn(tripA);
    Mockito.when(_tripBeanService.getTripForId(tripIdB)).thenReturn(tripB);
    ListBean<TripProblemReportSummaryBean> summaries = _service.getTripProblemReportSummaries(query, ETripProblemGroupBy.TRIP);
    List<TripProblemReportSummaryBean> list = summaries.getList();
    assertEquals(2, list.size());
    TripProblemReportSummaryBean summary = list.get(0);
    assertSame(tripA, summary.getTrip());
    assertEquals(7, summary.getCount());
    summary = list.get(1);
    assertSame(tripB, summary.getTrip());
    assertEquals(3, summary.getCount());
    Mockito.when(_dao.getTripProblemReportSummaries(query, ETripProblemGroupBy.STATUS)).thenReturn(Arrays.asList(Tuples.tuple((Object) EProblemReportStatus.NEW, 6), Tuples.tuple((Object) EProblemReportStatus.DUPLICATE, 4)));
    summaries = _service.getTripProblemReportSummaries(query, ETripProblemGroupBy.STATUS);
    list = summaries.getList();
    assertEquals(2, list.size());
    summary = list.get(0);
    assertEquals(EProblemReportStatus.NEW, summary.getStatus());
    assertEquals(6, summary.getCount());
    summary = list.get(1);
    assertEquals(EProblemReportStatus.DUPLICATE, summary.getStatus());
    assertEquals(4, summary.getCount());
    Mockito.when(_dao.getTripProblemReportSummaries(query, ETripProblemGroupBy.LABEL)).thenReturn(Arrays.asList(Tuples.tuple((Object) "label-a", 9), Tuples.tuple((Object) "label-b", 2)));
    summaries = _service.getTripProblemReportSummaries(query, ETripProblemGroupBy.LABEL);
    list = summaries.getList();
    assertEquals(2, list.size());
    summary = list.get(0);
    assertEquals("label-a", summary.getLabel());
    assertEquals(9, summary.getCount());
    summary = list.get(1);
    assertEquals("label-b", summary.getLabel());
    assertEquals(2, summary.getCount());
}
Also used : TripProblemReportQueryBean(org.onebusaway.transit_data.model.problems.TripProblemReportQueryBean) TripProblemReportSummaryBean(org.onebusaway.transit_data.model.problems.TripProblemReportSummaryBean) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TripBean(org.onebusaway.transit_data.model.trips.TripBean) Test(org.junit.Test)

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