Skip to content

Commit

Permalink
Hotfix 1.0.2 🔧 Fix recommended exam (#221)
Browse files Browse the repository at this point in the history
* Check for len of correct questions

* Bump version
  • Loading branch information
JeronimoMendes authored May 30, 2022
1 parent 2610cb7 commit 19d7dc8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions backend/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,13 +348,13 @@ def post(self, request):
questions_wrong_id = [i.id for i in questions_wrong]
questions_correct_id = [i.id for i in questions_correct]
questions_unanswered = list(Question.objects.exclude(id__in=questions_correct_id).exclude(id__in=questions_wrong_id).filter(accepted=True))

# Only insert a certain amount of unasnwered questions in the exam
if len(questions_unanswered) > MAX_UNANSWERED_QUESTIONS_RECOMMENDED:
questions_unanswered_selected = random.sample(questions_unanswered, MAX_UNANSWERED_QUESTIONS_RECOMMENDED)
else: questions_unanswered_selected = questions_unanswered

questions_unanswered = random.sample(questions_unanswered, MAX_UNANSWERED_QUESTIONS_RECOMMENDED)

questions = questions_unanswered
questions = questions_unanswered_selected

# Check if there are enough wrong answers to fill the exam, if not insert correct answers
space_left = QUESTION_PER_EXAM - len(questions)
Expand All @@ -370,7 +370,12 @@ def post(self, request):
# There are not enough wrong and unanswered questions so when need to get some right answers
space_left = QUESTION_PER_EXAM - len(questions)

questions_right_selected = random.sample(questions_correct, space_left)
if len(questions_correct) < space_left:
questions_right_selected = questions_correct
questions += random.sample(set(questions_unanswered) - set(questions_unanswered_selected), space_left - len(questions_correct))
else:
questions_right_selected = random.sample(questions_correct, space_left)

questions += questions_right_selected

if len(questions) < 10:
Expand Down
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "frontend",
"version": "1.0.1",
"version": "1.0.2",
"private": true,
"scripts": {
"start": "react-scripts start",
Expand Down

0 comments on commit 19d7dc8

Please sign in to comment.