From 4fa369a5e303ef11fada192fbd70dcfc65da1ced Mon Sep 17 00:00:00 2001 From: Jakob Erdmann Date: Mon, 18 Mar 2024 19:34:17 +0100 Subject: [PATCH] more info on missing stops. refs #5320 --- src/netbuild/NBPTLine.cpp | 17 ++++++++++++++--- src/netbuild/NBPTLine.h | 4 +++- src/netimport/NIImporter_OpenStreetMap.cpp | 16 +++++++++++++--- src/netimport/NIXMLPTHandler.cpp | 10 +++++++++- src/netimport/NIXMLPTHandler.h | 3 +++ 5 files changed, 42 insertions(+), 8 deletions(-) diff --git a/src/netbuild/NBPTLine.cpp b/src/netbuild/NBPTLine.cpp index fcf49440f1c..432e316d845 100644 --- a/src/netbuild/NBPTLine.cpp +++ b/src/netbuild/NBPTLine.cpp @@ -43,7 +43,10 @@ NBPTLine::NBPTLine(const std::string& id, const std::string& name, const std::st myColor(color), myInterval(interval), myNightService(nightService), - myVClass(vClass) + myVClass(vClass), + myNumOfStops(0), + myMissingStopsBefore(0), + myMissingStopsAfter(0) { } @@ -89,7 +92,13 @@ NBPTLine::write(OutputDevice& device) { if (myColor.isValid()) { device.writeAttr(SUMO_ATTR_COLOR, myColor); } - device.writeAttr("completeness", toString((double)myPTStops.size() / (double)myNumOfStops)); + device.writeAttr("completeness", (double)myPTStops.size() / myNumOfStops); + if (myMissingStopsBefore != 0) { + device.writeAttr("missingBefore", myMissingStopsBefore); + } + if (myMissingStopsAfter != 0) { + device.writeAttr("missingAfter", myMissingStopsAfter); + } if (!myRoute.empty()) { device.openTag(SUMO_TAG_ROUTE); @@ -154,8 +163,10 @@ NBPTLine::setEdges(const std::vector& edges) { void -NBPTLine::setMyNumOfStops(int numStops) { +NBPTLine::setNumOfStops(int numStops, int missingBefore, int missingAfter) { myNumOfStops = numStops; + myMissingStopsBefore = missingBefore; + myMissingStopsAfter = missingAfter; } diff --git a/src/netbuild/NBPTLine.h b/src/netbuild/NBPTLine.h index 2cfa5098508..573147a6436 100644 --- a/src/netbuild/NBPTLine.h +++ b/src/netbuild/NBPTLine.h @@ -64,7 +64,7 @@ class NBPTLine { void write(OutputDevice& device); void addWayNode(long long int way, long long int node); - void setMyNumOfStops(int numStops); + void setNumOfStops(int numStops, int missingBefore, int missingAfter); /// @brief get line reference (not unique) const std::string& getRef() const { @@ -141,4 +141,6 @@ class NBPTLine { private: int myNumOfStops; + int myMissingStopsBefore; + int myMissingStopsAfter; }; diff --git a/src/netimport/NIImporter_OpenStreetMap.cpp b/src/netimport/NIImporter_OpenStreetMap.cpp index 2c6157c64e9..825e1e3ed8b 100644 --- a/src/netimport/NIImporter_OpenStreetMap.cpp +++ b/src/netimport/NIImporter_OpenStreetMap.cpp @@ -2053,18 +2053,27 @@ NIImporter_OpenStreetMap::RelationHandler::myEndElement(int element) { } else if (myPTRouteType != "" && myIsRoute) { NBPTLine* ptLine = new NBPTLine(toString(myCurrentRelation), myName, myPTRouteType, myRef, myInterval, myNightService, interpretTransportType(myPTRouteType), myRouteColor); - ptLine->setMyNumOfStops((int)myStops.size()); bool hadGap = false; + int missingBefore = 0; + int missingAfter = 0; + int stopIndex = 0; for (long long ref : myStops) { + stopIndex++; const auto& nodeIt = myOSMNodes.find(ref); if (nodeIt == myOSMNodes.end()) { - if (!ptLine->getStops().empty() && !hadGap) { - hadGap = true; + if (ptLine->getStops().empty()) { + missingBefore++; + } else { + missingAfter++; + if (!hadGap) { + hadGap = true; + } } continue; } if (hadGap) { WRITE_WARNINGF(TL("PT line '%' in relation % seems to be split, only keeping first part."), myName, myCurrentRelation); + missingAfter = myStops.size() - missingBefore - ptLine->getStops().size(); break; } @@ -2096,6 +2105,7 @@ NIImporter_OpenStreetMap::RelationHandler::myEndElement(int element) { } } } + ptLine->setNumOfStops((int)myStops.size(), missingBefore, missingAfter); if (ptLine->getStops().empty()) { WRITE_WARNINGF(TL("PT line in relation % with no stops ignored. Probably OSM file is incomplete."), myCurrentRelation); delete ptLine; diff --git a/src/netimport/NIXMLPTHandler.cpp b/src/netimport/NIXMLPTHandler.cpp index 070bb18e425..0f784f8de13 100644 --- a/src/netimport/NIXMLPTHandler.cpp +++ b/src/netimport/NIXMLPTHandler.cpp @@ -99,6 +99,10 @@ NIXMLPTHandler::myStartElement(int element, myCurrentCompletion = attrs.get(SUMO_ATTR_VALUE, nullptr, ok); } else if (key == "name") { myCurrentLine->setName(attrs.get(SUMO_ATTR_VALUE, nullptr, ok)); + } else if (key == "missingBefore") { + myMissingBefore = attrs.get(SUMO_ATTR_VALUE, nullptr, ok); + } else if (key == "missingAfter") { + myMissingAfter = attrs.get(SUMO_ATTR_VALUE, nullptr, ok); } } else if (myCurrentStop != nullptr) { const std::string val = attrs.hasAttribute(SUMO_ATTR_VALUE) ? attrs.getString(SUMO_ATTR_VALUE) : ""; @@ -122,7 +126,7 @@ NIXMLPTHandler::myEndElement(int element) { case SUMO_TAG_PT_LINE: case SUMO_TAG_FLOW: case SUMO_TAG_TRIP: - myCurrentLine->setMyNumOfStops((int)((double)myCurrentLine->getStops().size() / myCurrentCompletion)); + myCurrentLine->setNumOfStops((int)((double)myCurrentLine->getStops().size() / myCurrentCompletion), myMissingBefore, myMissingAfter); myCurrentLine = nullptr; break; case SUMO_TAG_ROUTE: @@ -216,6 +220,8 @@ NIXMLPTHandler::addPTLine(const SUMOSAXAttributes& attrs) { const int intervalS = attrs.getOpt(SUMO_ATTR_PERIOD, id.c_str(), ok, -1); const std::string nightService = attrs.getStringSecure("nightService", ""); myCurrentCompletion = StringUtils::toDouble(attrs.getStringSecure("completeness", "1")); + myMissingBefore = StringUtils::toInt(attrs.getStringSecure("missingBefore", "0")); + myMissingAfter = StringUtils::toInt(attrs.getStringSecure("missingAfter", "0")); if (ok) { myCurrentLine = new NBPTLine(id, name, type, line, intervalS / 60, nightService, vClass, color); if (!myLineCont.insert(myCurrentLine)) { @@ -229,6 +235,8 @@ NIXMLPTHandler::addPTLine(const SUMOSAXAttributes& attrs) { void NIXMLPTHandler::addPTLineFromFlow(const SUMOSAXAttributes& attrs) { bool ok = true; + myMissingBefore = 0; + myMissingAfter = 0; const std::string id = attrs.get(SUMO_ATTR_ID, "flow", ok); const std::string line = attrs.get(SUMO_ATTR_LINE, id.c_str(), ok); const std::string type = attrs.get(SUMO_ATTR_TYPE, id.c_str(), ok); diff --git a/src/netimport/NIXMLPTHandler.h b/src/netimport/NIXMLPTHandler.h index 1897196246a..19055976eb3 100644 --- a/src/netimport/NIXMLPTHandler.h +++ b/src/netimport/NIXMLPTHandler.h @@ -155,6 +155,9 @@ class NIXMLPTHandler : public SUMOSAXHandler { /// @brief whether the current stop should be discarded bool myCurrentStopWasIgnored; + int myMissingBefore; + int myMissingAfter; + private: /** @brief Parses an public transport stop