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;
}
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);
}
}
}
}
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);
}
}
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);
}
}
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);
}
Aggregations