Search in sources :

Example 1 with TripNarrative

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

the class TripBeanServiceImpl method getTripForId.

@Cacheable
public TripBean getTripForId(AgencyAndId tripId) {
    TripEntry tripEntry = _graph.getTripEntryForId(tripId);
    if (tripEntry == null)
        return null;
    AgencyAndId routeId = tripEntry.getRouteCollection().getId();
    RouteBean routeBean = _routeBeanService.getRouteForId(routeId);
    TripNarrative tripNarrative = _narrativeService.getTripForId(tripId);
    TripBean tripBean = new TripBean();
    tripBean.setId(ApplicationBeanLibrary.getId(tripId));
    tripBean.setTripShortName(tripNarrative.getTripShortName());
    tripBean.setTripHeadsign(tripNarrative.getTripHeadsign());
    tripBean.setRoute(routeBean);
    tripBean.setRouteShortName(tripNarrative.getRouteShortName());
    tripBean.setServiceId(ApplicationBeanLibrary.getId(tripEntry.getServiceId().getId()));
    AgencyAndId shapeId = tripEntry.getShapeId();
    if (shapeId != null && shapeId.hasValues())
        tripBean.setShapeId(ApplicationBeanLibrary.getId(shapeId));
    tripBean.setDirectionId(tripEntry.getDirectionId());
    tripBean.setTotalTripDistance(tripEntry.getTotalTripDistance());
    BlockEntry block = tripEntry.getBlock();
    tripBean.setBlockId(ApplicationBeanLibrary.getId(block.getId()));
    return tripBean;
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) BlockEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) TripBean(org.onebusaway.transit_data.model.trips.TripBean) TripNarrative(org.onebusaway.transit_data_federation.model.narrative.TripNarrative) Cacheable(org.onebusaway.container.cache.Cacheable)

Example 2 with TripNarrative

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

the class StopSequenceCollectionServiceImpl method constructCollections.

/**
 * @param route
 * @param sequenceStats
 * @param sequencesByGroupId
 * @return
 */
private List<StopSequenceCollection> constructCollections(Map<StopSequence, PatternStats> sequenceStats, Map<String, List<StopSequence>> sequencesByGroupId) {
    computeContinuations(sequenceStats, sequencesByGroupId);
    Set<String> allNames = new HashSet<String>();
    Map<String, String> directionToName = new HashMap<String, String>();
    Map<String, Segment> segments = new HashMap<String, Segment>();
    for (Map.Entry<String, List<StopSequence>> entry : sequencesByGroupId.entrySet()) {
        String direction = entry.getKey();
        List<StopSequence> sequences = entry.getValue();
        Max<StopSequence> maxTripCount = new Max<StopSequence>();
        Counter<String> names = new Counter<String>();
        for (StopSequence sequence : sequences) {
            maxTripCount.add(sequence.getTripCount(), sequence);
            for (BlockTripEntry blockTrip : sequence.getTrips()) {
                TripEntry trip = blockTrip.getTrip();
                TripNarrative tripNarrative = _narrativeService.getTripForId(trip.getId());
                String headsign = tripNarrative.getTripHeadsign();
                if (headsign != null && headsign.length() > 0)
                    names.increment(headsign);
            }
        }
        String dName = names.getMax();
        RecursiveStats rs = new RecursiveStats();
        rs.maxTripCount = (long) maxTripCount.getMaxValue();
        exploreStopSequences(rs, sequenceStats, sequences, "");
        allNames.add(dName);
        directionToName.put(direction, dName);
        segments.put(direction, rs.longestSegment.getMaxElement());
    }
    if (allNames.size() < directionToName.size()) {
        for (Map.Entry<String, String> entry : directionToName.entrySet()) {
            String direction = entry.getKey();
            String name = entry.getValue();
            direction = direction.charAt(0) + direction.substring(1).toLowerCase();
            entry.setValue(name + " - " + direction);
        }
    }
    List<StopSequenceCollection> blocks = new ArrayList<StopSequenceCollection>();
    for (Map.Entry<String, String> entry : directionToName.entrySet()) {
        String direction = entry.getKey();
        String name = entry.getValue();
        List<StopSequence> patterns = sequencesByGroupId.get(direction);
        Segment segment = segments.get(direction);
        // System.out.println("  " + direction + " => " + name);
        StopSequenceCollection block = new StopSequenceCollection();
        if (segment.fromLat == 0.0)
            throw new IllegalStateException("what?");
        StopSequenceCollectionKey key = new StopSequenceCollectionKey(null, direction);
        block.setId(key);
        block.setPublicId(direction);
        block.setDescription(name);
        block.setStopSequences(patterns);
        block.setStartLat(segment.fromLat);
        block.setStartLon(segment.fromLon);
        block.setEndLat(segment.toLat);
        block.setEndLon(segment.toLon);
        blocks.add(block);
    }
    return blocks;
}
Also used : HashMap(java.util.HashMap) Max(org.onebusaway.collections.Max) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) ArrayList(java.util.ArrayList) StopSequence(org.onebusaway.transit_data_federation.model.StopSequence) Counter(org.onebusaway.collections.Counter) ArrayList(java.util.ArrayList) List(java.util.List) StopSequenceCollection(org.onebusaway.transit_data_federation.model.StopSequenceCollection) HashSet(java.util.HashSet) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) StopSequenceCollectionKey(org.onebusaway.transit_data_federation.model.StopSequenceCollectionKey) HashMap(java.util.HashMap) Map(java.util.Map) FactoryMap(org.onebusaway.collections.FactoryMap) TripNarrative(org.onebusaway.transit_data_federation.model.narrative.TripNarrative)

Example 3 with TripNarrative

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

the class GenerateNarrativesTask method getTripNarrative.

private TripNarrative getTripNarrative(Trip trip) {
    String headsign = trip.getTripHeadsign();
    if (headsign == null) {
        Route route = trip.getRoute();
        headsign = route.getLongName();
    }
    TripNarrative.Builder builder = TripNarrative.builder();
    builder.setRouteShortName(deduplicate(trip.getRouteShortName()));
    builder.setTripHeadsign(deduplicate(headsign));
    builder.setTripShortName(deduplicate(trip.getTripShortName()));
    return builder.create();
}
Also used : TripNarrative(org.onebusaway.transit_data_federation.model.narrative.TripNarrative) Route(org.onebusaway.gtfs.model.Route)

Example 4 with TripNarrative

use of org.onebusaway.transit_data_federation.model.narrative.TripNarrative 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 5 with TripNarrative

use of org.onebusaway.transit_data_federation.model.narrative.TripNarrative 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)

Aggregations

TripNarrative (org.onebusaway.transit_data_federation.model.narrative.TripNarrative)6 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 List (java.util.List)2 FactoryMap (org.onebusaway.collections.FactoryMap)2 Cacheable (org.onebusaway.container.cache.Cacheable)2 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)2 StopTime (org.onebusaway.gtfs.model.StopTime)2 Trip (org.onebusaway.gtfs.model.Trip)2 RouteBean (org.onebusaway.transit_data.model.RouteBean)2 StopTimeNarrative (org.onebusaway.transit_data_federation.model.narrative.StopTimeNarrative)2 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Test (org.junit.Test)1 Counter (org.onebusaway.collections.Counter)1 Max (org.onebusaway.collections.Max)1 Route (org.onebusaway.gtfs.model.Route)1 StopRouteDirectionScheduleBean (org.onebusaway.transit_data.model.StopRouteDirectionScheduleBean)1