Skip to content

Commit

Permalink
#368 migrate route map
Browse files Browse the repository at this point in the history
  • Loading branch information
vmarc committed Jul 17, 2024
1 parent 23e245f commit 73a4503
Show file tree
Hide file tree
Showing 25 changed files with 86 additions and 114 deletions.
3 changes: 0 additions & 3 deletions frontend/src/app/api/common/route/route-info-analysis.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
// this file is generated, please do not modify

import { RouteLocationAnalysis } from '@api/common';
import { RouteMap } from './route-map';

export interface RouteInfoAnalysis {
readonly expectedName: string;
readonly map: RouteMap;
readonly structureStrings: string[];
readonly geometryDigest: string;
readonly locationAnalysis: RouteLocationAnalysis;
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package kpn.api.common.route

import kpn.api.common.RouteLocationAnalysis

case class RouteInfoAnalysis(
expectedName: String,
map: RouteMap,
structureStrings: Seq[String],
geometryDigest: String,
locationAnalysis: RouteLocationAnalysis
)
12 changes: 6 additions & 6 deletions server/src/main/scala/kpn/core/analysis/RouteMemberWay.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import kpn.api.common.data.Element
import kpn.api.common.data.Node
import kpn.api.common.data.Way
import kpn.api.common.route.RouteNetworkNodeInfo
import kpn.server.analyzer.engine.analysis.route.OldRouteNode
import kpn.api.common.route.RouteNode
import kpn.server.analyzer.engine.analysis.route.WayAnalyzer

case class RouteMemberWay(
Expand All @@ -17,7 +17,7 @@ case class RouteMemberWay(
from: String,
to: String,
accessible: Boolean,
routeNodes: Seq[OldRouteNode]
routeNodes: Seq[RouteNode]
) extends RouteMember {

def memberType: String = "way"
Expand All @@ -38,12 +38,12 @@ case class RouteMemberWay(

def nodes: Seq[RouteNetworkNodeInfo] = routeNodes.map { rn =>
RouteNetworkNodeInfo(
rn.id,
rn.nodeId,
rn.name,
rn.alternateName,
rn.longName,
rn.node.latitude,
rn.node.longitude
None, // TODO redesign
"TODO rn.latitude",
"TODO rn.longitude"
)
}

Expand Down
3 changes: 3 additions & 0 deletions server/src/main/scala/kpn/core/doc/RouteDetailDoc.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package kpn.core.doc

import kpn.api.base.WithId
import kpn.api.common.RouteLocationAnalysis
import kpn.api.common.RouteSummary
import kpn.api.common.common.Ref
import kpn.api.common.route.RouteEdge
Expand Down Expand Up @@ -29,6 +30,8 @@ case class RouteDetailDoc(
nameDerivedFromNodes: Boolean,
nodes: RouteNodes,
analysis: RouteInfoAnalysis,
geometryDigest: String,
locationAnalysis: RouteLocationAnalysis,
tiles: Seq[String],
nodeRefs: Seq[Long], // networkNodeIds
elementIds: ElementIds,
Expand Down
2 changes: 2 additions & 0 deletions server/src/main/scala/kpn/core/doc/RouteDoc.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package kpn.core.doc

import kpn.api.base.WithId
import kpn.api.common.RouteLocationAnalysis
import kpn.api.common.RouteSummary
import kpn.api.common.common.Ref
import kpn.api.common.route.RouteInfoAnalysis
Expand Down Expand Up @@ -29,6 +30,7 @@ case class RouteDoc(
nameDerivedFromNodes: Boolean,
nodes: RouteNodes,
analysis: RouteInfoAnalysis,
locationAnalysis: RouteLocationAnalysis,
segments: Seq[RouteSegment],
paths: Seq[RoutePath],
) extends WithId {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class AnalysisStartRouteAnalyzer(log: Log, config: AnalysisStartConfiguration)(i
key = key,
changeType = ChangeType.InitialValue,
name = routeDoc.summary.name,
locationAnalysis = routeDoc.analysis.locationAnalysis,
locationAnalysis = routeDoc.locationAnalysis,
addedToNetwork = Seq.empty,
removedFromNetwork = Seq.empty,
before = None,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,9 @@ class RouteDetailDocBuilder(context: RouteDetailAnalysisContext) {
)
}

val length: Long = context.ways.map(_.length).sum
val length: Long = context.relation.wayMembers.map(_.way.length).sum

val routeWays: Seq[Way] = {
context.routeMembers.flatMap {
case w: RouteMemberWay => Some(w.way)
case _ => None
}
}
val routeWays: Seq[Way] = context.relation.wayMembers.map(_.way)

def routeMemberWays: Seq[RouteMemberWay] = {
context.routeMembers.flatMap {
Expand All @@ -71,9 +66,7 @@ class RouteDetailDocBuilder(context: RouteDetailAnalysisContext) {
val routeAnalysis = RouteInfoAnalysis(
context.expectedName.getOrElse(""),
context.routeMap,
new RouteStructureFormatter(context.structure).strings,
context.geometryDigest,
context.locationAnalysis.get
new RouteStructureFormatter(context.oldStructure).strings,
)

val lastUpdatedElement: Element = {
Expand Down Expand Up @@ -119,6 +112,8 @@ class RouteDetailDocBuilder(context: RouteDetailAnalysisContext) {
nameDerivedFromNodes,
context.nodes.toRouteNodes,
routeAnalysis,
context.geometryDigest,
context._locationAnalysis.get,
context.tiles,
routeAnalysis.map.nodeIds,
context.elementIds,
Expand Down Expand Up @@ -175,11 +170,11 @@ class RouteDetailDocBuilder(context: RouteDetailAnalysisContext) {

private def buildPaths: Seq[RouteDetailPath] = {
Seq(
context.newStructure.forwardPath.toSeq.map(path => toRouteDetailPath(path, "forward")),
context.newStructure.backwardPath.toSeq.map(path => toRouteDetailPath(path, "backward")),
context.newStructure.startTentaclePaths.zipWithIndex.map { case (path, index) => toRouteDetailPath(path, s"start-tentacle-${index + 1}") },
context.newStructure.endTentaclePaths.zipWithIndex.map { case (path, index) => toRouteDetailPath(path, s"end-tentacle-${index + 1}") },
context.newStructure.otherPaths.zipWithIndex.map { case (path, index) => toRouteDetailPath(path, s"other-${index + 1}") },
context.structure.forwardPath.toSeq.map(path => toRouteDetailPath(path, "forward")),
context.structure.backwardPath.toSeq.map(path => toRouteDetailPath(path, "backward")),
context.structure.startTentaclePaths.zipWithIndex.map { case (path, index) => toRouteDetailPath(path, s"start-tentacle-${index + 1}") },
context.structure.endTentaclePaths.zipWithIndex.map { case (path, index) => toRouteDetailPath(path, s"end-tentacle-${index + 1}") },
context.structure.otherPaths.zipWithIndex.map { case (path, index) => toRouteDetailPath(path, s"other-${index + 1}") },
).flatten
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class RouteMainAnalyzer {
context.routeDetailDoc.nameDerivedFromNodes,
context.routeDetailDoc.nodes,
context.routeDetailDoc.analysis,
context.routeDetailDoc.locationAnalysis,
segments,
paths
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class OldRouteStructureAnalyzer(context: RouteDetailAnalysisContext) {
// val structure = analyzeStructure(context.oldRouteNodeAnalysis)
// analyzeStructure2(context.oldRouteNodeAnalysis, structure, context.fragmentMap.all)
context.copy(
_structure = Some(RouteStructure()) // TODO redesign - Some(structure),
_oldStructure = Some(RouteStructure()) // TODO redesign - Some(structure),
// oldFacts = oldFacts.toSeq,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ class RouteAnalysisBuilder(context: RouteDetailAnalysisContext) {
context.unexpectedNodeIds,
context.unexpectedRelationIds,
context.expectedName.getOrElse(""),
context.structure,
context.oldStructure,
context.oldRouteNodeAnalysis,
context.nodes.toRouteNodes
)

RouteDetailAnalysis(
context.relation,
routeDetail = route,
structure = context.structure,
structure = context.oldStructure,
routeNodeAnalysis = context.oldRouteNodeAnalysis,
routeMembers = context._routeMembers.get,
ways = context._ways.get,
Expand Down Expand Up @@ -119,8 +119,6 @@ class RouteAnalysisBuilder(context: RouteDetailAnalysisContext) {
expectedName,
routeMap,
new RouteStructureFormatter(structure).strings,
context.geometryDigest,
context.locationAnalysis.get
)

val lastUpdatedElement: Element = {
Expand Down Expand Up @@ -166,6 +164,8 @@ class RouteAnalysisBuilder(context: RouteDetailAnalysisContext) {
nameDerivedFromNodes,
nodes,
routeAnalysis,
context.geometryDigest,
context.locationAnalysis,
context.tiles,
routeAnalysis.map.nodeIds,
context.elementIds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import org.springframework.stereotype.Component
class RouteLocationAnalyzerImpl(routeRepository: RouteRepository, routeLocator: RouteLocator) extends RouteLocationAnalyzer {

def analyze(context: RouteDetailAnalysisContext): RouteDetailAnalysisContext = {
routeRepository.findRouteById(context.relation.id) match {
routeRepository.findRouteDetailById(context.relation.id) match {
case Some(route) =>
if (route.analysis.geometryDigest == context.geometryDigest) {
context.copy(locationAnalysis = Some(route.analysis.locationAnalysis))
if (route.geometryDigest == context.geometryDigest) {
context.copy(_locationAnalysis = Some(route.locationAnalysis))
}
else {
locate(context)
Expand All @@ -34,7 +34,7 @@ class RouteLocationAnalyzerImpl(routeRepository: RouteRepository, routeLocator:
if (routeLocationAnalysis.location.isEmpty && context.country.nonEmpty) {
val country = context.country.get.domain
context.copy(
locationAnalysis = Some(
_locationAnalysis = Some(
RouteLocationAnalysis(
location = Some(
Location(Seq(country))
Expand All @@ -46,7 +46,7 @@ class RouteLocationAnalyzerImpl(routeRepository: RouteRepository, routeLocator:
)
}
else {
context.copy(locationAnalysis = Some(routeLocationAnalysis))
context.copy(_locationAnalysis = Some(routeLocationAnalysis))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import kpn.core.analysis.RouteMember
import kpn.core.analysis.RouteMemberNode
import kpn.core.analysis.RouteMemberWay
import kpn.core.analysis.TagInterpreter
import kpn.server.analyzer.engine.analysis.route.OldRouteNodeAnalysis
import kpn.server.analyzer.engine.analysis.route.domain.RouteDetailAnalysisContext
import kpn.server.analyzer.engine.analysis.route.structure.RouteAnalysisNodes
import kpn.server.analyzer.engine.analysis.route.structure.RouteLinkWay

object RouteMemberAnalyzer extends RouteAnalyzer {
Expand All @@ -22,7 +22,7 @@ object RouteMemberAnalyzer extends RouteAnalyzer {
class RouteMemberAnalyzer(context: RouteDetailAnalysisContext) {

def analyze: RouteDetailAnalysisContext = {
val routeMembers: Seq[RouteMember] = Seq.empty // TODO redesign - analyzeRouteMembers(context.oldRouteNodeAnalysis)
val routeMembers: Seq[RouteMember] = analyzeRouteMembers(context.nodes)
if (routeMembers.exists(!_.accessible)) {
context.copy(_routeMembers = Some(routeMembers)).withFact(RouteInaccessible)
}
Expand All @@ -31,7 +31,7 @@ class RouteMemberAnalyzer(context: RouteDetailAnalysisContext) {
}
}

private def analyzeRouteMembers(routeNodeAnalysis: OldRouteNodeAnalysis): Seq[RouteMember] = {
private def analyzeRouteMembers(nodes: RouteAnalysisNodes): Seq[RouteMember] = {
// map with key Node.id and value node number
val nodeMap: scala.collection.mutable.Map[Long, Int] = scala.collection.mutable.Map.empty
val nodeNumberIterator = (1 to 10000).iterator
Expand Down Expand Up @@ -71,7 +71,7 @@ class RouteMemberAnalyzer(context: RouteDetailAnalysisContext) {
n
}

val alternateName = routeNodeAnalysis.routeNodes.find(rn => rn.id == node.id).map(_.alternateName) match {
val alternateName = nodes.nodes.find(rn => rn.node.id == node.id).map(_.alternateName) match {
case Some(aname) => aname
case _ => name
}
Expand All @@ -97,7 +97,7 @@ class RouteMemberAnalyzer(context: RouteDetailAnalysisContext) {
else {
false
}
}.flatMap(n => routeNodeAnalysis.routeNodes.find(_.id == n.id))
}.flatMap(n => nodes.nodes.find(_.node.id == n.id))
val name = way.tagValue("name").getOrElse("")

val fromNode = if (link.link.direction == LinkDirection.Forward) way.nodes.head else way.nodes.last
Expand Down Expand Up @@ -137,7 +137,7 @@ class RouteMemberAnalyzer(context: RouteDetailAnalysisContext) {
from.toString,
to.toString,
accessible,
wayNetworkNodes
wayNetworkNodes.map(_.toRouteNode)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class RouteStructureAnalyzer(context: RouteDetailAnalysisContext) {
}

context.copy(
_newStructure = Some(structure),
_structure = Some(structure),
facts = facts.toSeq,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ case class RouteDetailAnalysisContext(
expectedName: Option[String] = None,
suspiciousWayIds: Option[Seq[Long]] = None,
_fragmentMap: Option[FragmentMap] = None,
_structure: Option[RouteStructure] = None,
_newStructure: Option[Structure] = None,
_oldStructure: Option[RouteStructure] = None,
_structure: Option[Structure] = None,
_routeMembers: Option[Seq[RouteMember]] = None,
_routeMap: Option[RouteMap] = None,
_ways: Option[Seq[Way]] = None,
allWayNodes: Option[Seq[Node]] = None,
streets: Option[Seq[String]] = None,
_geometryDigest: Option[String] = None,
locationAnalysis: Option[RouteLocationAnalysis] = None,
_locationAnalysis: Option[RouteLocationAnalysis] = None,
lastSurvey: Option[Day] = None,
labels: Seq[String] = Seq.empty,
_tileAnalysis: Option[RouteTileAnalysis] = None,
Expand Down Expand Up @@ -181,14 +181,16 @@ case class RouteDetailAnalysisContext(

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

def structure: RouteStructure = _structure.getOrElse(throw new PreconditionMissingException)
def oldStructure: RouteStructure = _oldStructure.getOrElse(throw new PreconditionMissingException)

def newStructure: Structure = _newStructure.getOrElse(throw new PreconditionMissingException)
def structure: Structure = _structure.getOrElse(throw new PreconditionMissingException)

def routeMembers: Seq[RouteMember] = _routeMembers.getOrElse(throw new PreconditionMissingException)

def geometryDigest: String = _geometryDigest.getOrElse(throw new PreconditionMissingException)

def locationAnalysis: RouteLocationAnalysis = _locationAnalysis.getOrElse(throw new PreconditionMissingException)

def tileAnalysis: RouteTileAnalysis = _tileAnalysis.getOrElse(throw new PreconditionMissingException)

def oldRouteDetailAnalysis: RouteDetailAnalysis = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ case class Structure(
startTentaclePaths: Seq[StructurePath],
endTentaclePaths: Seq[StructurePath],
otherPaths: Seq[StructurePath]
)
) {
def paths: Seq[StructurePath] = {
forwardPath.toSeq ++ backwardPath.toSeq ++ startTentaclePaths ++ endTentaclePaths ++ otherPaths
}
}
Loading

0 comments on commit 73a4503

Please sign in to comment.