Skip to content

Commit

Permalink
server release 4.1.7 - repair monitor routes with gpx reference and z…
Browse files Browse the repository at this point in the history
…ero segments
  • Loading branch information
vmarc committed Nov 5, 2023
1 parent bfbd642 commit 81c86df
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 25 deletions.
2 changes: 1 addition & 1 deletion server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>knooppuntnet</groupId>
<artifactId>server</artifactId>
<version>4.1.6</version>
<version>4.1.7</version>
<name>server</name>
<description>knooppuntnet server</description>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ object MonitorUpdateTool {
}
}
val tool = new MonitorUpdateTool(database, overpassQueryExecutor)
// tool.testUpdate("A", "_SP12")
tool.update()
// tool.testUpdate("NL-LAW", "LAW-3")
// tool.update()
tool.repair()
}
("update completed", ())
}
Expand Down Expand Up @@ -72,6 +73,18 @@ class MonitorUpdateTool(
monitorRouteStructureLoader
)

def repair(): Unit = {
val groups = configuration.monitorGroupRepository.groups().sortBy(_.name)
val groupRoutes = groups.foreach { group =>
configuration.monitorGroupRepository.groupRoutes(group._id).sortBy(_.name).foreach { route =>
if (route.osmSegmentCount == 0) {
println(s"${group.name} ${route.name}")
testUpdate(group.name, route.name)
}
}
}
}

