From 19d7dc8fcab4e3a8357063b965e430155336467d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jer=C3=B3nimo=20Mendes?= <39437433+JeronimoMendes@users.noreply.github.com> Date: Mon, 30 May 2022 23:35:41 +0100 Subject: [PATCH] =?UTF-8?q?Hotfix=201.0.2=20=F0=9F=94=A7=20Fix=20recommend?= =?UTF-8?q?ed=20exam=20(#221)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Check for len of correct questions * Bump version --- backend/api/views.py | 15 ++++++++++----- frontend/package.json | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/backend/api/views.py b/backend/api/views.py index 049de8f6..94443876 100644 --- a/backend/api/views.py +++ b/backend/api/views.py @@ -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) @@ -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: diff --git a/frontend/package.json b/frontend/package.json index b24f9221..c6e636f3 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,6 +1,6 @@ { "name": "frontend", - "version": "1.0.1", + "version": "1.0.2", "private": true, "scripts": { "start": "react-scripts start",