Search in sources :

Example 1 with PathwayUtil

use of org.onebusaway.gtfs_transformer.util.PathwayUtil in project onebusaway-gtfs-modules by OneBusAway.

the class MTAEntrancesStrategy method run.

@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
    ExternalServices es = new ExternalServicesBridgeFactory().getExternalServices();
    Collection<FeedInfo> feedInfos = dao.getAllFeedInfos();
    String feed = null;
    if (feedInfos.size() > 0)
        feed = feedInfos.iterator().next().getPublisherName();
    File entrancesFile = new File(entrancesCsv);
    if (!entrancesFile.exists()) {
        es.publishMultiDimensionalMetric(getNamespace(), "MissingControlFiles", new String[] { "feed", "controlFileName" }, new String[] { feed, entrancesCsv }, 1);
        throw new IllegalStateException("Entrances file does not exist: " + entrancesFile.getName());
    }
    if (elevatorsCsv != null) {
        File elevatorsFile = new File(elevatorsCsv);
        if (!elevatorsFile.exists()) {
            es.publishMultiDimensionalMetric(getNamespace(), "MissingControlFiles", new String[] { "feed", "controlFileName" }, new String[] { feed, elevatorsCsv }, 1);
            throw new IllegalStateException("Elevators file does not exist: " + elevatorsFile.getName());
        }
    }
    agencyId = dao.getAllAgencies().iterator().next().getId();
    newStops = new HashSet<>();
    newPathways = new HashSet<>();
    pathwayUtil = new PathwayUtil(agencyId, newPathways);
    for (Pathway pathway : dao.getAllPathways()) {
        stopIdsWithPathways.add(pathway.getFromStop().getId());
        stopIdsWithPathways.add(pathway.getToStop().getId());
    }
    Map<String, StopGroup> stopGroups = new HashMap<>();
    // For every stop that's not a station, add an entrance which is not wheelchair accessible, and a pathway.
    for (Stop stop : dao.getAllStops()) {
        if (stopsHaveParents) {
            // Put stop into a stop-group with parent, uptown, downtown
            String gid = stop.getLocationType() == LOCATION_TYPE_STOP ? stop.getParentStation() : stop.getId().getId();
            if (gid == null) {
                gid = stop.getId().getId();
                // don't fret about this one, it's a shuttle stop
                if (stop.getName().contains("SHUTTLE BUS STOP"))
                    continue;
                _log.warn("stop {} didn't have a parent set--using own stop ID.", stop.getName());
                continue;
            }
            StopGroup group = stopGroups.get(gid);
            if (group == null) {
                group = new StopGroup();
                stopGroups.put(gid, group);
            }
            if (stop.getLocationType() == LOCATION_TYPE_STATION) {
                group.parent = stop;
            } else if (stop.getId().getId().endsWith("S")) {
                group.downtown = stop;
            } else if (stop.getId().getId().endsWith("N")) {
                group.uptown = stop;
            } else {
                // it's a pathway, ignore
                if (stop.getLocationType() >= 2)
                    continue;
                // don't fret about this one, it's a shuttle stop
                if (stop.getName().contains("SHUTTLE BUS STOP"))
                    continue;
                _log.error("unexpected stop not of parent type but of {} for stop {}: {}", stop.getLocationType(), stop.getId(), stop.getName());
                continue;
            }
        } else {
            StopGroup group = new StopGroup();
            group.parent = stop;
            String gid = stop.getId().getId();
            stopGroups.put(gid, group);
        }
    }
    readEntranceData(stopGroups);
    if (elevatorsCsv != null) {
        readElevatorData(stopGroups, getComplexList(dao));
    }
    for (Stop s : newStops) {
        dao.saveEntity(s);
    }
    for (Pathway pathway : newPathways) {
        dao.saveEntity(pathway);
    }
}
Also used : ExternalServicesBridgeFactory(org.onebusaway.cloud.api.ExternalServicesBridgeFactory) HashMap(java.util.HashMap) Stop(org.onebusaway.gtfs.model.Stop) Pathway(org.onebusaway.gtfs.model.Pathway) FeedInfo(org.onebusaway.gtfs.model.FeedInfo) PathwayUtil(org.onebusaway.gtfs_transformer.util.PathwayUtil) ExternalServices(org.onebusaway.cloud.api.ExternalServices) File(java.io.File)

Example 2 with PathwayUtil

