Skip to content

Commit

Permalink
Merge pull request #3517 from ProjectSidewalk/develop
Browse files Browse the repository at this point in the history
v7.19.0
  • Loading branch information
misaugstad authored Mar 14, 2024
2 parents a98c138 + 9915ce8 commit 01006cb
Show file tree
Hide file tree
Showing 50 changed files with 1,123 additions and 1,107 deletions.
7 changes: 4 additions & 3 deletions app/controllers/AdminController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import models.attribute.{GlobalAttribute, GlobalAttributeTable}
import models.audit.{AuditTaskInteractionTable, AuditTaskTable, AuditedStreetWithTimestamp, InteractionWithLabel}
import models.daos.slick.DBTableDefinitions.UserTable
import models.gsv.{GSVDataSlim, GSVDataTable}
import models.label.LabelTable.LabelMetadata
import models.label.LabelTable.{AdminValidationData, LabelMetadata}
import models.label.{LabelLocationWithSeverity, LabelPointTable, LabelTable, LabelTypeTable, LabelValidationTable}
import models.mission.MissionTable
import models.region.RegionCompletionTable
Expand Down Expand Up @@ -368,7 +368,8 @@ class AdminController @Inject() (implicit val env: Environment[User, SessionAuth
case Some(labelPointObj) =>
val userId: String = request.identity.get.userId.toString
val labelMetadata: LabelMetadata = LabelTable.getSingleLabelMetadata(labelId, userId)
val labelMetadataJson: JsObject = LabelFormat.labelMetadataWithValidationToJsonAdmin(labelMetadata)
val adminData: AdminValidationData = LabelTable.getExtraAdminValidateData(List(labelId)).head
val labelMetadataJson: JsObject = LabelFormat.labelMetadataWithValidationToJsonAdmin(labelMetadata, adminData)
Future.successful(Ok(labelMetadataJson))
case _ => Future.failed(new NotFoundException("No label found with that ID"))
}
Expand Down Expand Up @@ -401,7 +402,7 @@ class AdminController @Inject() (implicit val env: Environment[User, SessionAuth

// Grab 10k labels at a time and write them to a JSON file to reduce server memory usage and crashes.
var startIndex: Int = 0
val batchSize: Int = 10000
val batchSize: Int = 20000
var moreWork: Boolean = true
while (moreWork) {
val features: List[JsValue] = LabelTable.getLabelCVMetadata(startIndex, batchSize).map(l => Json.toJson(l))
Expand Down
744 changes: 204 additions & 540 deletions app/controllers/ProjectSidewalkAPIController.scala

Large diffs are not rendered by default.

25 changes: 9 additions & 16 deletions app/controllers/ValidationController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.mohiva.play.silhouette.api.{Environment, Silhouette}
import com.mohiva.play.silhouette.impl.authenticators.SessionAuthenticator
import controllers.headers.ProvidesHeader
import controllers.helper.ControllerUtils.{isAdmin, isMobile}
import controllers.helper.ValidateHelper.AdminValidateParams
import controllers.helper.ValidateHelper.{AdminValidateParams, getLabelTypeIdToValidate}
import formats.json.CommentSubmissionFormats._
import formats.json.LabelFormat
import models.amt.AMTAssignmentTable
Expand Down Expand Up @@ -67,7 +67,7 @@ class ValidationController @Inject() (implicit val env: Environment[User, Sessio
if (validationData._4.missionType != "validation" || user.role.getOrElse("") == "Turker" || !isMobile(request)) {
Future.successful(Redirect("/explore"))
} else {
Future.successful(Ok(views.html.mobileValidate("Sidewalk - Validate", Some(user), validationData._1, validationData._2, validationData._3, validationData._4.numComplete, validationData._5, validationData._6)))
Future.successful(Ok(views.html.mobileValidate("Sidewalk - Validate", Some(user), adminParams, validationData._1, validationData._2, validationData._3, validationData._4.numComplete, validationData._5, validationData._6)))
}
case None =>
Future.successful(Redirect(s"/anonSignUp?url=/mobile"));
Expand Down Expand Up @@ -140,23 +140,16 @@ class ValidationController @Inject() (implicit val env: Environment[User, Sessio
if (user.role.getOrElse("") == "Turker") MissionTable.getProgressOnMissionSet(user.username)
else MissionTable.defaultValidationMissionSetProgress

val possibleLabTypeIds: List[Int] = LabelTable.retrievePossibleLabelTypeIds(user.userId, labelCount, None)
.filter(labTypeId => adminParams.labelTypeId.isEmpty || adminParams.labelTypeId.get == labTypeId)
val hasWork: Boolean = possibleLabTypeIds.nonEmpty
val labelTypeId: Option[Int] = getLabelTypeIdToValidate(user.userId, labelCount, adminParams.labelTypeId)

val completedValidations: Int = LabelValidationTable.countValidations(user.userId)
// Checks if there are still labels in the database for the user to validate.
if (hasWork && missionSetProgress.missionType == "validation") {
// possibleLabTypeIds can contain [1, 2, 3, 4, 7, 9, 10]. Select ids 1, 2, 3, 4, 9, 10 if possible, o/w choose 7.
val possibleIds: List[Int] =
if (possibleLabTypeIds.size > 1) possibleLabTypeIds.filter(_ != 7)
else possibleLabTypeIds
val index: Int = if (possibleIds.size > 1) scala.util.Random.nextInt(possibleIds.size) else 0
val labelTypeId: Int = possibleIds(index)
val mission: Mission = MissionTable.resumeOrCreateNewValidationMission(user.userId,
AMTAssignmentTable.TURKER_PAY_PER_LABEL_VALIDATION, 0.0, validationMissionStr, labelTypeId).get

val labelList: JsValue = getLabelListForValidation(user.userId, labelTypeId, mission, adminParams)
if (labelTypeId.isDefined && missionSetProgress.missionType == "validation") {
val mission: Mission = MissionTable.resumeOrCreateNewValidationMission(
user.userId, AMTAssignmentTable.TURKER_PAY_PER_LABEL_VALIDATION, 0.0, validationMissionStr, labelTypeId.get
).get

val labelList: JsValue = getLabelListForValidation(user.userId, labelTypeId.get, mission, adminParams)
val missionJsObject: JsObject = mission.toJSON
val progressJsObject: JsObject = LabelValidationTable.getValidationProgress(mission.missionId)
val hasDataForMission: Boolean = labelList.toString != "[]"
Expand Down
61 changes: 26 additions & 35 deletions app/controllers/ValidationTaskController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.mohiva.play.silhouette.api.{Environment, Silhouette}
import com.mohiva.play.silhouette.impl.authenticators.SessionAuthenticator
import controllers.headers.ProvidesHeader
import controllers.helper.ControllerUtils.{isAdmin, sendSciStarterContributions}
import controllers.helper.ValidateHelper.AdminValidateParams
import controllers.helper.ValidateHelper.{AdminValidateParams, getLabelTypeIdToValidate}
import formats.json.ValidationTaskSubmissionFormats._
import models.amt.AMTAssignmentTable
import models.label._
Expand Down Expand Up @@ -61,10 +61,23 @@ class ValidationTaskController @Inject() (implicit val env: Environment[User, Se
for (label: LabelValidationSubmission <- data.labels) {
userOption match {
case Some(user) =>
LabelValidationTable.insertOrUpdate(LabelValidation(0, label.labelId, label.validationResult,
user.userId.toString, label.missionId, label.canvasX, label.canvasY, label.heading, label.pitch, label.zoom,
label.canvasHeight, label.canvasWidth, new Timestamp(label.startTimestamp),
new Timestamp(label.endTimestamp), label.source))
val undoneValidation: Boolean = label.undone.getOrElse(false)
if (undoneValidation) {
// Deleting the last label's comment if it exists.
ValidationTaskCommentTable.deleteIfExists(label.labelId, label.missionId)

// Delete the label from the label_validation table.
LabelValidationTable.deleteLabelValidation(LabelValidation(0, label.labelId, label.validationResult,
identity.get.userId.toString, label.missionId, label.canvasX, label.canvasY,
label.heading, label.pitch, label.zoom, label.canvasHeight, label.canvasWidth,
new Timestamp(label.startTimestamp), new Timestamp(label.endTimestamp), label.source))
} else {
// Adding (or updating) the new label in the label_validation table.
LabelValidationTable.insertOrUpdate(LabelValidation(0, label.labelId, label.validationResult,
user.userId.toString, label.missionId, label.canvasX, label.canvasY, label.heading, label.pitch, label.zoom,
label.canvasHeight, label.canvasWidth, new Timestamp(label.startTimestamp),
new Timestamp(label.endTimestamp), label.source))
}
case None =>
Logger.warn("User without user_id validated a label, but every user should have a user_id.")
}
Expand All @@ -79,8 +92,14 @@ class ValidationTaskController @Inject() (implicit val env: Environment[User, Se
val returnValue: ValidationTaskPostReturnValue = data.missionProgress match {
case Some(_) =>
val missionProgress: ValidationMissionProgress = data.missionProgress.get
val currentMissionLabelTypeId: Int = missionProgress.labelTypeId
val nextMissionLabelTypeId: Option[Int] = getLabelTypeId(userOption, missionProgress, Some(currentMissionLabelTypeId), adminParams)
val nextMissionLabelTypeId: Option[Int] =
if (missionProgress.completed) {
val labelsToRetrieve: Int = MissionTable.validationMissionLabelsToRetrieve
getLabelTypeIdToValidate(userOption.get.userId, labelsToRetrieve, adminParams.labelTypeId)
} else {
None
}

nextMissionLabelTypeId match {
// Load new mission, generate label list for validation.
case Some (nextMissionLabelTypeId) =>
Expand Down Expand Up @@ -220,34 +239,6 @@ class ValidationTaskController @Inject() (implicit val env: Environment[User, Se
)
}

/**
* Returns the label type id for the next validation mission.
*
* @param user UserId of the current user.
* @param missionProgress Progress of the current validation mission.
* @param currentLabelTypeId Label Type ID of the current mission
* @param adminParams Parameters related to the admin version of the validate page.
*/
def getLabelTypeId(user: Option[User], missionProgress: ValidationMissionProgress, currentLabelTypeId: Option[Int], adminParams: AdminValidateParams): Option[Int] = {
val userId: UUID = user.get.userId
if (missionProgress.completed) {
val labelsToRetrieve: Int = MissionTable.validationMissionLabelsToRetrieve
val possibleLabelTypeIds: List[Int] = LabelTable.retrievePossibleLabelTypeIds(userId, labelsToRetrieve, currentLabelTypeId)
.filter(labTypeId => adminParams.labelTypeId.isEmpty || adminParams.labelTypeId.get == labTypeId)
val hasNextMission: Boolean = possibleLabelTypeIds.nonEmpty

if (hasNextMission) {
// possibleLabTypeIds can contain [1, 2, 3, 4, 7, 9, 10]. Select 1, 2, 3, 4, 9, 10 if possible, o/w choose 7.
val possibleIds: List[Int] =
if (possibleLabelTypeIds.size > 1) possibleLabelTypeIds.filter(_ != 7)
else possibleLabelTypeIds
val index: Int = if (possibleIds.size > 1) scala.util.Random.nextInt(possibleIds.size - 1) else 0
return Some(possibleIds(index))
}
}
None
}

/**
* Gets a list of new labels to validate if the mission is complete.
*
Expand Down
Loading

0 comments on commit 01006cb

Please sign in to comment.