Skip to content

Commit

Permalink
more info on missing stops. refs #5320
Browse files Browse the repository at this point in the history
  • Loading branch information
namdre committed Mar 18, 2024
1 parent 8ccae7a commit 4fa369a
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 8 deletions.
17 changes: 14 additions & 3 deletions src/netbuild/NBPTLine.cpp
Expand Up @@ -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)
{ }


Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -154,8 +163,10 @@ NBPTLine::setEdges(const std::vector<NBEdge*>& edges) {


void
NBPTLine::setMyNumOfStops(int numStops) {
NBPTLine::setNumOfStops(int numStops, int missingBefore, int missingAfter) {
myNumOfStops = numStops;
myMissingStopsBefore = missingBefore;
myMissingStopsAfter = missingAfter;
}


Expand Down
4 changes: 3 additions & 1 deletion src/netbuild/NBPTLine.h
Expand Up @@ -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 {
Expand Down Expand Up @@ -141,4 +141,6 @@ class NBPTLine {
private:

int myNumOfStops;
int myMissingStopsBefore;
int myMissingStopsAfter;
};
16 changes: 13 additions & 3 deletions src/netimport/NIImporter_OpenStreetMap.cpp
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down
10 changes: 9 additions & 1 deletion src/netimport/NIXMLPTHandler.cpp
Expand Up @@ -99,6 +99,10 @@ NIXMLPTHandler::myStartElement(int element,
myCurrentCompletion = attrs.get<double>(SUMO_ATTR_VALUE, nullptr, ok);
} else if (key == "name") {
myCurrentLine->setName(attrs.get<std::string>(SUMO_ATTR_VALUE, nullptr, ok));
} else if (key == "missingBefore") {
myMissingBefore = attrs.get<int>(SUMO_ATTR_VALUE, nullptr, ok);
} else if (key == "missingAfter") {
myMissingAfter = attrs.get<int>(SUMO_ATTR_VALUE, nullptr, ok);
}
} else if (myCurrentStop != nullptr) {
const std::string val = attrs.hasAttribute(SUMO_ATTR_VALUE) ? attrs.getString(SUMO_ATTR_VALUE) : "";
Expand All @@ -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:
Expand Down Expand Up @@ -216,6 +220,8 @@ NIXMLPTHandler::addPTLine(const SUMOSAXAttributes& attrs) {
const int intervalS = attrs.getOpt<int>(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)) {
Expand All @@ -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<std::string>(SUMO_ATTR_ID, "flow", ok);
const std::string line = attrs.get<std::string>(SUMO_ATTR_LINE, id.c_str(), ok);
const std::string type = attrs.get<std::string>(SUMO_ATTR_TYPE, id.c_str(), ok);
Expand Down
3 changes: 3 additions & 0 deletions src/netimport/NIXMLPTHandler.h
Expand Up @@ -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
Expand Down

0 comments on commit 4fa369a

Please sign in to comment.