Skip to content

Commit

Permalink
prioritize tasks by challenge id in nextTaskReview endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
CollinBeczak committed Apr 15, 2024
1 parent 49bffd1 commit 3e4bce2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class TaskReviewController @Inject() (
onlySaved: Boolean = false,
sort: String,
order: String,
lastChallengeId: Long = -1,
lastTaskId: Long = -1,
excludeOtherReviewers: Boolean = false,
asMetaReview: Boolean = false
Expand All @@ -139,10 +140,12 @@ class TaskReviewController @Inject() (
onlySaved,
sort,
order,
(if (lastChallengeId == -1) None else Some(lastChallengeId)),
(if (lastTaskId == -1) None else Some(lastTaskId)),
excludeOtherReviewers,
asMetaReview
)

val nextTask = result match {
case Some(task) =>
Ok(Json.toJson(this.service.startTaskReview(user, task)))
Expand Down
51 changes: 19 additions & 32 deletions app/org/maproulette/framework/service/TaskReviewService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package org.maproulette.framework.service
import javax.inject.{Inject, Singleton}
import scala.concurrent.duration.FiniteDuration
import org.joda.time.DateTime

import scala.util.Random
import org.maproulette.framework.model._
import org.maproulette.framework.psql.{Query, _}
import org.maproulette.framework.psql.filter.{BaseParameter, _}
Expand Down Expand Up @@ -140,6 +140,7 @@ class TaskReviewService @Inject() (
onlySaved: Boolean = false,
sort: String,
order: String,
lastChallengeId: Option[Long] = None,
lastTaskId: Option[Long] = None,
excludeOtherReviewers: Boolean = false,
asMetaReview: Boolean = false
Expand All @@ -151,10 +152,20 @@ class TaskReviewService @Inject() (

val params = copyParamsForMetaReview(asMetaReview, searchParameters)

val position = lastTaskId match {
case Some(taskId) => {
// Queries for a map of (taskId -> row position)
val rowMap = this.repository.queryTasksWithRowNumber(
// Define a function to prioritize tasks with the same challenge ID
def prioritizeByChallengeId(tasks: List[Task]): List[Task] =
lastChallengeId match {
case Some(challengeId) =>
val filteredTasks =
tasks.filter(task => task.parent == challengeId && task.id != lastTaskId.getOrElse(-1))
if (filteredTasks.nonEmpty) filteredTasks
else tasks.filter(_.id != lastTaskId.getOrElse(-1))
case None => tasks
}

val tasks =
prioritizeByChallengeId(
this.repository.queryTasks(
getReviewRequestedQueries(
user,
params,
Expand All @@ -166,35 +177,11 @@ class TaskReviewService @Inject() (
excludeOtherReviewers,
asMetaReview
),
taskId
params
)
rowMap.get(taskId)

// If our task id is in the row map, we have a position for it
rowMap.get(taskId) match {
case Some(row) => row
case _ => 0
}
}
case _ => 0
}

this.repository
.queryTasks(
getReviewRequestedQueries(
user,
params,
onlySaved,
Paging(1, position),
sort,
order,
false,
excludeOtherReviewers,
asMetaReview
),
params
)
.headOption

Random.shuffle(tasks).headOption
}

/**
Expand Down
2 changes: 1 addition & 1 deletion conf/v2_route/review.api
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ GET /tasks/reviewed @org.maproulette.framework.cont
# in: query
# description: The search string used to match the Reviewer names. (reviewed_by)
###
GET /tasks/review/next @org.maproulette.framework.controller.TaskReviewController.nextTaskReview(onlySaved:Boolean ?= false, sort:String ?= "", order:String ?= "ASC", lastTaskId:Long ?= -1, excludeOtherReviewers:Boolean ?= false, asMetaReview: Boolean ?= false)
GET /tasks/review/next @org.maproulette.framework.controller.TaskReviewController.nextTaskReview(onlySaved:Boolean ?= false, sort:String ?= "", order:String ?= "ASC", lastChallengeId:Long ?= -1, lastTaskId:Long ?= -1, excludeOtherReviewers:Boolean ?= false, asMetaReview: Boolean ?= false)
###
# tags: [ Review ]
# summary: Retrieves nearby Tasks
Expand Down

0 comments on commit 3e4bce2

Please sign in to comment.