Skip to content

Commit

Permalink
#278 monitor route analysis - wip
Browse files Browse the repository at this point in the history
  • Loading branch information
vmarc committed Feb 10, 2024
1 parent b4c4d33 commit 3b392ae
Show file tree
Hide file tree
Showing 8 changed files with 466 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package kpn.core.tools.monitor.support

import kpn.core.data.DataBuilder
import kpn.core.loadOld.Parser
import kpn.core.overpass.OverpassQueryExecutorRemoteImpl
import kpn.core.overpass.QueryRelation
import kpn.server.analyzer.engine.monitor.structure.StructureElementAnalyzer
import org.apache.commons.io.FileUtils

import java.io.File
import scala.jdk.CollectionConverters.CollectionHasAsScala
import scala.xml.XML

object StructureAnalysisTool {
def main(args: Array[String]): Unit = {
new StructureAnalysisTool().analyze()
}
}

class StructureAnalysisTool {

private val overpassQueryExecutor = new OverpassQueryExecutorRemoteImpl()

def analyze(): Unit = {
val ids = FileUtils.readLines(new File("/kpn/cycling-ok-routes.txt")).asScala
ids.zipWithIndex.foreach { case (id, index) =>
val relationId = id.toLong
val xmlString = overpassQueryExecutor.executeQuery(None, QueryRelation(relationId))
val xml = XML.loadString(xmlString)
val rawData = new Parser().parse(xml)
val relation = new DataBuilder(rawData).data.relations(relationId)
val elementGroups = StructureElementAnalyzer.analyze(relation.members)
println(s"${index + 1}/${ids.size} $relationId ${if (elementGroups.size > 1) "ISSUE" else "OK"}")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package kpn.core.tools.monitor.support

import kpn.api.custom.NetworkType
import kpn.core.doc.Label
import kpn.database.base.Database
import kpn.database.base.Id
import kpn.database.util.Mongo
import org.apache.commons.io.FileUtils
import org.mongodb.scala.bson.BsonDocument
import org.mongodb.scala.model.Aggregates.filter
import org.mongodb.scala.model.Aggregates.project
import org.mongodb.scala.model.Filters.and
import org.mongodb.scala.model.Filters.equal
import org.mongodb.scala.model.Projections.fields
import org.mongodb.scala.model.Projections.include

import java.io.File

object StructureFindOkCyclingRoutesTool {
def main(args: Array[String]): Unit = {
Mongo.executeIn("kpn-prod") { database =>
new StructureFindOkCyclingRoutesTool(database).report()
}
}
}

class StructureFindOkCyclingRoutesTool(database: Database) {
def report(): Unit = {
println("Collecting route ids")
val pipeline = Seq(
filter(
and(
equal("labels", Label.active),
equal("labels", Label.networkType(NetworkType.cycling)),
BsonDocument("""{"facts": { "$size": 0 }}""")
)
),
project(
fields(
include("_id")
)
)
)
val ids = database.routes.aggregate[Id](pipeline).map(_._id).sorted
println(s"${ids.size} routes")
FileUtils.writeStringToFile(new File("/kpn/cycling-ok-routes.txt"), ids.map(_.toString).mkString("\n"))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package kpn.core.tools.monitor.support

import kpn.database.base.Database
import kpn.database.util.Mongo
import kpn.server.repository.RouteRepositoryImpl
import org.apache.commons.io.FileUtils

import java.io.File
import scala.jdk.CollectionConverters.CollectionHasAsScala

object StructureIssueAnalysisTool {
def main(args: Array[String]): Unit = {
Mongo.executeIn("kpn-prod") { database =>
new StructureIssueAnalysisTool(database).analyze()
}
}
}

class StructureIssueAnalysisTool(database: Database) {

val routeRepository = new RouteRepositoryImpl(database)

def analyze(): Unit = {
val routeIds = FileUtils.readLines(new File("/kpn/cycling-nok-routes.txt")).asScala.map(_.toLong)
routeIds.zipWithIndex.foreach { case (routeId, index) =>
routeRepository.findById(routeId) match {
case None => println(s"${index + 1}/${routeIds.size} $routeId not found")
case Some(route) =>
val hasIssueLink = route.analysis.members.exists { member =>
StructureIssueLinks.links.contains(member.linkName)
}
println(s"${index + 1}/${routeIds.size} $routeId ${if (hasIssueLink) "ISSUE" else "OK"}")
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
package kpn.core.tools.monitor.support

object StructureIssueLinks {
val links = Seq(
"wb000",
"wb001",
"wb002",
"wb008",
"wb009",
"wb010",
"wb016",
"wb017",
"wb018",
"wb024",
"wb025",
"wb026",
"wb032",
"wb033",
"wb034",
"wb040",
"wb041",
"wb042",
"wb048",
"wb049",
"wb050",
"wb056",
"wb057",
"wb058",
"wb064",
"wb065",
"wb066",
"wb072",
"wb073",
"wb074",
"wb080",
"wb081",
"wb082",
"wb088",
"wb089",
"wb090",
"wb096",
"wb097",
"wb098",
"wb104",
"wb105",
"wb106",
"wb112",
"wb113",
"wb114",
"wb120",
"wb121",
"wb122",
"wf000",
"wf001",
"wf002",
"wf008",
"wf009",
"wf010",
"wf016",
"wf017",
"wf018",
"wf024",
"wf025",
"wf026",
"wf032",
"wf033",
"wf034",
"wf040",
"wf041",
"wf042",
"wf048",
"wf049",
"wf050",
"wf056",
"wf057",
"wf058",
"wf064",
"wf065",
"wf066",
"wf072",
"wf073",
"wf074",
"wf080",
"wf081",
"wf082",
"wf088",
"wf089",
"wf090",
"wf096",
"wf097",
"wf098",
"wf104",
"wf105",
"wf106",
"wf112",
"wf113",
"wf114",
"wf120",
"wf121",
"wf122",
"wl000",
"wl001",
"wl002",
"wl008",
"wl009",
"wl010",
"wl016",
"wl017",
"wl018",
"wl024",
"wl025",
"wl026",
"wl032",
"wl033",
"wl034",
"wl040",
"wl041",
"wl042",
"wl048",
"wl049",
"wl050",
"wl056",
"wl057",
"wl058",
"wl064",
"wl065",
"wl066",
"wl072",
"wl073",
"wl074",
"wl080",
"wl081",
"wl082",
"wl088",
"wl089",
"wl090",
"wl096",
"wl097",
"wl098",
"wl104",
"wl105",
"wl106",
"wl112",
"wl113",
"wl114",
"wl120",
"wl121",
"wl122",
"wn000",
"wn001",
"wn002",
"wn008",
"wn009",
"wn010",
"wn016",
"wn017",
"wn018",
"wn024",
"wn025",
"wn026",
"wn032",
"wn033",
"wn034",
"wn040",
"wn041",
"wn042",
"wn048",
"wn049",
"wn050",
"wn056",
"wn057",
"wn058",
"wn064",
"wn065",
"wn066",
"wn072",
"wn073",
"wn074",
"wn080",
"wn081",
"wn082",
"wn088",
"wn089",
"wn090",
"wn096",
"wn097",
"wn098",
"wn104",
"wn105",
"wn106",
"wn112",
"wn113",
"wn114",
"wn120",
"wn121",
"wn122",
"wr000",
"wr001",
"wr002",
"wr008",
"wr009",
"wr010",
"wr016",
"wr017",
"wr018",
"wr024",
"wr025",
"wr026",
"wr032",
"wr033",
"wr034",
"wr040",
"wr041",
"wr042",
"wr048",
"wr049",
"wr050",
"wr056",
"wr057",
"wr058",
"wr064",
"wr065",
"wr066",
"wr072",
"wr073",
"wr074",
"wr080",
"wr081",
"wr082",
"wr088",
"wr089",
"wr090",
"wr096",
"wr097",
"wr098",
"wr104",
"wr105",
"wr106",
"wr112",
"wr113",
"wr114",
"wr120",
"wr121",
"wr122",
)
}

0 comments on commit 3b392ae

Please sign in to comment.