Skip to content

Commit

Permalink
Pass selected task options into the condition evaluator
Browse files Browse the repository at this point in the history
  - Note, need to remove logs before finalizing.
  • Loading branch information
sufyanAbbasi committed Feb 23, 2024
1 parent 64eed95 commit 899a15e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.google.android.ground.model.task

import timber.log.Timber

/** The task ID. */
typealias TaskId = String
/** The selected option ID for each task. */
Expand Down Expand Up @@ -45,6 +47,7 @@ constructor(

/** Given the user's task selections, determine whether the condition is fulfilled. */
fun fulfilledBy(taskSelections: TaskSelections): Boolean {
Timber.v("taskSelections: %s", taskSelections)
return when (matchType) {
MatchType.MATCH_ANY -> expressions.any { it.fulfilledBy(taskSelections) }
MatchType.MATCH_ALL -> expressions.all { it.fulfilledBy(taskSelections) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ internal object TaskConverter {
// Default index to -1 to degrade gracefully on older dev db instances and surveys.
val multipleChoice: MultipleChoice? =
if (type == Task.Type.MULTIPLE_CHOICE) toMultipleChoice(em) else null
Timber.v("task condition: ", em.condition)
return Task(
id,
em.index ?: -1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.google.android.ground.coroutines.IoDispatcher
import com.google.android.ground.domain.usecases.submission.SubmitDataUseCase
import com.google.android.ground.model.Survey
import com.google.android.ground.model.job.Job
import com.google.android.ground.model.submission.MultipleChoiceResponse
import com.google.android.ground.model.submission.Value
import com.google.android.ground.model.submission.ValueDelta
import com.google.android.ground.model.task.Condition
Expand Down Expand Up @@ -206,6 +207,7 @@ class DataCollectionViewModel
tasks.subList(startIndex, tasks.size)
}.let { tasks ->
tasks.asSequence().filter {
Timber.v("condition: %s", it.condition)
it.condition == null || evaluateCondition(it.condition)
}
}
Expand Down Expand Up @@ -236,9 +238,15 @@ class DataCollectionViewModel
} == getTaskSequence().last().id

/** Evaluates the task condition against the current inputs. */
private fun evaluateCondition(condition: Condition): Boolean {
return true
}
private fun evaluateCondition(condition: Condition): Boolean = condition.fulfilledBy(
data.mapNotNull { (task, value) ->
if (value is MultipleChoiceResponse) {
task.id to value.selectedOptionIds.toSet()
} else {
null
}
}.toMap()
)

companion object {
private const val TASK_JOB_ID_KEY = "jobId"
Expand Down

0 comments on commit 899a15e

Please sign in to comment.