Search in sources :

Example 11 with BlockTripEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry 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 12 with BlockTripEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry 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 13 with BlockTripEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry in project onebusaway-application-modules by camsys.

the class ScheduledBlockLocationServiceImpl method getScheduledBlockLocationFromScheduledTime.

@Override
public ScheduledBlockLocation getScheduledBlockLocationFromScheduledTime(ScheduledBlockLocation previousLocation, int scheduleTime) {
    if (previousLocation.getScheduledTime() > scheduleTime)
        throw new IllegalStateException("previousLocation's scheduledTime must be before the requested scheduleTime");
    BlockTripEntry trip = previousLocation.getActiveTrip();
    BlockConfigurationEntry blockConfig = trip.getBlockConfiguration();
    List<BlockStopTimeEntry> stopTimes = blockConfig.getStopTimes();
    int index = previousLocation.getStopTimeIndex();
    while (index < stopTimes.size()) {
        int t = blockConfig.getDepartureTimeForIndex(index);
        if (scheduleTime <= t)
            break;
        index++;
    }
    return getScheduledBlockLocationFromScheduleTimeAndStopTimeIndex(stopTimes, scheduleTime, index);
}
Also used : BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint)

Example 14 with BlockTripEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry in project onebusaway-application-modules by camsys.

the class ScheduledBlockLocationServiceImpl method getLocationAlongShape.

private PointAndOrientation getLocationAlongShape(BlockTripEntry activeBlockTrip, double distanceAlongBlock, int shapePointIndexFrom, int shapePointIndexTo) {
    TripEntry activeTrip = activeBlockTrip.getTrip();
    AgencyAndId shapeId = activeTrip.getShapeId();
    if (shapeId == null)
        return null;
    ShapePoints shapePoints = _shapePointService.getShapePointsForShapeId(shapeId);
    if (shapePoints == null || shapePoints.isEmpty())
        return null;
    /**
     * We allow callers of this method to specify an arbitrarily high
     * shapePointIndexTo, knowing we'll bound it by the max number of points
     */
    shapePointIndexFrom = Math.min(shapePointIndexFrom, shapePoints.getSize());
    shapePointIndexTo = Math.min(shapePointIndexTo, shapePoints.getSize());
    double distanceAlongTrip = distanceAlongBlock - activeBlockTrip.getDistanceAlongBlock();
    ShapePointIndex shapePointIndexMethod = new DistanceTraveledShapePointIndex(distanceAlongTrip, shapePointIndexFrom, shapePointIndexTo);
    return shapePointIndexMethod.getPointAndOrientation(shapePoints);
}
Also used : ShapePoints(org.onebusaway.transit_data_federation.model.ShapePoints) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) DistanceTraveledShapePointIndex(org.onebusaway.transit_data_federation.impl.shapes.DistanceTraveledShapePointIndex) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) ShapePointIndex(org.onebusaway.transit_data_federation.impl.shapes.ShapePointIndex) DistanceTraveledShapePointIndex(org.onebusaway.transit_data_federation.impl.shapes.DistanceTraveledShapePointIndex)

Example 15 with BlockTripEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry in project onebusaway-application-modules by camsys.

the class BlockIndexFactoryServiceImpl method ensureFrequencyTripGroups.

private List<FrequencyTripGroup> ensureFrequencyTripGroups(List<BlockTripEntry> tripsWithSameSequence) {
    List<BlockTripWithFrequency> btwfs = new ArrayList<BlockTripWithFrequency>();
    for (BlockTripEntry trip : tripsWithSameSequence) {
        BlockConfigurationEntry blockConfig = trip.getBlockConfiguration();
        for (FrequencyEntry frequency : blockConfig.getFrequencies()) btwfs.add(new BlockTripWithFrequency(trip, frequency));
    }
    Collections.sort(btwfs);
    List<FrequencyTripGroup> lists = new ArrayList<FrequencyTripGroup>();
    for (BlockTripWithFrequency btwf : btwfs) {
        FrequencyTripGroup group = getBestFrequencyTripGroup(lists, btwf);
        if (group == null) {
            group = new FrequencyTripGroup();
            lists.add(group);
        }
        group.addEntry(btwf);
    }
    return lists;
}
Also used : BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) ArrayList(java.util.ArrayList) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)

Aggregations

BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)72 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)30 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)27 ArrayList (java.util.ArrayList)26 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)25 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)23 StopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry)15 List (java.util.List)11 FrequencyEntry (org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry)10 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)10 FactoryMap (org.onebusaway.collections.FactoryMap)9 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)8 HashSet (java.util.HashSet)7 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)7 StopTimeInstance (org.onebusaway.transit_data_federation.model.StopTimeInstance)7 InstanceState (org.onebusaway.transit_data_federation.services.blocks.InstanceState)7 Date (java.util.Date)6 FrequencyBlockTripIndex (org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex)6 ServiceInterval (org.onebusaway.gtfs.model.calendar.ServiceInterval)5 StopSequence (org.onebusaway.transit_data_federation.model.StopSequence)5