Skip to content

Commit

Permalink
Fixed inverted condition and removed unused validator
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaro committed Sep 17, 2023
1 parent d8411bc commit e92dcef
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 90 deletions.
2 changes: 1 addition & 1 deletion backend/src/main/kotlin/dev/dres/DRES.kt
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ object DRES {
TemplateManager.init(store)

/* Initialize RunExecutor. */
RunExecutor.init(CONFIG, store, global)
RunExecutor.init(store)

/* Initialize EventStreamProcessor */
EventStreamProcessor.register( /* Add handlers here */)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ package dev.dres.data.model.run
import dev.dres.data.model.template.task.DbTaskTemplate
import dev.dres.data.model.template.task.options.DbTargetOption
import dev.dres.data.model.submissions.DbSubmission
import dev.dres.run.validation.MediaItemsAnswerSetValidator
import dev.dres.run.validation.TemporalOverlapAnswerSetValidator
import dev.dres.run.validation.TextAnswerSetValidator
import dev.dres.run.validation.TransientMediaSegment
import dev.dres.run.validation.*
import dev.dres.run.validation.interfaces.AnswerSetValidator
import dev.dres.run.validation.judged.BasicJudgementValidator
import dev.dres.run.validation.judged.BasicVoteValidator
Expand Down Expand Up @@ -40,7 +37,7 @@ abstract class AbstractInteractiveTask(store: TransientEntityStore, task: DbTask
val target =
template.targets.filter { (it.item ne null) and (it.start ne null) and (it.end ne null) }
.asSequence().map { TransientMediaSegment(it.item!!, it.range!!) }.toSet()
TemporalOverlapAnswerSetValidator(target)
TemporalContainmentAnswerSetValidator(target)
}

DbTargetOption.TEXT -> TextAnswerSetValidator(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package dev.dres.data.model.run

import dev.dres.data.model.template.task.options.DbTargetOption
import dev.dres.run.validation.MediaItemsAnswerSetValidator
import dev.dres.run.validation.TemporalOverlapAnswerSetValidator
import dev.dres.run.validation.TextAnswerSetValidator
import dev.dres.run.validation.TransientMediaSegment
import dev.dres.run.validation.*
import dev.dres.run.validation.interfaces.AnswerSetValidator
import dev.dres.run.validation.judged.BasicJudgementValidator
import dev.dres.run.validation.judged.ItemRange
Expand Down Expand Up @@ -33,7 +30,7 @@ abstract class AbstractNonInteractiveTask(store: TransientEntityStore, task: DbT
val target =
template.targets.filter { (it.item ne null) and (it.start ne null) and (it.end ne null) }
.asSequence().map { TransientMediaSegment(it.item!!, it.range!!) }.toSet()
TemporalOverlapAnswerSetValidator(target)
TemporalContainmentAnswerSetValidator(target)
}

DbTargetOption.TEXT -> TextAnswerSetValidator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ class InteractiveSynchronousEvaluation(store: TransientEntityStore, evaluation:

init {

check(this@InteractiveSynchronousEvaluation.taskRuns.isEmpty() || this@InteractiveSynchronousEvaluation.taskRuns.last().hasEnded) {
check(this@InteractiveSynchronousEvaluation.taskRuns.isEmpty() || this@InteractiveSynchronousEvaluation.taskRuns.last().hasEnded) { //FIXME causes issues when resuming evaluation
"Cannot create a new task. Another task is currently running."
}
(this@InteractiveSynchronousEvaluation.taskRuns).add(this)
this@InteractiveSynchronousEvaluation.taskRuns.add(this)

/* Initialize submission filter. */
this.filter = store.transactional {
Expand Down
13 changes: 8 additions & 5 deletions backend/src/main/kotlin/dev/dres/run/RunExecutor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,17 @@ object RunExecutor {

/** Initializes the [RunExecutor] singleton.
*
* @param config The [Config] with which DRES was started.
* @param store The [TransientEntityStore] instance used to access persistent data.
* @param cache The [CacheManager] instance used to access the media cache.
*/
fun init(config: Config, store: TransientEntityStore, cache: CacheManager) {
fun init(store: TransientEntityStore) {
store.transactional {
DbEvaluation.filter { (it.ended eq null) }.asSequence().forEach {e ->
this.schedule(e.toRunManager(store)) /* Re-schedule evaluations. */
DbEvaluation.filter { (it.ended eq null) }.asSequence().forEach {evaluation ->
try {
this.schedule(evaluation.toRunManager(store)) /* Re-schedule evaluations. */
} catch (e: IllegalStateException) {
logger.error("Could not re-schedule previous run: ${e.message}")
evaluation.ended = System.currentTimeMillis()
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
package dev.dres.run.validation

import dev.dres.data.model.media.MediaItem
import dev.dres.data.model.media.time.TemporalRange
import dev.dres.data.model.submissions.*
import dev.dres.run.validation.interfaces.AnswerSetValidator
import kotlinx.dnq.query.FilteringContext.isEmpty
import kotlinx.dnq.query.asSequence
import kotlinx.dnq.query.iterator
import kotlinx.dnq.query.size

typealias TransientMediaSegment = Pair<MediaItem, TemporalRange>

/**
* A [AnswerSetValidator] class that checks, if a submission is correct based on the target segment and the
Expand All @@ -27,20 +34,21 @@ class TemporalContainmentAnswerSetValidator(private val targetSegments: Collecti
*/
override fun validate(answerSet: DbAnswerSet) {

/* Basically, we assume that the DBAnswerSet is wrong. */
answerSet.status = DbVerdictStatus.WRONG
/* If there are answers, there could be a correct one */
var correct = answerSet.answers.size() > 0

/* Now we check all the answers. */
/* Now we check all the answers. If an incorrect one is found, we break */
for (answer in answerSet.answers) {
/* Perform sanity checks. */
val item = answer.item
val start = answer.start
val end = answer.end
if (answer.type != DbAnswerType.TEMPORAL || item == null || start == null || end == null || start > end) {
return
correct = false
break
}

if (targetSegments.any { targetSegment ->
if (!targetSegments.any { targetSegment ->
/* Perform item validation. */
if (item.mediaItemId != targetSegment.first.mediaItemId) {
return@any false
Expand All @@ -50,11 +58,16 @@ class TemporalContainmentAnswerSetValidator(private val targetSegments: Collecti
val outer = targetSegment.second.toMilliseconds()
!(outer.first > start || outer.second < end)
}) {
return
correct = false
break
}
}

/* If code reaches this point, the [DbAnswerSet] is correct. */
answerSet.status = DbVerdictStatus.CORRECT

answerSet.status = if (correct) {
DbVerdictStatus.CORRECT
} else {
DbVerdictStatus.WRONG
}
}
}

This file was deleted.

0 comments on commit e92dcef

Please sign in to comment.