def testUpdate(groupName: String, routeName: String): Unit = {
configuration.monitorGroupRepository.groupByName(groupName) match {
case None => MonitorUpdateTool.log.error(s"group not found: $groupName")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,20 @@ class MonitorRouteUpdateExecutor(

def execute(originalContext: MonitorUpdateContext): Unit = {
context = originalContext.copy(
referenceType = Some(context.update.referenceType),
analysisStartMillis = Some(System.currentTimeMillis())
)
try {
if (context.update.action == "add") {
if (context.isActionAdd) {
add()
}
else if (context.update.action == "update") {
else if (context.isActionUpdate) {
update()
}
else if (context.update.action == "gpx-upload") {
else if (context.isActionGpxUpload) {
gpxUpload()
}
else if (context.update.action == "gpx-delete") {
else if (context.isActionGpxDelete) {
gpxDelete()
}
}
Expand Down Expand Up @@ -98,6 +99,7 @@ class MonitorRouteUpdateExecutor(
user = "analyzer",
reporter = null,
update = null, //update,
referenceType = Some(oldRoute.referenceType),
group = Some(group),
newRoute = Some(oldRoute),
analysisStartMillis = Some(System.currentTimeMillis()),
Expand Down Expand Up @@ -183,10 +185,10 @@ class MonitorRouteUpdateExecutor(
reportStepActive("analyze-route-structure")
context = monitorUpdateStructure.update(context)

if (context.update.referenceType == "gpx") {
if (context.isReferenceTypeGpx) {
updateRouteWithGpxReference()
}
else if (context.update.referenceType == "multi-gpx") {
else if (context.isReferenceTypeMultiGpx) {
addRouteWithMultiGpxReference()
}
else {
Expand Down Expand Up @@ -265,7 +267,7 @@ class MonitorRouteUpdateExecutor(
removeObsoleteReferences()
removeObsoleteStates()

if (context.update.referenceType == "gpx") {
if (context.isReferenceTypeGpx) {
updateRouteWithGpxReference()
}
else {
Expand Down Expand Up @@ -359,7 +361,7 @@ class MonitorRouteUpdateExecutor(
newReferenceSummaries = context.newReferenceSummaries :+ MonitorRouteReferenceSummary.from(reference),
)

if (context.update.referenceType == "multi-gpx") { // TODO referenceType will always be "multi-gpx" ?
if (context.isReferenceTypeMultiGpx) { // TODO referenceType will always be "multi-gpx" ?
context = context.copy(
newRoute = context.oldRoute
)
Expand Down Expand Up @@ -462,7 +464,7 @@ class MonitorRouteUpdateExecutor(
val osmSegmentAnalysis = monitorRouteOsmSegmentAnalyzer.analyze(wayMembers)
val bounds = Util.mergeBounds(osmSegmentAnalysis.routeSegments.map(_.segment.bounds))

val id = if (context.update.action == "update" || context.update.action == "gpx-upload") {
val id = if (context.isActionUpdate || context.isActionGpxUpload) {
context.oldStateIds.find(_.relationId == mrr.relationId) match {
case Some(oldStateId) => oldStateId._id
case None => ObjectId()
Expand Down Expand Up @@ -652,7 +654,7 @@ class MonitorRouteUpdateExecutor(
geoJsonWriter.setEncodeCRS(false)
val geometry = geoJsonWriter.write(geometryCollection)

val id = if (context.update.action == "update" || context.update.action == "gpx-upload") {
val id = if (context.isActionUpdate || context.isActionGpxUpload) {
monitorRouteRepository.routeRelationReferenceId(context.routeId, Some(subRelation.id)) match {
case Some(id) => id
case None => ObjectId()
Expand Down Expand Up @@ -779,7 +781,6 @@ class MonitorRouteUpdateExecutor(

val referenceTimestamp = context.update.referenceTimestamp.getOrElse(throw new RuntimeException("reference timestamp not found"))

val now = Time.now
val geometryFactory = new GeometryFactory

val geometryCollection = new GeoJsonReader(geometryFactory).read(referenceGeoJson)
Expand All @@ -793,7 +794,7 @@ class MonitorRouteUpdateExecutor(
ObjectId(),
routeId = context.routeId,
relationId = context.relationId,
timestamp = now,
timestamp = Time.now,
user = context.user,
referenceBounds = referenceBounds,
referenceType = "gpx",
Expand Down Expand Up @@ -1022,7 +1023,7 @@ class MonitorRouteUpdateExecutor(
case None =>
case Some(oldRoute) =>

val updatedRelation = if (context.update.referenceType.contains("multi-gpx")) {
val updatedRelation = if (context.isReferenceTypeMultiGpx) {
oldRoute.relation.map { monitorRouteRelation =>
udpateMonitorRouteRelation(context, monitorRouteRelation)
}
Expand All @@ -1032,7 +1033,7 @@ class MonitorRouteUpdateExecutor(
}

val updatedRoute = oldRoute.copy(
referenceDistance = if (context.update.referenceType == "osm") referenceDistance else 0,
referenceDistance = if (context.isReferenceTypeOsm) referenceDistance else 0,
relation = updatedRelation
)

Expand All @@ -1042,7 +1043,7 @@ class MonitorRouteUpdateExecutor(
}

case Some(newRoute) =>
val updatedRelation = if (context.update.referenceType.contains("multi-gpx")) {
val updatedRelation = if (context.isReferenceTypeMultiGpx) {
newRoute.relation.map { monitorRouteRelation =>
udpateMonitorRouteRelation(context, monitorRouteRelation)
}
Expand All @@ -1051,7 +1052,7 @@ class MonitorRouteUpdateExecutor(
newRoute.relation
}
val updatedRoute = newRoute.copy(
referenceDistance = if (context.update.referenceType != "multi-gpx") referenceDistance else 0,
referenceDistance = if (context.isReferenceTypeMultiGpx) referenceDistance else 0,
relation = updatedRelation
)
context = context.copy(
Expand Down Expand Up @@ -1122,7 +1123,7 @@ class MonitorRouteUpdateExecutor(

private def updatedMonitorRouteRelation(monitorRouteRelation: MonitorRouteRelation, stateSummaries: Seq[MonitorRouteStateSummary]): MonitorRouteRelation = {

val updatedWithState = if (context.update != null && context.update.referenceType == "gpx") {
val updatedWithState = if (context.isReferenceTypeGpx) {
stateSummaries.headOption match {
case None => monitorRouteRelation
case Some(stateSummary) =>
Expand Down Expand Up @@ -1160,7 +1161,7 @@ class MonitorRouteUpdateExecutor(
}
}

if (context.update != null && context.update.action == "gpx-delete" && context.update.relationId.get == monitorRouteRelation.relationId) {
if (context.isActionGpxDelete && context.update.relationId.get == monitorRouteRelation.relationId) {
updatedWithState.copy(
referenceTimestamp = None,
referenceFilename = None,
Expand Down Expand Up @@ -1252,7 +1253,7 @@ class MonitorRouteUpdateExecutor(
val relationOption = if (currentRelation.nonEmpty) {
currentRelation
}
else if (context.update != null && context.update.referenceType == "gpx") {
else if (context.isReferenceTypeGpx) {
monitorRouteRelationRepository.load(None, relationId)
}
else {
Expand All @@ -1261,11 +1262,11 @@ class MonitorRouteUpdateExecutor(
relationOption match {
case None => None
case Some(relation) =>
if (context.update != null && context.update.referenceType == "gpx") {
if (context.isReferenceTypeGpx) {
updateSubRelationOsmInfo(relation)
}

val allWayMembers = if (context.update != null && context.update.referenceType == "gpx") {
val allWayMembers = if (context.isReferenceTypeGpx) {
collectAllWayMembers(relation)
}
else {
Expand Down Expand Up @@ -1294,7 +1295,7 @@ class MonitorRouteUpdateExecutor(
routeAnalysis.deviations.isEmpty &&
routeAnalysis.osmSegments.size == 1

val id = if (context.update == null || context.update.action == "update" || context.update.action == "gpx-upload") {
val id = if (context.isActionAnalyze || context.isActionUpdate || context.isActionGpxUpload) {
context.oldStateIds.find(_.relationId == relationId) match {
case Some(oldStateId) => oldStateId._id
case None => ObjectId()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ case class MonitorUpdateContext(
user: String,
reporter: MonitorUpdateReporter,
update: MonitorRouteUpdate,
referenceType: Option[String] = None,
status: MonitorRouteUpdateStatus = MonitorRouteUpdateStatus(),
group: Option[MonitorGroup] = None,
oldRoute: Option[MonitorRoute] = None,
Expand Down Expand Up @@ -94,4 +95,20 @@ case class MonitorUpdateContext(
}
}
}

def isReferenceTypeGpx: Boolean = referenceType.contains("gpx")

def isReferenceTypeMultiGpx: Boolean = referenceType.contains("multi-gpx")

def isReferenceTypeOsm: Boolean = referenceType.contains("osm")

def isActionAdd: Boolean = update != null && update.action == "add"

def isActionUpdate: Boolean = update != null && update.action == "update"

def isActionGpxUpload: Boolean = update != null && update.action == "gpx-upload"

def isActionGpxDelete: Boolean = update != null && update.action == "gpx-delete"

def isActionAnalyze: Boolean = update == null
}

0 comments on commit 81c86df

Please sign in to comment.