Search in sources :

Example 71 with Stop

use of org.onebusaway.gtfs.model.Stop in project onebusaway-gtfs-modules by OneBusAway.

the class StationComplexStrategy method getComplexList.

private Collection<List<Stop>> getComplexList(GtfsDao dao) {
    Map<String, Stop> stops = getStopMap(dao);
    Collection<List<Stop>> complexes = new ArrayList<>();
    try (BufferedReader br = new BufferedReader(new FileReader(new File(complexFile)))) {
        String line;
        while ((line = br.readLine()) != null) {
            List<Stop> complex = new ArrayList<>();
            for (String id : line.split(STOP_SEPARATOR)) {
                Stop stop = stops.get(id);
                if (stop == null)
                    _log.info("null stop: {}", id);
                complex.add(stop);
            }
            complexes.add(complex);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return complexes;
}
Also used : Stop(org.onebusaway.gtfs.model.Stop) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) List(java.util.List) FileReader(java.io.FileReader) IOException(java.io.IOException) File(java.io.File)

Example 72 with Stop

use of org.onebusaway.gtfs.model.Stop in project onebusaway-gtfs-modules by OneBusAway.

the class StationComplexStrategy method setParents.

private void setParents(Collection<List<Stop>> complexes, GtfsMutableRelationalDao dao) {
    for (List<Stop> complex : complexes) {
        Map<String, List<Stop>> grouped = complex.stream().collect(Collectors.groupingBy(Stop::getName));
        for (List<Stop> group : grouped.values()) {
            String parent = group.get(0).getParentStation();
            for (Stop stop : group) {
                stop.setParentStation(parent);
                dao.updateEntity(stop);
            }
        }
    }
}
Also used : Stop(org.onebusaway.gtfs.model.Stop) ArrayList(java.util.ArrayList) List(java.util.List)

Example 73 with Stop

use of org.onebusaway.gtfs.model.Stop 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 74 with Stop

use of org.onebusaway.gtfs.model.Stop in project onebusaway-gtfs-modules by OneBusAway.

the class UpdateStopIdFromControlStrategy method run.

@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
    GtfsMutableRelationalDao reference = (GtfsMutableRelationalDao) context.getReferenceReader().getEntityStore();
    RemoveEntityLibrary removeEntityLibrary = new RemoveEntityLibrary();
    File controlFile = new File((String) context.getParameter("controlFile"));
    ExternalServices es = new ExternalServicesBridgeFactory().getExternalServices();
    String feed = CloudContextService.getLikelyFeedName(dao);
    if (!controlFile.exists()) {
        es.publishMultiDimensionalMetric(CloudContextService.getNamespace(), "MissingControlFiles", new String[] { "feed", "controlFileName" }, new String[] { feed, controlFile.getName() }, 1);
        throw new IllegalStateException("Control file does not exist: " + controlFile.getName());
    }
    List<String> controlLines = new InputLibrary().readList((String) context.getParameter("controlFile"));
    int matched = 0;
    int unmatched = 0;
    int duplicate = 0;
    int inCntrlRefNotAtis = 0;
    ArrayList<AgencyAndId> stopsToRemove = new ArrayList();
    // a map of the new id (from reference/control file) to the old id
    // so that stop times can be associated with new id
    HashMap<AgencyAndId, AgencyAndId> stopsUpdated = new HashMap<>();
    HashMap<String, Stop> referenceStops = new HashMap<>();
    for (Stop stop : reference.getAllStops()) {
        referenceStops.put(stop.getId().getId(), stop);
    }
    AgencyAndId agencyAndId = dao.getAllStops().iterator().next().getId();
    for (String controlLine : controlLines) {
        String[] controlArray = controlLine.split(",");
        if (controlArray == null || controlArray.length < 2) {
            _log.info("bad control line {}", controlLine);
            continue;
        }
        String referenceId = controlArray[LOCATION_NAME_INDEX];
        String direction = controlArray[DIRECTION];
        String atisId = controlArray[ATIS_ID_INDEX];
        Stop refStop;
        // find the reference stop based on the Id
        if (direction.isEmpty()) {
            refStop = referenceStops.get(referenceId);
            if (refStop == null) {
                if (!atisId.equals("0")) {
                // _log.info("missing reference stop {} for agency {} for ATIS id {}", referenceId, getReferenceAgencyId(reference), atisId);
                }
                unmatched++;
                continue;
            }
        } else {
            refStop = referenceStops.get(referenceId + direction);
            if (refStop == null) {
                if (!atisId.equals("0")) {
                // _log.info("missing reference stop {} for agency {} for ATIS id {}", referenceId, getReferenceAgencyId(reference), atisId);
                }
                unmatched++;
                continue;
            }
        }
        Stop atisStop = dao.getStopForId(new AgencyAndId(agencyAndId.getAgencyId(), atisId));
        // for example: there are two 128N ref stops in control file
        if (stopsUpdated.containsKey(refStop.getId())) {
            duplicate++;
            Stop persistStop = dao.getStopForId(stopsUpdated.get(refStop.getId()));
            stopsToRemove.add(new AgencyAndId(agencyAndId.getAgencyId(), atisId));
            // _log.info("Stop times for stop: {} stopTimes: {}", atisStop.getId().getId(), dao.getStopTimesForStop(atisStop).size());
            for (StopTime stopTime : dao.getStopTimesForStop(atisStop)) {
                stopTime.setStop(persistStop);
            }
            // _log.info("Duplicate stops keep: {}  remove: {} ", persistStop.getId().getId(), atisStop.getId().getId());
            continue;
        }
        if (atisStop == null) {
            if (!atisId.equals("0")) {
            // _log.info("missing atis stop {} for Reference id {}{}", atisId, referenceId, direction);
            }
            unmatched++;
            continue;
        } else {
            atisStop.setName(refStop.getName());
            atisStop.setDirection(refStop.getDirection());
            atisStop.setId(refStop.getId());
            atisStop.setParentStation(refStop.getParentStation());
            atisStop.setLocationType(refStop.getLocationType());
            stopsUpdated.put(atisStop.getId(), new AgencyAndId(agencyAndId.getAgencyId(), atisId));
            dao.updateEntity(atisStop);
            matched++;
        // _log.error("Updated stop: original ATIS id: {} Reference id: {} Id now: {}", atisId, referenceId, atisStop.getId().getId());
        }
    }
    _log.info("Complete with {} matched and {} unmatched and {} duplicates", matched, unmatched, duplicate);
    for (AgencyAndId id : stopsToRemove) {
        Stop stop = dao.getStopForId(id);
        // removeEntityLibrary.removeStop(dao, stop);
        dao.removeEntity(stop);
    }
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) ExternalServicesBridgeFactory(org.onebusaway.cloud.api.ExternalServicesBridgeFactory) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) HashMap(java.util.HashMap) Stop(org.onebusaway.gtfs.model.Stop) ArrayList(java.util.ArrayList) ExternalServices(org.onebusaway.cloud.api.ExternalServices) File(java.io.File) StopTime(org.onebusaway.gtfs.model.StopTime)

