Skip to content

Commit

Permalink
feat: add new condition (count of selected correct choices in the las…
Browse files Browse the repository at this point in the history
…t multi-choice submitted answer)
  • Loading branch information
AmooHashem committed Oct 26, 2024
1 parent 7205e9f commit 50f14fd
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion apps/attributes/models/intrinsic_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,31 @@ def is_true(self, *args, **kwargs):
player = kwargs.get('player')
value = self.value

if 'expected_correct_choices_in_last_answer_count' in value:
expected_count = value.get(
'expected_correct_choices_in_last_answer_count')

try:
# Get the last multi-choice answer in a single query
from apps.fsm.models.response import MultiChoiceAnswer
last_answer = (
player.answer_sheet.answers
.instance_of(MultiChoiceAnswer)
.prefetch_related('choices')
.latest('id')
)

# Count how many of the selected choices are marked as correct
correct_choices_count = sum(
1 for choice in last_answer.choices.all()
if choice.is_correct
)

return correct_choices_count == expected_count

except MultiChoiceAnswer.DoesNotExist:
return False

if 'completed_fsms' in value:
completed_fsm_ids = value.get('completed_fsms')
# Get distinct completed FSMs
Expand Down Expand Up @@ -79,4 +104,4 @@ class Cost(IntrinsicAttribute):


class Reward(IntrinsicAttribute):
pass
pass

0 comments on commit 50f14fd

Please sign in to comment.