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;
}
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());
}
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);
}
}
}
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);
}
Aggregations