Search in sources :

Example 1 with StopTimeNarrative

use of org.onebusaway.transit_data_federation.model.narrative.StopTimeNarrative in project onebusaway-application-modules by camsys.

the class ArrivalsAndDeparturesBeanServiceImpl method getStopTimeInstanceAsBean.

/**
 **
 * Private Methods
 ***
 */
private ArrivalAndDepartureBean getStopTimeInstanceAsBean(long time, ArrivalAndDepartureInstance instance, Map<AgencyAndId, StopBean> stopBeanCache) {
    ArrivalAndDepartureBean pab = new ArrivalAndDepartureBean();
    pab.setServiceDate(instance.getServiceDate());
    BlockStopTimeEntry blockStopTime = instance.getBlockStopTime();
    BlockTripEntry blockTrip = blockStopTime.getTrip();
    StopTimeEntry stopTime = blockStopTime.getStopTime();
    StopEntry stop = stopTime.getStop();
    TripEntry trip = stopTime.getTrip();
    TripBean tripBean = _tripBeanService.getTripForId(trip.getId());
    pab.setTrip(tripBean);
    pab.setBlockTripSequence(blockTrip.getSequence());
    pab.setArrivalEnabled(stopTime.getSequence() > 0);
    pab.setDepartureEnabled(stopTime.getSequence() + 1 < trip.getStopTimes().size());
    StopTimeNarrative stopTimeNarrative = _narrativeService.getStopTimeForEntry(stopTime);
    pab.setRouteShortName(stopTimeNarrative.getRouteShortName());
    pab.setTripHeadsign(stopTimeNarrative.getStopHeadsign());
    StopBean stopBean = stopBeanCache.get(stop.getId());
    if (stopBean == null) {
        stopBean = _stopBeanService.getStopForId(stop.getId());
        stopBeanCache.put(stop.getId(), stopBean);
    }
    pab.setStop(stopBean);
    pab.setStopSequence(stopTime.getSequence());
    pab.setTotalStopsInTrip(stopTime.getTotalStopsInTrip());
    pab.setStatus("default");
    pab.setScheduledArrivalTime(instance.getScheduledArrivalTime());
    pab.setScheduledDepartureTime(instance.getScheduledDepartureTime());
    FrequencyEntry frequency = instance.getFrequencyLabel();
    pab.setFrequency(null);
    if (frequency != null) {
        FrequencyBean fb = FrequencyBeanLibrary.getBeanForFrequency(instance.getServiceDate(), frequency);
        pab.setFrequency(fb);
    }
    return pab;
}
Also used : StopTimeNarrative(org.onebusaway.transit_data_federation.model.narrative.StopTimeNarrative) FrequencyBean(org.onebusaway.transit_data.model.schedule.FrequencyBean) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) 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) StopBean(org.onebusaway.transit_data.model.StopBean) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry) ArrivalAndDepartureBean(org.onebusaway.transit_data.model.ArrivalAndDepartureBean) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Example 2 with StopTimeNarrative

use of org.onebusaway.transit_data_federation.model.narrative.StopTimeNarrative in project onebusaway-application-modules by camsys.

the class GenerateNarrativesTaskTest method testGenerateTripNarratives.

@Test
public void testGenerateTripNarratives() {
    Trip trip = new Trip();
    trip.setId(aid("trip"));
    trip.setRouteShortName("R1");
    trip.setTripHeadsign("Where are we going?");
    trip.setTripShortName("LOCAL");
    StopTime stopTime = new StopTime();
    stopTime.setRouteShortName("R1X");
    stopTime.setStopHeadsign("Here");
    Mockito.when(_gtfsDao.getAllTrips()).thenReturn(Arrays.asList(trip));
    Mockito.when(_gtfsDao.getStopTimesForTrip(trip)).thenReturn(Arrays.asList(stopTime));
    _task.generateTripNarratives(_provider);
    TripNarrative narrative = _provider.getNarrativeForTripId(trip.getId());
    assertEquals(trip.getRouteShortName(), narrative.getRouteShortName());
    assertEquals(trip.getTripHeadsign(), narrative.getTripHeadsign());
    assertEquals(trip.getTripShortName(), narrative.getTripShortName());
    StopEntryImpl stopEntry = stop("stop", 47.0, -122.0);
    TripEntryImpl tripEntry = trip("trip");
    StopTimeEntryImpl stopTimeEntry = stopTime(0, stopEntry, tripEntry, 0, 0.0);
    StopTimeNarrative stopTimeNarrative = _provider.getNarrativeForStopTimeEntry(stopTimeEntry);
    assertEquals(stopTime.getRouteShortName(), stopTimeNarrative.getRouteShortName());
    assertEquals(stopTime.getStopHeadsign(), stopTimeNarrative.getStopHeadsign());
}
Also used : StopTimeNarrative(org.onebusaway.transit_data_federation.model.narrative.StopTimeNarrative) Trip(org.onebusaway.gtfs.model.Trip) StopTimeEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl) TripNarrative(org.onebusaway.transit_data_federation.model.narrative.TripNarrative) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) StopTime(org.onebusaway.gtfs.model.StopTime) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl) Test(org.junit.Test)