Example 75 with Stop

use of org.onebusaway.gtfs.model.Stop in project onebusaway-gtfs-modules by OneBusAway.

the class UpdateStopIdsFromFile method run.

@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
    File controlFile = new File((String) context.getParameter("controlFile"));
    String feed = dao.getAllFeedInfos().iterator().next().getPublisherName();
    ExternalServices es = new ExternalServicesBridgeFactory().getExternalServices();
    if (!controlFile.exists()) {
        es.publishMultiDimensionalMetric(CloudContextService.getNamespace(), "MissingControlFiles", new String[] { "feed", "controlFileName" }, new String[] { feed, controlFile.getName() }, 1);
        throw new IllegalStateException("Control file does not exist: " + controlFile.getName());
    }
    List<String> controlLines = new InputLibrary().readList((String) context.getParameter("controlFile"));
    int matched = 0;
    int unmatched = 0;
    int duplicate = 0;
    AgencyAndId agencyAndId = dao.getAllStops().iterator().next().getId();
    for (String controlLine : controlLines) {
        String[] controlArray = controlLine.split(",");
        if (controlArray == null || controlArray.length < 2) {
            _log.info("bad control line {}", controlLine);
            continue;
        }
        String oldId = controlArray[OLD_STOP_ID];
        String newId = controlArray[NEW_STOP_ID];
        String newCode = controlArray[NEW_STOP_CODE];
        Stop stop = dao.getStopForId(new AgencyAndId(agencyAndId.getAgencyId(), newId));
        if (stop == null) {
            if (!newId.equals("0")) {
                _log.info("missing stop for new id {}", newId);
            } else {
                _log.error("No stop found for id {}", newId);
            }
            unmatched++;
            continue;
        }
        matched++;
        _log.info("Setting existing new id {} to old id {}", newId, oldId);
        stop.setId(new AgencyAndId(stop.getId().getAgencyId(), oldId));
        stop.setCode(newCode);
    }
    _log.info("Complete with {} matched and {} unmatched and {} duplicates", matched, unmatched, duplicate);
}
Also used : ExternalServicesBridgeFactory(org.onebusaway.cloud.api.ExternalServicesBridgeFactory) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) ExternalServices(org.onebusaway.cloud.api.ExternalServices) File(java.io.File)

Aggregations

Stop (org.onebusaway.gtfs.model.Stop)160 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)75 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)49 Trip (org.onebusaway.gtfs.model.Trip)40 Test (org.junit.Test)39 ArrayList (java.util.ArrayList)33 StopTime (org.onebusaway.gtfs.model.StopTime)33 Route (org.onebusaway.gtfs.model.Route)28 TripPattern (org.opentripplanner.routing.edgetype.TripPattern)23 Agency (org.onebusaway.gtfs.model.Agency)19 Vertex (org.opentripplanner.routing.graph.Vertex)18 HashMap (java.util.HashMap)14 TripTimes (org.opentripplanner.routing.trippattern.TripTimes)13 GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)11 LineString (com.vividsolutions.jts.geom.LineString)10 List (java.util.List)10 GET (javax.ws.rs.GET)10 ShapePoint (org.onebusaway.gtfs.model.ShapePoint)10 GraphPath (org.opentripplanner.routing.spt.GraphPath)10 Coordinate (com.vividsolutions.jts.geom.Coordinate)9