Search in sources :

Example 1 with MTAElevator

use of org.onebusaway.gtfs_transformer.csv.MTAElevator in project onebusaway-gtfs-modules by OneBusAway.

the class MTAEntrancesStrategy method readElevatorData.

private void readElevatorData(Map<String, StopGroup> stopGroups, Map<String, List<Stop>> complexIdToStops) {
    List<MTAElevator> elevators = getElevators();
    for (MTAElevator e : elevators) {
        StopGroup g = stopGroups.get(e.getStopId());
        if (g == null)
            _log.error("No stop group for elevator={}, stop={}", e.getId(), e.getStopId());
        else
            g.elevators.add(e);
    }
    int unknown = 0;
    for (StopGroup group : stopGroups.values()) {
        // there should be no more. Therefore, we can skip this stop completely.
        if (skipStopsWithExistingPathways && (group.parent != null && stopIdsWithPathways.contains(group.parent.getId()) || (group.uptown != null && stopIdsWithPathways.contains(group.uptown.getId())) || (group.downtown != null && stopIdsWithPathways.contains(group.downtown.getId())))) {
            _log.info("Stop {} already has pathways from other sources; skipping.", group);
            continue;
        }
        Stop entrance = null;
        // elevator is defined by ID, type, and direction iff it includes platform
        Set<String> seenElevatorPathways = new HashSet<>();
        Map<String, Stop> mezzByName = new HashMap<>();
        for (MTAElevator e : group.elevators) {
            ElevatorPathwayType type = ElevatorPathwayType.valueOf(e.getLoc());
            type.resolveElevatorNames(e);
            if (type == ElevatorPathwayType.UNKNOWN) {
                unknown++;
                _log.debug("unknown type={}, elev={}", e.getLoc(), e.getId());
                continue;
            }
            if (entrance == null && type.shouldCreateStreetEntrance()) {
                entrance = createAccessibleStreetEntrance(group.parent);
            }
            Stop platform = null;
            if (e.getDirection() != null) {
                if (e.getDirection().equals("N")) {
                    platform = group.uptown;
                    if (platform == null) {
                        _log.warn("Elevator file refers to platform {} and direction {} which is not in the GTFS. Check your data.", e.getStopId(), e.getDirection());
                        continue;
                    }
                } else if (e.getDirection().equals("S")) {
                    platform = group.downtown;
                    if (platform == null) {
                        _log.warn("Elevator file refers to platform {} and direction {} which is not in the GTFS. Check your data.", e.getStopId(), e.getDirection());
                        continue;
                    }
                } else {
                    _log.error("Unexpected direction={}, elev={}", e.getDirection(), e.getId());
                }
            }
            // only if the user hasn't already done so by naming the mezzes
            if (type.mezzanineNames != null) {
                List<String> newMezzanineNames = new ArrayList<>();
                for (String name : type.mezzanineNames) {
                    boolean partOfComplex = false;
                    for (String complexId : complexIdToStops.keySet()) {
                        List<Stop> stopsInComplex = complexIdToStops.get(complexId);
                        if (stopsInComplex.contains(platform)) {
                            newMezzanineNames.add(complexId + "-mezz-" + name);
                            partOfComplex = true;
                            break;
                        }
                    }
                    // parent stop ID as we would have before
                    if (!partOfComplex)
                        newMezzanineNames.add(group.parent.getId().getId() + "-mezz-" + name);
                }
                type.mezzanineNames = newMezzanineNames;
            }
            if (type.shouldCreateMezzanine()) {
                for (String name : type.mezzanineNames) {
                    Stop m = mezzByName.get(name);
                    if (m == null) {
                        m = createMezzanineWithId(group.parent, new AgencyAndId(platform.getId().getAgencyId(), name));
                        mezzByName.put(name, m);
                    }
                }
            }
            String code = e.getId();
            if (type.shouldCreateStreetToMezzanine()) {
                String id_base = "S2M_" + code;
                for (String name : type.mezzanineNames) {
                    Stop mezz = mezzByName.get(name);
                    String id = id_base + "_" + name;
                    createElevPathways(entrance, mezz, code, id, seenElevatorPathways);
                }
            }
            if (type.shouldCreateMezzanineToPlatform()) {
                String id_base = "M2P_" + code + "_" + e.getDirection();
                for (String name : type.mezzanineNames) {
                    Stop mezz = mezzByName.get(name);
                    String id = id_base + "_" + name;
                    createElevPathways(mezz, platform, code, id, seenElevatorPathways);
                }
            }
            if (type.shouldCreateStreetToPlatform()) {
                String id = "S2P_" + code + "_" + e.getDirection();
                createElevPathways(entrance, platform, code, id, seenElevatorPathways);
            }
            if (type.shouldCreateMezzanineToMezzanine()) {
                for (int i = 0; i < type.mezzanineNames.size(); i++) {
                    for (int j = i + 1; j < type.mezzanineNames.size(); j++) {
                        String name0 = type.mezzanineNames.get(i);
                        String name1 = type.mezzanineNames.get(j);
                        Stop mezz0 = mezzByName.get(name0);
                        Stop mezz1 = mezzByName.get(name1);
                        String id = "M2M_" + code + "_" + name0 + "_" + name1;
                        createElevPathways(mezz0, mezz1, code, id, seenElevatorPathways);
                    }
                }
            }
        }
    }
    _log.info("Processed {} / {} ({} are unknown)", elevators.size() - unknown, elevators.size(), unknown);
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MTAElevator(org.onebusaway.gtfs_transformer.csv.MTAElevator) HashSet(java.util.HashSet)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)1 Stop (org.onebusaway.gtfs.model.Stop)1 MTAElevator (org.onebusaway.gtfs_transformer.csv.MTAElevator)1