Skip to content

Commit

Permalink
#368 setup route analysis tool for development
Browse files Browse the repository at this point in the history
  • Loading branch information
vmarc committed Jun 20, 2024
1 parent de7b186 commit 1149548
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import kpn.api.common.ReplicationId
import kpn.api.common.changes.ChangeSet
import kpn.api.custom.Timestamp
import kpn.core.overpass.OverpassQueryExecutorRemoteImpl
import kpn.core.tools.config.Dirs
import kpn.database.util.Mongo
import kpn.server.analyzer.engine.analysis.location.LocationAnalyzerImpl
import kpn.server.analyzer.engine.analysis.location.RouteLocatorImpl
Expand Down Expand Up @@ -40,6 +41,11 @@ import kpn.server.analyzer.engine.tile.OldLinesTileCalculatorImpl
import kpn.server.analyzer.engine.tile.OldNodeTileCalculatorImpl
import kpn.server.analyzer.engine.tile.OldTileCalculatorImpl
import kpn.server.analyzer.engine.tile.RouteTileCalculatorImpl
import kpn.server.analyzer.engine.tile.TileFileBuilderImpl
import kpn.server.analyzer.engine.tiles.TileAnalyzerImpl
import kpn.server.analyzer.engine.tiles.TileDataNodeBuilderImpl
import kpn.server.analyzer.engine.tiles.TileFileRepositoryImpl
import kpn.server.analyzer.engine.tiles.TilesBuilder
import kpn.server.overpass.OverpassRepository
import kpn.server.overpass.OverpassRepositoryImpl
import kpn.server.repository.AnalysisRepository
Expand Down Expand Up @@ -67,7 +73,7 @@ class AnalysisStartConfiguration(options: AnalysisStartToolOptions) {
val nodeRepository: NodeRepository = new NodeRepositoryImpl(database)
val analysisRepository: AnalysisRepository = new AnalysisRepositoryImpl(database)

private val locationAnalyzer = new LocationAnalyzerImpl(true)
private val locationAnalyzer = new LocationAnalyzerImpl(true, true)

private val tileCalculator = new OldTileCalculatorImpl()

Expand Down Expand Up @@ -155,4 +161,34 @@ class AnalysisStartConfiguration(options: AnalysisStartToolOptions) {
),
ElementIds()
)

private val tileDir = Dirs.root.getAbsolutePath + "/tiles"
private val tileDataNodeBuilder = new TileDataNodeBuilderImpl()

val tileAnalyzer = {
val nodeRepository = new NodeRepositoryImpl(database)
val routeRepository = new RouteRepositoryImpl(database)
new TileAnalyzerImpl(
nodeRepository,
routeRepository,
tileDataNodeBuilder
)
}

