Skip to content

Commit

Permalink
#368 migrate structure tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vmarc committed Jul 14, 2024
1 parent a51ecb6 commit 42cb5a0
Show file tree
Hide file tree
Showing 15 changed files with 200 additions and 198 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class RouteDetailDocBuilder(context: RouteDetailAnalysisContext) {
context.unexpectedNodeIds.get,
context.unexpectedRelationIds.get,
members,
context.expectedName.get,
context.expectedName.getOrElse(""),
nameDerivedFromNodes,
context.routeMap,
new RouteStructureFormatter(context.structure).strings,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package kpn.server.analyzer.engine.analysis.route

case class RouteNodeAnalysis(
reversed: Boolean = false, // TODO redesign - obsolete?
freeNodes: Seq[RouteNodeData] = Seq.empty, // TODO redesign - obsolete?
startNode: Option[RouteNodeData] = None,
endNode: Option[RouteNodeData] = None,
startTentacleFromNodes: Seq[RouteNodeData] = Seq.empty,
endTentacleToNodes: Seq[RouteNodeData] = Seq.empty,
startTentacleNodes: Seq[RouteNodeData] = Seq.empty,
endTentacleNodes: Seq[RouteNodeData] = Seq.empty,
redundantNodes: Seq[RouteNodeData] = Seq.empty
) {
def nodes: Seq[RouteNodeData] = startNode.toSeq ++ endNode.toSeq ++ startTentacleFromNodes ++ endTentacleToNodes
def nodes: Seq[RouteNodeData] = startNode.toSeq ++ endNode.toSeq ++ startTentacleNodes ++ endTentacleNodes

def nodeIds: Seq[Long] = nodes.map(_.node.id)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ class RouteNodeAnalysisFormatter(analysis: RouteNodeAnalysis) {

def nodeStrings: Seq[String] = {
List(
nodeStrings("Free", analysis.freeNodes),
nodeStrings("Start", analysis.startNode.toSeq),
nodeStrings("End", analysis.endNode.toSeq),
nodeStrings("Start tentacle from", analysis.startTentacleFromNodes),
nodeStrings("End tentacle to", analysis.endTentacleToNodes),
nodeStrings("Start tentacle from", analysis.startTentacleNodes),
nodeStrings("End tentacle to", analysis.endTentacleNodes),
nodeStrings("Redundant", analysis.redundantNodes),
if (analysis.reversed) Seq("(reversed)") else Seq.empty
).flatten
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import org.locationtech.jts.geom.GeometryFactory
object OldRouteSegmentAnalyzer extends RouteAnalyzer {
def analyze(context: RouteDetailAnalysisContext): RouteDetailAnalysisContext = {
val wayMembers = context.relation.wayMembers
val segmentAnalysis = new OldRouteSegmentAnalyzer(context.routeNodeAnalysis).analyze(wayMembers)
val segmentAnalysis = new OldRouteSegmentAnalyzer(context.nodeAnalysis).analyze(wayMembers)
context.copy(
_segmentAnalysis = Some(segmentAnalysis)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ object RouteNodeAnalyzer extends RouteAnalyzer {
new RouteNodeAnalyzer(context).analyze
}
else {
context.copy(_routeNodeAnalysis = Some(RouteNodeAnalysis()))
context.copy(_nodeAnalysis = Some(RouteNodeAnalysis()))
}
}
}
Expand Down Expand Up @@ -90,12 +90,10 @@ class RouteNodeAnalyzer(context: RouteDetailAnalysisContext) {
val redundantNodes = routeNodeDatas.filterNot(n => startNodes.contains(n) || endNodes.contains(n))

val routeNodeAnalysis = RouteNodeAnalysis(
reversed = false,
freeNodes = Seq.empty,
startNode = startNodes.lastOption,
endNode = endNodes.headOption,
startTentacleFromNodes = startNodes.dropRight(1),
endTentacleToNodes = endNodes.drop(1),
startTentacleNodes = startNodes.dropRight(1),
endTentacleNodes = endNodes.drop(1),
redundantNodes = redundantNodes
)

Expand All @@ -115,7 +113,7 @@ class RouteNodeAnalyzer(context: RouteDetailAnalysisContext) {
}

context.copy(
_routeNodeAnalysis = Some(routeNodeAnalysis)
_nodeAnalysis = Some(routeNodeAnalysis)
).withFacts(facts.toSeq *)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ case class RouteDetailAnalysisContext(
unexpectedRelationIds: Option[Seq[Long]] = None,
_routeNameAnalysis: Option[RouteNameAnalysis] = None,
_oldRouteNodeAnalysis: Option[OldRouteNodeAnalysis] = None,
_routeNodeAnalysis: Option[RouteNodeAnalysis] = None,
_nodeAnalysis: Option[RouteNodeAnalysis] = None,
expectedName: Option[String] = None,
suspiciousWayIds: Option[Seq[Long]] = None,
_fragmentMap: Option[FragmentMap] = None,
Expand Down Expand Up @@ -177,7 +177,7 @@ case class RouteDetailAnalysisContext(

def oldRouteNodeAnalysis: OldRouteNodeAnalysis = _oldRouteNodeAnalysis.getOrElse(throw new PreconditionMissingException)

def routeNodeAnalysis: RouteNodeAnalysis = _routeNodeAnalysis.getOrElse(throw new PreconditionMissingException)
def nodeAnalysis: RouteNodeAnalysis = _nodeAnalysis.getOrElse(throw new PreconditionMissingException)

def fragmentMap: FragmentMap = _fragmentMap.getOrElse(throw new PreconditionMissingException)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class RouteLinksReport(context: RouteDetailAnalysisContext) {
else {
(head, last)
}
("node", routeLinkWay.way.id, "TODO", from, to, networkNodeString(routeLinkWay.way.nodeIds))
("node", routeLinkWay.way.id, "TODO", from, to, allNodes(routeLinkWay.way.nodeIds))
case routeLinkRelationId: RouteLinkRelationId =>
("node", routeLinkRelationId.relationId, "TODO", "", "", "")
}
Expand Down Expand Up @@ -84,19 +84,18 @@ class RouteLinksReport(context: RouteDetailAnalysisContext) {
|""".stripMargin
}

private def networkNodeString(nodeIds: Seq[Long]): String = {
private def allNodes(nodeIds: Seq[Long]): String = {
Seq(
networkNodeStrings(nodeIds, "start", context.routeNodeAnalysis.startNode.toSeq),
networkNodeStrings(nodeIds, "end", context.routeNodeAnalysis.endNode.toSeq),
networkNodeStrings(nodeIds, "start tentacle", context.routeNodeAnalysis.startTentacleFromNodes),
networkNodeStrings(nodeIds, "end tentacle", context.routeNodeAnalysis.endTentacleToNodes),
networkNodeStrings(nodeIds, "free", context.routeNodeAnalysis.freeNodes),
networkNodeStrings(nodeIds, "redundant", context.routeNodeAnalysis.redundantNodes)
nodes(nodeIds, "start", context.nodeAnalysis.startNode.toSeq),
nodes(nodeIds, "end", context.nodeAnalysis.endNode.toSeq),
nodes(nodeIds, "start tentacle", context.nodeAnalysis.startTentacleNodes),
nodes(nodeIds, "end tentacle", context.nodeAnalysis.endTentacleNodes),
nodes(nodeIds, "redundant", context.nodeAnalysis.redundantNodes)
).flatten.mkString(", ")
}

private def networkNodeStrings(nodeIds: Seq[Long], nodeType: String, routeNodeDatas: Seq[RouteNodeData]): Seq[String] = {
val routeNodeDatasInFragment = routeNodeDatas.filter(n => nodeIds.contains(n.node.id))
routeNodeDatasInFragment.map(routeNodeData => s"$nodeType=${routeNodeData.node.id}(${routeNodeData.name})")
private def nodes(nodeIds: Seq[Long], nodeType: String, nodeDatas: Seq[RouteNodeData]): Seq[String] = {
val filteredNodeDatas = nodeDatas.filter(n => nodeIds.contains(n.node.id))
filteredNodeDatas.map(nodeData => s"$nodeType=${nodeData.node.id}(${nodeData.name})")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import kpn.server.analyzer.engine.analysis.route.domain.RouteDetailAnalysisConte
object RouteNodeAnalysisReport {

def report(context: RouteDetailAnalysisContext): String = {
val routeNodeAnalysis = context.routeNodeAnalysis
if (routeNodeAnalysis.startNode.nonEmpty || routeNodeAnalysis.endNode.nonEmpty || routeNodeAnalysis.freeNodes.nonEmpty || routeNodeAnalysis.redundantNodes.nonEmpty) {
val nodeAnalysis = context.nodeAnalysis
if (nodeAnalysis.startNode.nonEmpty || nodeAnalysis.endNode.nonEmpty || nodeAnalysis.redundantNodes.nonEmpty) {
s"""
|<table>
| <tr class="header">
Expand All @@ -19,11 +19,9 @@ object RouteNodeAnalysisReport {
| <td>name</td>
| <td>isInWay</td>
| </tr>
| ${routeNodeAnalysis.startNode.map(n => routeNodeReport("startNode", n)).mkString}
| ${routeNodeAnalysis.endNode.map(n => routeNodeReport("endNode", n)).mkString}
| ${routeNodeAnalysis.freeNodes.map(n => routeNodeReport("freeNode", n)).mkString}
| ${routeNodeAnalysis.redundantNodes.map(n => routeNodeReport("redundantNode", n)).mkString}
| <tr><td colspan="4">reversed: ${routeNodeAnalysis.reversed}</td></tr>
| ${nodeAnalysis.startNode.map(n => routeNodeReport("startNode", n)).mkString}
| ${nodeAnalysis.endNode.map(n => routeNodeReport("endNode", n)).mkString}
| ${nodeAnalysis.redundantNodes.map(n => routeNodeReport("redundantNode", n)).mkString}
|</table>
|""".stripMargin
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,24 +109,23 @@ class RouteSegmentReport(context: RouteDetailAnalysisContext) {
| <td>
| $to
| </td>
| <td>${networkNodeString(fragment.nodeIds)}</td>
| <td>${allNodes(fragment.nodeIds)}</td>
|</tr>
|""".stripMargin
}

private def networkNodeString(nodeIds: Seq[Long]): String = {
private def allNodes(nodeIds: Seq[Long]): String = {
Seq(
networkNodeStrings(nodeIds, "start", context.routeNodeAnalysis.startNode.toSeq),
networkNodeStrings(nodeIds, "end", context.routeNodeAnalysis.endNode.toSeq),
networkNodeStrings(nodeIds, "start tentacle", context.routeNodeAnalysis.startTentacleFromNodes),
networkNodeStrings(nodeIds, "end tentacle", context.routeNodeAnalysis.endTentacleToNodes),
networkNodeStrings(nodeIds, "free", context.routeNodeAnalysis.freeNodes),
networkNodeStrings(nodeIds, "redundant", context.routeNodeAnalysis.redundantNodes)
nodes(nodeIds, "start", context.nodeAnalysis.startNode.toSeq),
nodes(nodeIds, "end", context.nodeAnalysis.endNode.toSeq),
nodes(nodeIds, "start tentacle", context.nodeAnalysis.startTentacleNodes),
nodes(nodeIds, "end tentacle", context.nodeAnalysis.endTentacleNodes),
nodes(nodeIds, "redundant", context.nodeAnalysis.redundantNodes)
).flatten.mkString(", ")
}

private def networkNodeStrings(nodeIds: Seq[Long], nodeType: String, routeNodeDatas: Seq[RouteNodeData]): Seq[String] = {
val routeNodeDatasInFragment = routeNodeDatas.filter(n => nodeIds.contains(n.node.id))
routeNodeDatasInFragment.map(routeNodeData => s"$nodeType=${routeNodeData.node.id}(${routeNodeData.name})")
private def nodes(nodeIds: Seq[Long], nodeType: String, nodeDatas: Seq[RouteNodeData]): Seq[String] = {
val filteredNodeDatas = nodeDatas.filter(n => nodeIds.contains(n.node.id))
filteredNodeDatas.map(nodeData => s"$nodeType=${nodeData.node.id}(${nodeData.name})")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,16 @@ class StructureElementGroupsReport(context: RouteDetailAnalysisContext) {

private def networkNodes(fragment: StructureFragment): String = {
Seq(
fragmentNodes(fragment, "start", context.routeNodeAnalysis.startNode.toSeq),
fragmentNodes(fragment, "end", context.routeNodeAnalysis.endNode.toSeq),
fragmentNodes(fragment, "start tentacle", context.routeNodeAnalysis.startTentacleFromNodes),
fragmentNodes(fragment, "end tentacle", context.routeNodeAnalysis.endTentacleToNodes),
fragmentNodes(fragment, "free", context.routeNodeAnalysis.freeNodes),
fragmentNodes(fragment, "redundant", context.routeNodeAnalysis.redundantNodes)
fragmentNodes(fragment, "start", context.nodeAnalysis.startNode.toSeq),
fragmentNodes(fragment, "end", context.nodeAnalysis.endNode.toSeq),
fragmentNodes(fragment, "start tentacle", context.nodeAnalysis.startTentacleNodes),
fragmentNodes(fragment, "end tentacle", context.nodeAnalysis.endTentacleNodes),
fragmentNodes(fragment, "redundant", context.nodeAnalysis.redundantNodes)
).flatten.mkString(", ")
}

private def fragmentNodes(fragment: StructureFragment, nodeType: String, routeNodeDatas: Seq[RouteNodeData]): Seq[String] = {
val routeNodeDatasInFragment = routeNodeDatas.filter(n => fragment.nodeIds.contains(n.node.id))
private def fragmentNodes(fragment: StructureFragment, nodeType: String, nodeDatas: Seq[RouteNodeData]): Seq[String] = {
val routeNodeDatasInFragment = nodeDatas.filter(n => fragment.nodeIds.contains(n.node.id))
routeNodeDatasInFragment.map(routeNodeData => s"$nodeType=${routeNodeData.name}(${routeNodeData.node.id})")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ class RouteSegmentAnalyzer(context: RouteDetailAnalysisContext) {
handleRoundabout(previousRouteLinkWayOption, currentRouteLinkWay, nextRouteLinkWayOption)
}
else {
val linkFragments = StructureUtil.split(currentRouteLinkWay.nodeIds, context.routeNodeAnalysis.nodeIds).map { nodeIds =>
val linkFragments = StructureUtil.split(currentRouteLinkWay.nodeIds, context.nodeAnalysis.nodeIds).map { nodeIds =>
toFragment(currentRouteLinkWay, nodeIds)
}

if (context.routeNodeAnalysis.nodeIds.contains(linkFragments.head.fromNodeId)) {
if (context.nodeAnalysis.nodeIds.contains(linkFragments.head.fromNodeId)) {
finalizeSegmentElement()
}

linkFragments.foreach { fragment =>
if (context.routeNodeAnalysis.nodeIds.contains(fragment.nodeIds.last)) {
if (context.nodeAnalysis.nodeIds.contains(fragment.nodeIds.last)) {
fragments += fragment
finalizeSegmentElement()
}
Expand Down Expand Up @@ -184,7 +184,7 @@ class RouteSegmentAnalyzer(context: RouteDetailAnalysisContext) {
}

private def fragmentEndContainsNetworkNode(fragment: NewRouteSegmentElementFragment): Boolean = {
context.routeNodeAnalysis.nodeIds.contains(fragment.nodeIds.last) // TODO redesign - not sure if this is ok
context.nodeAnalysis.nodeIds.contains(fragment.nodeIds.last) // TODO redesign - not sure if this is ok
}

private def buildSegmentElement(fragments: Seq[NewRouteSegmentElementFragment]): NewRouteSegmentElement = {
Expand All @@ -201,8 +201,8 @@ class RouteSegmentAnalyzer(context: RouteDetailAnalysisContext) {
RoutePathDirection.Bidirectional
}

val fromNetworkNode = context.routeNodeAnalysis.nodes.find(_.node.id == fromNodeId)
val toNetworkNode = context.routeNodeAnalysis.nodes.find(_.node.id == toNodeId)
val fromNetworkNode = context.nodeAnalysis.nodes.find(_.node.id == fromNodeId)
val toNetworkNode = context.nodeAnalysis.nodes.find(_.node.id == toNodeId)

NewRouteSegmentElement(
elementIds.next(),
Expand Down Expand Up @@ -234,8 +234,8 @@ class RouteSegmentAnalyzer(context: RouteDetailAnalysisContext) {
nodeIds
)

val fromNetworkNode = context.routeNodeAnalysis.nodes.find(_.node.id == fragment.fromNodeId)
val toNetworkNode = context.routeNodeAnalysis.nodes.find(_.node.id == fragment.toNodeId)
val fromNetworkNode = context.nodeAnalysis.nodes.find(_.node.id == fragment.fromNodeId)
val toNetworkNode = context.nodeAnalysis.nodes.find(_.node.id == fragment.toNodeId)

NewRouteSegmentElement(
elementIds.next(),
Expand Down
Loading

0 comments on commit 42cb5a0

Please sign in to comment.