Skip to content

Commit

Permalink
#368 improve route node analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
vmarc committed Jul 20, 2024
1 parent 516334a commit 795a625
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ class RouteAnalysisCompareTool(config: AnalysisStartConfiguration) {

def analyze(): Unit = {
log.info("Collecting routeIds")
// val routeIds = readRouteIds("logs/mismatch-ids-4.txt")
val routeIds = Seq(17613906L) // config.oldDatabase.oldRoutes.ids()
val routeIds = config.oldDatabase.oldRoutes.ids()
// val routeIds = readRouteIds("logs/mismatch-ids-5.txt")
// val routeIds = Seq(17613906L)
log.info(s"Comparing ${routeIds.size} routes")
routeIds.zipWithIndex.foreach { case (routeId, index) =>
if (index % 50 == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ class RouteDetailMainAnalyzer(
// TODO ExpectedNameRouteAnalyzer, // <== needs further updating
SuspiciousWaysRouteAnalyzer, // OK

RouteNodeAnalyzer,
RouteLinkAnalyzer,
RouteNodeAnalyzer,
RouteSegmentAnalyzer,
RouteStructureAnalyzer,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ import kpn.api.custom.NetworkScope
import kpn.api.custom.NetworkType
import kpn.api.custom.Relation
import kpn.api.custom.ScopedNetworkType
import kpn.core.analysis.LinkDirection
import kpn.server.analyzer.engine.analysis.route.domain.RouteDetailAnalysisContext
import kpn.server.analyzer.engine.analysis.route.structure.RouteAnalysisNode
import kpn.server.analyzer.engine.analysis.route.structure.RouteAnalysisNodes
import kpn.server.analyzer.engine.analysis.route.structure.RouteLinkNode
import kpn.server.analyzer.engine.analysis.route.structure.RouteLinkWay

import scala.collection.mutable.ListBuffer

Expand Down Expand Up @@ -127,32 +130,43 @@ class RouteNodeAnalyzer(context: RouteDetailAnalysisContext) {

private def findRouteNodes(networkType: NetworkType): Seq[RouteAnalysisNode] = {
val nodeDatas = ListBuffer[RouteAnalysisNode]()
context.relation.members.foreach {
case wayMember: WayMember =>
wayMember.way.nodes.distinct.foreach { node =>
wayNodeData(networkType, node) match {
case None => // not a node network node
case Some(nodeData) =>
if (!nodeDatas.filter(_.isInWay).map(_.node.id).contains(nodeData.node.id)) {
nodeDatas += nodeData
}

context.links.links.foreach { link =>
link match {
case routeLinkWay: RouteLinkWay =>
val nodes = if (routeLinkWay.link.direction == LinkDirection.Backward) {
routeLinkWay.way.nodes.reverse.distinct
}
else {
routeLinkWay.way.nodes.distinct
}
nodes.foreach { node =>
wayNodeData(networkType, node) match {
case None => // not a node network node
case Some(nodeData) =>
if (!nodeDatas.filter(_.isInWay).map(_.node.id).contains(nodeData.node.id)) {
nodeDatas += nodeData
}
}
}
}

case nodeMember: NodeMember =>
if (nodeDatas.map(_.node.id).contains(nodeMember.node.id)) {
// we prefer the position of the node in the ways over the position in the route relation
}
else {
standaloneNodeData(networkType, nodeMember.node) match {
case None => // not a node network node
case Some(nodeData) =>
if (!nodeDatas.filterNot(_.isInWay).map(_.node.id).contains(nodeData.node.id)) {
nodeDatas += nodeData
}
case routeLinkNode: RouteLinkNode =>

if (nodeDatas.map(_.node.id).contains(routeLinkNode.node.id)) {
// we prefer the position of the node in the ways over the position in the route relation
}
}
case _ =>
else {
standaloneNodeData(networkType, routeLinkNode.node) match {
case None => // not a node network node
case Some(nodeData) =>
if (!nodeDatas.filterNot(_.isInWay).map(_.node.id).contains(nodeData.node.id)) {
nodeDatas += nodeData
}
}
}

case _ =>
}
}

val wayNodeIds = nodeDatas.toSeq.filter(_.isInWay).map(_.node.id)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package kpn.server.analyzer.engine.analysis.route.structure

import kpn.core.util.UnitTest

// start tentacle in middle of way in backward order (like route 17613906)
class Structure_N25_Test extends UnitTest {

private def setup = new StructureTestSetupBuilder() {
node(1, "01")
node(3, "01")
node(5, "02")
memberWay(11, "", 3, 2, 1)
memberWay(12, "", 5, 4, 3)
}.build("01", "02")

test("analyze") {

val context = setup.analyze()

context.facts.foreach(a => println(s""""$a","""))
context.links.foreach(a => println(s""""$a","""))
context.nodes.foreach(a => println(s""""$a","""))
context.segments.foreach(a => println(s""""$a","""))
context.paths.foreach(a => println(s""""$a","""))

context.facts.shouldMatchTo(Set.empty)
context.links.shouldMatchTo(
Seq(
"1 p n ■ loop fp bp head tail d backward",
"2 p ■ n loop fp bp head tail d backward",
)
)

context.nodes.shouldMatchTo(
Seq(
"start=3(01)",
"end=5(02)",
"start-tentacle=1(01)",
)
)

context.segments.shouldMatchTo(
Seq(
"segment-1 1>5",
" element-1 1>3 1(01) 3(01) ↔ nodes=1, 2, 3",
" way-11 p n ■ loop fp bp head tail d backward",
" element-2 3>5 3(01) 5(02) ↔ nodes=3, 4, 5",
" way-12 p ■ n loop fp bp head tail d backward",
)
)

context.paths.shouldMatchTo(
Seq(
"forward=3>5 nodes=3, 4, 5",
"backward=5>3 nodes=5, 4, 3",
"start-tentacle=1>3 nodes=1, 2, 3",
)
)
}
}

0 comments on commit 795a625

Please sign in to comment.