val tilesBuilder: TilesBuilder = {
val tileCalculator = new OldTileCalculatorImpl()
val bitmapTileFileRepository = new TileFileRepositoryImpl(tileDir, "png")
val vectorTileFileRepository = new TileFileRepositoryImpl(tileDir, "mvt")
val tileFileBuilder = new TileFileBuilderImpl(bitmapTileFileRepository, vectorTileFileRepository)
val nodeTileCalculator = new OldNodeTileCalculatorImpl(tileCalculator)
val linesTileCalculator = new OldLinesTileCalculatorImpl(tileCalculator)
val routeTileCalculator = new RouteTileCalculatorImpl(linesTileCalculator)
new TilesBuilder(
bitmapTileFileRepository,
vectorTileFileRepository,
tileFileBuilder,
nodeTileCalculator,
routeTileCalculator
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import kpn.api.common.data.RelationMember
import kpn.api.common.data.Way
import kpn.api.common.data.WayMember
import kpn.api.custom.Relation
import kpn.api.custom.Tags
import kpn.api.custom.Timestamp
import kpn.core.tools.next.database.NextDatabase
import kpn.core.tools.next.database.NextDatabaseImpl
import kpn.core.tools.next.domain.NextRouteRelation
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package kpn.core.tools.next.support

import kpn.api.common.tiles.ZoomLevel
import kpn.api.custom.NetworkType
import kpn.api.custom.Relation
import kpn.core.tools.analysis.AnalysisStartConfiguration
import kpn.core.tools.analysis.AnalysisStartToolOptions
import kpn.core.util.Log

object RouteAnalysisTool {
def main(args: Array[String]): Unit = {
val configuration = new AnalysisStartConfiguration(AnalysisStartToolOptions("kpn-next"))
new RouteAnalysisTool(configuration).analyze()
}
}

class RouteAnalysisTool(config: AnalysisStartConfiguration) {
private val log = Log(classOf[RouteAnalysisTool])

def analyze(): Unit = {
log.info("Start")
analyzeRoutes(Seq(13844575L))
buildTiles()
log.info(s"Done")
}

private def analyzeRoutes(routeIds: Seq[Long]): Unit = {
val relations = config.overpassRepository.fullRelations(config.timestamp, routeIds)
relations.foreach { relation =>
analyzeRoute(relation)
}
}

private def analyzeRoute(relation: Relation): Unit = {
Log.context(s"route=${relation.id}") {
try {
config.masterRouteAnalyzer.analyze(relation) match {
case None =>
case Some(routeAnalysis) =>
config.routeRepository.save(routeAnalysis.route)
// TODO saveRouteChange(routeAnalysis)
}
} catch {
case e: Exception =>
log.error(s"Error processing route ${relation.id}", e)
throw e
}
}
}

private def buildTiles(): Unit = {
/* NetworkType.all */ Seq(NetworkType.hiking).foreach { networkType =>
Log.context(networkType.name) {
log.info("Start tile analysis")
val tileAnalysis = config.tileAnalyzer.analysis(networkType)
(ZoomLevel.minZoom to ZoomLevel.vectorTileMaxZoom).foreach { z =>
Log.context(s"$z") {
config.tilesBuilder.build(z, tileAnalysis)
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ object PoiAnalyzerTool {
new PoiLoaderImpl(overpassQueryExecutor)
}
val poiRepository = new PoiRepositoryImpl(poiDatabase)
val locationAnalyzer = new LocationAnalyzerImpl(true)
val locationAnalyzer = new LocationAnalyzerImpl(true, false)
val poiScopeAnalyzer = new PoiScopeAnalyzerImpl(locationAnalyzer)
val tileCalculator: OldTileCalculator = new OldTileCalculatorImpl()
val masterPoiAnalyzer = new MasterPoiAnalyzerImpl()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import org.locationtech.jts.geom.Geometry
import org.springframework.stereotype.Component

@Component
class LocationAnalyzerImpl(analyzerEnabled: Boolean) extends LocationAnalyzerAbstract {
class LocationAnalyzerImpl(analyzerEnabled: Boolean, development: Boolean) extends LocationAnalyzerAbstract {

private val log = Log(classOf[LocationAnalyzerImpl])

private val locationStore = if (analyzerEnabled) {
new LocationStoreReader().read()
new LocationStoreReader(development).read()
}
else {
LocationStore(Seq.empty)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,21 @@ import org.locationtech.jts.geom.Polygon

import java.io.File

class LocationStoreReader {
class LocationStoreReader(development: Boolean) {

private val log = Log(classOf[LocationStoreReader])

private val root = s"${Dirs.root}/locations"

def read(): LocationStore = {
val countries: Seq[LocationStoreCountry] = Country.all.map { country =>
val locationCounties = if (development) {
log.warn("!!! Loading NL and BE locations only!!!")
Seq(Country.nl, Country.be)
}
else {
Country.all
}
val countries: Seq[LocationStoreCountry] = locationCounties.map { country =>
val locationStoreCountry = loadCountry(country)
val filename = s"$root/${country.domain}/tree.json"
val string = FileUtils.readFileToString(new File(filename), "UTF-8")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ class ServerConfiguration {
value
}

@Bean
def development(@Value("${app.development:false}") value: Boolean): Boolean = {
value
}

@Bean
def changeSetInfoEngineEnabled(@Value("${app.change-set-info-engine-enabled:false}") value: Boolean): Boolean = {
value
Expand Down

0 comments on commit 1149548

Please sign in to comment.