Example 3 with StopTimeNarrative

use of org.onebusaway.transit_data_federation.model.narrative.StopTimeNarrative in project onebusaway-application-modules by camsys.

the class GenerateNarrativesTask method generateTripNarratives.

public void generateTripNarratives(NarrativeProviderImpl provider) {
    int tripIndex = 0;
    Collection<Trip> trips = _gtfsDao.getAllTrips();
    int logInterval = LoggingIntervalUtil.getAppropriateLoggingInterval(trips.size());
    for (Trip trip : trips) {
        if (tripIndex % logInterval == 0) {
            _log.info("trips=" + tripIndex + " of " + trips.size());
        }
        tripIndex++;
        TripNarrative tripNarrative = getTripNarrative(trip);
        provider.setNarrativeForTripId(trip.getId(), tripNarrative);
        List<StopTime> stopTimes = _gtfsDao.getStopTimesForTrip(trip);
        int stopTimeIndex = 0;
        for (StopTime stopTime : stopTimes) {
            StopTimeNarrative stopTimeNarrative = getStopTimeNarrative(stopTime);
            provider.setNarrativeForStopTimeEntry(trip.getId(), stopTimeIndex++, stopTimeNarrative);
        }
    }
}
Also used : StopTimeNarrative(org.onebusaway.transit_data_federation.model.narrative.StopTimeNarrative) Trip(org.onebusaway.gtfs.model.Trip) TripNarrative(org.onebusaway.transit_data_federation.model.narrative.TripNarrative) ProjectedPoint(org.onebusaway.transit_data_federation.model.ProjectedPoint) StopTime(org.onebusaway.gtfs.model.StopTime)

Example 4 with StopTimeNarrative

use of org.onebusaway.transit_data_federation.model.narrative.StopTimeNarrative in project onebusaway-application-modules by camsys.

the class NarrativeProviderImpl method getNarrativeForStopTimeEntry.

public StopTimeNarrative getNarrativeForStopTimeEntry(StopTimeEntry entry) {
    TripEntry trip = entry.getTrip();
    List<StopTimeNarrative> narratives = _stopTimeNarrativesByTripIdAndStopTimeSequence.get(trip.getId());
    if (narratives == null)
        return null;
    int index = entry.getSequence();
    return narratives.get(index);
}
Also used : StopTimeNarrative(org.onebusaway.transit_data_federation.model.narrative.StopTimeNarrative) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)

Aggregations

StopTimeNarrative (org.onebusaway.transit_data_federation.model.narrative.StopTimeNarrative)4 StopTime (org.onebusaway.gtfs.model.StopTime)2 Trip (org.onebusaway.gtfs.model.Trip)2 TripNarrative (org.onebusaway.transit_data_federation.model.narrative.TripNarrative)2 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)2 Test (org.junit.Test)1 ArrivalAndDepartureBean (org.onebusaway.transit_data.model.ArrivalAndDepartureBean)1 StopBean (org.onebusaway.transit_data.model.StopBean)1 FrequencyBean (org.onebusaway.transit_data.model.schedule.FrequencyBean)1 TripBean (org.onebusaway.transit_data.model.trips.TripBean)1 StopEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)1 StopTimeEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl)1 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)1 ProjectedPoint (org.onebusaway.transit_data_federation.model.ProjectedPoint)1 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)1 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)1 FrequencyEntry (org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry)1 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)1 StopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry)1