This commit is contained in:
Denis Voinovich committed 2025-06-26 07:51:32 +03:00
commit 0d0db01b29
1 file changed
+8 -2
+8 -2
View File
@@ -517,6 +517,10 @@ class TestResultView(generics.ListCreateAPIView):
test_answers = TestAnswer.objects.filter(id__in=answer_ids) test_answers = TestAnswer.objects.filter(id__in=answer_ids)
test = Test.objects.get(id=test_id) test = Test.objects.get(id=test_id)
answered_questions_total = test_answers.values('question').distinct().count() 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( correct_questions = sum(
TestAnswer.objects.filter( TestAnswer.objects.filter(
@@ -531,8 +535,10 @@ class TestResultView(generics.ListCreateAPIView):
pass_perc = test.pass_perc pass_perc = test.pass_perc
correct_answers_perc = 0 correct_answers_perc = 0
if answered_questions_total !=0: if q_count !=0:
correct_answers_perc = correct_questions/answered_questions_total*100 correct_answers_perc = correct_questions/q_count*100
# if answered_questions_total !=0:
# correct_answers_perc = correct_questions/answered_questions_total*100
result = { result = {
"is_passed": correct_answers_perc >= pass_perc, "is_passed": correct_answers_perc >= pass_perc,
"score": correct_questions, "score": correct_questions,