use of org.onebusaway.gtfs_transformer.util.PathwayUtil in project onebusaway-gtfs-modules by OneBusAway.

the class StationComplexStrategy method makePathways.

private void makePathways(Collection<List<Stop>> complexes, GtfsMutableRelationalDao dao) {
    String feedId = dao.getAllStops().iterator().next().getId().getAgencyId();
    List<Pathway> newPathways = new ArrayList<>();
    PathwayUtil util = new PathwayUtil(feedId, newPathways);
    for (List<Stop> complex : complexes) {
        for (Stop s : complex) {
            for (Stop t : complex) {
                if (s != null && s.getParentStation() != null && t != null) {
                    if (!s.equals(t)) {
                        String id = String.format("complex-%s-%s-%s", pathwayType.name(), s.getId().getId(), t.getId().getId());
                        util.createPathway(s, t, pathwayType.ordinal(), genericPathwayTraversalTime, id, null);
                    }
                } else {
                    _log.error("Illegal Stop {}", s);
                }
            }
        }
    }
    for (Pathway p : newPathways) {
        dao.saveEntity(p);
    }
}
Also used : Stop(org.onebusaway.gtfs.model.Stop) Pathway(org.onebusaway.gtfs.model.Pathway) ArrayList(java.util.ArrayList) PathwayUtil(org.onebusaway.gtfs_transformer.util.PathwayUtil)

Example 3 with PathwayUtil

use of org.onebusaway.gtfs_transformer.util.PathwayUtil in project onebusaway-gtfs-modules by OneBusAway.

the class InferPathwaysFromEntrancesStrategy method run.

@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
    String agencyId = dao.getAllStops().iterator().next().getId().getId();
    List<Pathway> pathways = new ArrayList<>();
    PathwayUtil pathwayUtil = new PathwayUtil(agencyId, pathways);
    Map<String, List<Stop>> stopMap = new HashMap<>();
    for (Stop stop : dao.getAllStops()) {
        String station = stop.getParentStation();
        if (stop.getLocationType() == STATION_TYPE) {
            station = stop.getId().getId();
        }
        List<Stop> stops = stopMap.get(station);
        if (stops == null) {
            stops = new ArrayList<>();
            stopMap.put(station, stops);
        }
        stops.add(stop);
    }
    for (List<Stop> stationStops : stopMap.values()) {
        List<Stop> stops = new ArrayList<>();
        List<Stop> entrances = new ArrayList<>();
        Stop station = null;
        for (Stop stop : stationStops) {
            if (stop.getLocationType() == STOP_TYPE) {
                stops.add(stop);
            } else if (stop.getLocationType() == ENTRANCE_TYPE) {
                entrances.add(stop);
            } else if (stop.getLocationType() == STATION_TYPE) {
                station = stop;
            }
        }
        if (station == null || stops.isEmpty() || entrances.isEmpty()) {
            continue;
        }
        for (Stop stop : stops) {
            for (Stop entrance : entrances) {
                String id = stop.getId().getId();
                int accessibleTime = -1;
                if (stop.getWheelchairBoarding() == WHEELCHAIR_BOARDING_ALLOWED) {
                    accessibleTime = wheelchairTraversalTime;
                } else if (stop.getWheelchairBoarding() == 0 && station.getWheelchairBoarding() == WHEELCHAIR_BOARDING_ALLOWED) {
                    accessibleTime = wheelchairTraversalTime;
                }
                pathwayUtil.createPathway(stop, entrance, MODE_WALKWAY, traversalTime, id, null);
            }
        }
    }
    for (Pathway pathway : pathways) {
        dao.saveEntity(pathway);
    }
}
Also used : HashMap(java.util.HashMap) Stop(org.onebusaway.gtfs.model.Stop) Pathway(org.onebusaway.gtfs.model.Pathway) ArrayList(java.util.ArrayList) PathwayUtil(org.onebusaway.gtfs_transformer.util.PathwayUtil) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

Pathway (org.onebusaway.gtfs.model.Pathway)3 Stop (org.onebusaway.gtfs.model.Stop)3 PathwayUtil (org.onebusaway.gtfs_transformer.util.PathwayUtil)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 File (java.io.File)1 List (java.util.List)1 ExternalServices (org.onebusaway.cloud.api.ExternalServices)1 ExternalServicesBridgeFactory (org.onebusaway.cloud.api.ExternalServicesBridgeFactory)1 FeedInfo (org.onebusaway.gtfs.model.FeedInfo)1