Skip to content

Commit

Permalink
First draft #467 and tested in synchronous setting
Browse files Browse the repository at this point in the history
  • Loading branch information
sauterl committed Jul 16, 2024
1 parent 966f9d3 commit 9059aeb
Show file tree
Hide file tree
Showing 29 changed files with 150 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ data class ApiEvaluationState(
val taskId: String?,
val taskStatus: ApiTaskStatus,
val taskTemplateId: String?,
val timeLeft: Long,
val timeLeft: Long?,
val timeElapsed: Long
) {
constructor(run: InteractiveRunManager, context: RunActionContext) : this(
Expand All @@ -27,7 +27,7 @@ data class ApiEvaluationState(
run.currentTask(context)?.taskId,
run.currentTask(context)?.status ?: ApiTaskStatus.NO_TASK,
run.currentTaskTemplate(context).templateId,
run.timeLeft(context) / 1000,
run.timeLeft(context)?.div(1000),
run.timeElapsed(context) / 1000
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import dev.dres.data.model.template.task.options.DbScoreOption
* @version 1.1.0
*/
enum class ApiScoreOption {
KIS, AVS, LEGACY_AVS;
KIS, AVS, LEGACY_AVS, NOOP;

/**
* Converts this [ApiScoreOption] to a [DbScoreOption] representation. Requires an ongoing transaction.
Expand All @@ -21,5 +21,6 @@ enum class ApiScoreOption {
KIS -> DbScoreOption.KIS
AVS -> DbScoreOption.AVS
LEGACY_AVS -> DbScoreOption.LEGACY_AVS
NOOP -> DbScoreOption.NOOP
}
}
12 changes: 9 additions & 3 deletions backend/src/main/kotlin/dev/dres/mgmt/TemplateManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,15 @@ object TemplateManager {

/* Update task type information. */
val taskTypes = apiEvaluationTemplate.taskTypes.map { it.name }.toTypedArray()
dbEvaluationTemplate.taskTypes.removeAll(
DbTaskType.query(DbTaskType::evaluation eq dbEvaluationTemplate and not(DbTaskType::name.containsIn(*taskTypes)))
)
val taskTypesToDeleteQuery = DbTaskType.query(DbTaskType::evaluation eq dbEvaluationTemplate and not(DbTaskType::name.containsIn(*taskTypes)))
/* Manual cleanup, as removeAll does not cleanup related children. */
val configuredOptionsToDelIds= taskTypesToDeleteQuery.toList().map {
it.configurations.toList().map{opt -> opt.entityId}
}.flatten().toTypedArray()
DbConfiguredOption.all().toList().filter{configuredOptionsToDelIds.contains(it.entityId)}.forEach{it.delete()}

dbEvaluationTemplate.taskTypes.removeAll(taskTypesToDeleteQuery)

for (apiTaskType in apiEvaluationTemplate.taskTypes) {
val taskType =
DbTaskType.findOrNew(DbTaskType.query((DbTaskType::name eq apiTaskType.name) and (DbTaskType::evaluation eq dbEvaluationTemplate))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,22 +371,25 @@ class InteractiveAsynchronousRunManager(
/**
* Returns the time in milliseconds that is left until the end of the currently running task for the given team.
* Only works if the [InteractiveAsynchronousRunManager] is in state [RunManagerStatus.ACTIVE].
* If no task is running or is running perpetually, this method returns -1L.
* If no task is running, this method returns -1L.
* If the task runs perpetually, this method returns NULL.
*
* @param context The [RunActionContext] used for the invocation.
* @return Time remaining until the task will end or -1, if no task is running.
* @return Time remaining until the task will end or -1, if no task is running. NULL if the task runs perpetually.
*/
override fun timeLeft(context: RunActionContext): Long = this.stateLock.read {

override fun timeLeft(context: RunActionContext): Long? = this.stateLock.read {
val currentTaskRun = this.currentTask(context)

return if (currentTaskRun?.isRunning == true && currentTaskRun.duration != null) { // TODO what is the semantic of a perpetual IA task?
max(
0L,
currentTaskRun.duration!! * 1000L - (System.currentTimeMillis() - currentTaskRun.started!!) + InteractiveRunManager.COUNTDOWN_DURATION
)
return if (currentTaskRun?.duration == null) {
null
} else {
-1L
if (currentTaskRun.isRunning) {
max(
0L,
currentTaskRun.duration!! * 1000L - (System.currentTimeMillis() - currentTaskRun.started!!) + InteractiveRunManager.COUNTDOWN_DURATION
)
} else {
-1L
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions backend/src/main/kotlin/dev/dres/run/InteractiveRunManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ interface InteractiveRunManager : RunManager {
* this method returns -1L.
*
* @param context The [RunActionContext] used for the invocation.
* @return Time remaining until the task will end or -1, if no task is running.
* @return Time remaining until the task will end or -1, if no task is running. Null if the task runs perpetually.
*/
fun timeLeft(context: RunActionContext): Long
fun timeLeft(context: RunActionContext): Long?

/**
* Returns the time in milliseconds that has elapsed since the start of the currently running task.
Expand Down Expand Up @@ -178,4 +178,4 @@ interface InteractiveRunManager : RunManager {
* @return true on success, false otherwise
*/
fun overrideReadyState(context: RunActionContext, viewerId: String): Boolean
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@ class InteractiveSynchronousRunManager(
/* End ongoing tasks upon initialization (in case server crashed during task execution). */
for (task in this.evaluation.taskRuns) {
if (task.isRunning || task.status == ApiTaskStatus.RUNNING) {
task.end()
/* We exclude perpetual tasks here */
if(task.duration != null){
task.end()
}
}
}

Expand Down Expand Up @@ -367,12 +370,15 @@ class InteractiveSynchronousRunManager(
/**
* Returns the time in milliseconds that is left until the end of the current [DbTask].
* Only works if the [RunManager] is in right [RunManagerStatus]. If no task is running,
* OR a perpetual task is running, this method returns -1L.
* this method returns -1L. If the task is to run perpetually, NULL is returned.
*
* @return Time remaining until the task will end or -1, if no task is running.
* @return Time remaining until the task will end or -1, if no task is running. NULL if the task runs perpetually.
*/
override fun timeLeft(context: RunActionContext): Long {
return if (this.evaluation.currentTaskRun?.status == ApiTaskStatus.RUNNING && this.evaluation.currentTaskRun?.duration != null) {
override fun timeLeft(context: RunActionContext): Long? {
return if(this.evaluation.currentTaskRun?.duration == null){
null
}else{
if (this.evaluation.currentTaskRun?.status == ApiTaskStatus.RUNNING) {
val currentTaskRun = this.currentTask(context)
?: throw IllegalStateException("SynchronizedRunManager is in status ${this.status} but has no active TaskRun. This is a serious error!")
max(
Expand All @@ -381,7 +387,7 @@ class InteractiveSynchronousRunManager(
)
} else {
-1L
}
}}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,20 @@ class EndOnSubmitUpdatable(private val manager: InteractiveRunManager) : Updatab
val limit = taskType.configuration["LIMIT_CORRECT_PER_TEAM"]?.toIntOrNull() ?: 1

/* Count number of correct submissions per team. */
if (this.manager.timeLeft(context) > 0) {
for (s in submissions) {
for (a in s.answerSets.toList()) {
if (a.status == DbVerdictStatus.CORRECT) {
teams[s.team.id] = teams[s.team.id]!! + 1
if (currentTask.duration != null) {
if (this.manager.timeLeft(context)!! > 0) {
for (s in submissions) {
for (a in s.answerSets.toList()) {
if (a.status == DbVerdictStatus.CORRECT) {
teams[s.team.id] = teams[s.team.id]!! + 1
}
}
}
}

/* If all teams have reached the limit, end the task. */
if (teams.all { it.value >= limit }) {
this.manager.abortTask(context)
/* If all teams have reached the limit, end the task. */
if (teams.all { it.value >= limit }) {
this.manager.abortTask(context)
}
}
}
}
Expand All @@ -74,4 +76,4 @@ class EndOnSubmitUpdatable(private val manager: InteractiveRunManager) : Updatab
*/
override fun shouldBeUpdated(runStatus: RunManagerStatus, taskStatus: ApiTaskStatus?): Boolean =
(runStatus == RunManagerStatus.ACTIVE && taskStatus == ApiTaskStatus.RUNNING)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class ProlongOnSubmitUpdatable(private val manager: InteractiveRunManager): Upda
override fun update(runStatus: RunManagerStatus, taskStatus: ApiTaskStatus?, context: RunActionContext) {
if (runStatus == RunManagerStatus.ACTIVE && taskStatus == ApiTaskStatus.RUNNING) {
val currentTask = this.manager.currentTask(context) ?: return
/* This is only sensible to do, if the task has a duration */
if(currentTask.duration == null){
return
}
val taskType = this.manager.template.taskTypes.firstOrNull { it.name == currentTask.template.taskType }!!
val prolongOnSubmit = taskType.taskOptions.contains(ApiTaskOption.PROLONG_ON_SUBMISSION)
if (prolongOnSubmit) {
Expand All @@ -47,7 +51,7 @@ class ProlongOnSubmitUpdatable(private val manager: InteractiveRunManager): Upda
if (lastSubmission == null || (correctOnly && lastSubmission.answerSets.asSequence().all { it.status != DbVerdictStatus.CORRECT })) {
return
}
val timeLeft = Math.floorDiv(this.manager.timeLeft(context), 1000)
val timeLeft = Math.floorDiv(this.manager.timeLeft(context)!!, 1000)
if (timeLeft in 0 until limit) {
this.manager.adjustDuration(context, prolongBy)
}
Expand All @@ -64,4 +68,4 @@ class ProlongOnSubmitUpdatable(private val manager: InteractiveRunManager): Upda
*/
override fun shouldBeUpdated(runStatus: RunManagerStatus, taskStatus: ApiTaskStatus?): Boolean =
(runStatus == RunManagerStatus.ACTIVE && taskStatus == ApiTaskStatus.RUNNING)
}
}
18 changes: 9 additions & 9 deletions doc/oas-client.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"openapi" : "3.0.3",
"info" : {
"title" : "DRES Client API",
"version" : "2.0.4",
"description" : "Client API for DRES (Distributed Retrieval Evaluation Server), Version 2.0.4"
"version" : "2.0.5-SNAPSHOT",
"description" : "Client API for DRES (Distributed Retrieval Evaluation Server), Version 2.0.5-SNAPSHOT"
},
"paths" : {
"/api/v2/client/evaluation/currentTask/{evaluationId}" : {
Expand Down Expand Up @@ -1159,7 +1159,7 @@
"format" : "int64"
}
},
"required" : [ "name", "taskGroup", "taskType", "duration" ]
"required" : [ "name", "taskGroup", "taskType" ]
},
"ApiEvaluation" : {
"type" : "object",
Expand Down Expand Up @@ -1282,7 +1282,7 @@
"format" : "int64"
}
},
"required" : [ "evaluationId", "evaluationStatus", "taskStatus", "timeLeft", "timeElapsed" ]
"required" : [ "evaluationId", "evaluationStatus", "taskStatus", "timeElapsed" ]
},
"ApiEvaluationStatus" : {
"type" : "string",
Expand Down Expand Up @@ -1383,7 +1383,7 @@
"format" : "int64"
}
},
"required" : [ "id", "name", "type", "group", "duration", "taskId", "status" ]
"required" : [ "id", "name", "type", "group", "taskId", "status" ]
},
"ApiTaskStatus" : {
"type" : "string",
Expand Down Expand Up @@ -1413,7 +1413,7 @@
"format" : "int64"
}
},
"required" : [ "templateId", "name", "taskGroup", "taskType", "duration" ]
"required" : [ "templateId", "name", "taskGroup", "taskType" ]
},
"ApiTeamInfo" : {
"type" : "object",
Expand Down Expand Up @@ -2154,7 +2154,7 @@
"type" : "string"
}
},
"required" : [ "name", "taskGroup", "taskType", "duration", "collectionId", "targets", "hints" ]
"required" : [ "name", "taskGroup", "taskType", "collectionId", "targets", "hints" ]
},
"ApiTaskType" : {
"type" : "object",
Expand Down Expand Up @@ -2198,15 +2198,15 @@
}
}
},
"required" : [ "name", "duration", "targetOption", "hintOptions", "submissionOptions", "taskOptions", "scoreOption", "configuration" ]
"required" : [ "name", "targetOption", "hintOptions", "submissionOptions", "taskOptions", "scoreOption", "configuration" ]
},
"ApiHintOption" : {
"type" : "string",
"enum" : [ "IMAGE_ITEM", "VIDEO_ITEM_SEGMENT", "TEXT", "EXTERNAL_IMAGE", "EXTERNAL_VIDEO" ]
},
"ApiScoreOption" : {
"type" : "string",
"enum" : [ "KIS", "AVS", "LEGACY_AVS" ]
"enum" : [ "KIS", "AVS", "LEGACY_AVS", "NOOP" ]
},
"ApiSubmissionOption" : {
"type" : "string",
Expand Down
18 changes: 9 additions & 9 deletions doc/oas.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"openapi" : "3.0.3",
"info" : {
"title" : "DRES API",
"version" : "2.0.4",
"description" : "API for DRES (Distributed Retrieval Evaluation Server), Version 2.0.4",
"version" : "2.0.5-SNAPSHOT",
"description" : "API for DRES (Distributed Retrieval Evaluation Server), Version 2.0.5-SNAPSHOT",
"contact" : {
"name" : "The DRES Dev Team",
"url" : "https://dres.dev"
Expand Down Expand Up @@ -5573,7 +5573,7 @@
"format" : "int64"
}
},
"required" : [ "name", "taskGroup", "taskType", "duration" ]
"required" : [ "name", "taskGroup", "taskType" ]
},
"ApiEvaluation" : {
"type" : "object",
Expand Down Expand Up @@ -5696,7 +5696,7 @@
"format" : "int64"
}
},
"required" : [ "evaluationId", "evaluationStatus", "taskStatus", "timeLeft", "timeElapsed" ]
"required" : [ "evaluationId", "evaluationStatus", "taskStatus", "timeElapsed" ]
},
"ApiEvaluationStatus" : {
"type" : "string",
Expand Down Expand Up @@ -5797,7 +5797,7 @@
"format" : "int64"
}
},
"required" : [ "id", "name", "type", "group", "duration", "taskId", "status" ]
"required" : [ "id", "name", "type", "group", "taskId", "status" ]
},
"ApiTaskStatus" : {
"type" : "string",
Expand Down Expand Up @@ -5827,7 +5827,7 @@
"format" : "int64"
}
},
"required" : [ "templateId", "name", "taskGroup", "taskType", "duration" ]
"required" : [ "templateId", "name", "taskGroup", "taskType" ]
},
"ApiTeamInfo" : {
"type" : "object",
Expand Down Expand Up @@ -6568,7 +6568,7 @@
"type" : "string"
}
},
"required" : [ "name", "taskGroup", "taskType", "duration", "collectionId", "targets", "hints" ]
"required" : [ "name", "taskGroup", "taskType", "collectionId", "targets", "hints" ]
},
"ApiTaskType" : {
"type" : "object",
Expand Down Expand Up @@ -6612,15 +6612,15 @@
}
}
},
"required" : [ "name", "duration", "targetOption", "hintOptions", "submissionOptions", "taskOptions", "scoreOption", "configuration" ]
"required" : [ "name", "targetOption", "hintOptions", "submissionOptions", "taskOptions", "scoreOption", "configuration" ]
},
"ApiHintOption" : {
"type" : "string",
"enum" : [ "IMAGE_ITEM", "VIDEO_ITEM_SEGMENT", "TEXT", "EXTERNAL_IMAGE", "EXTERNAL_VIDEO" ]
},
"ApiScoreOption" : {
"type" : "string",
"enum" : [ "KIS", "AVS", "LEGACY_AVS" ]
"enum" : [ "KIS", "AVS", "LEGACY_AVS", "NOOP" ]
},
"ApiSubmissionOption" : {
"type" : "string",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Component, Inject, OnInit } from '@angular/core';
import { CompetitionFormBuilder } from '../competition-form.builder';
import { TaskTemplateFormBuilder } from '../../../../template/template-builder/task-template-form.builder';
import { AppConfig } from '../../../../app.config';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { VideoPlayerSegmentBuilderData } from '../video-player-segment-builder/video-player-segment-builder.component';

export class AdvancedBuilderDialogData {
builder: CompetitionFormBuilder;
builder: TaskTemplateFormBuilder;
}

// TODO rewrite
Expand Down
Loading

0 comments on commit 9059aeb

Please sign in to comment.