get_test_info
This commit is contained in:
1 parent
7eae7807b7
commit
734b37e038
1 file changed
+8
-2
@@ -517,6 +517,10 @@ class TestResultView(generics.ListCreateAPIView):
|
||||
test_answers = TestAnswer.objects.filter(id__in=answer_ids)
|
||||
test = Test.objects.get(id=test_id)
|
||||
answered_questions_total = test_answers.values('question').distinct().count()
|
||||
q_count = test.question_count
|
||||
all_questions = len(TestQuestion.objects.filter(test=test))
|
||||
if all_questions <= q_count:
|
||||
q_count = all_questions
|
||||
|
||||
correct_questions = sum(
|
||||
TestAnswer.objects.filter(
|
||||
@@ -531,8 +535,10 @@ class TestResultView(generics.ListCreateAPIView):
|
||||
|
||||
pass_perc = test.pass_perc
|
||||
correct_answers_perc = 0
|
||||
if answered_questions_total !=0:
|
||||
correct_answers_perc = correct_questions/answered_questions_total*100
|
||||
if q_count !=0:
|
||||
correct_answers_perc = correct_questions/q_count*100
|
||||
# if answered_questions_total !=0:
|
||||
# correct_answers_perc = correct_questions/answered_questions_total*100
|
||||
result = {
|
||||
"is_passed": correct_answers_perc >= pass_perc,
|
||||
"score": correct_questions,
|
||||
|
||||
Reference in new issue
Block a user