Quiz Logic

This commit is contained in:
scmmishra 2018-10-22 12:30:59 +05:30 committed by Aditya Hase
parent d133e8229b
commit 3bf71a2df6
3 changed files with 7 additions and 8 deletions

View File

@ -16,9 +16,8 @@ class Quiz(Document):
def evaluate(self, response_dict):
self.get_questions()
answers = {q.name:q.get_answer() for q in self.get_questions()}
correct_answers = [{'question':question,'selected_option':response_dict[question],'result':(answers[question] == response_dict[question])} for question in response_dict.keys()]
print(correct_answers)
return correct_answers, (sum(answer['result'] for answer in correct_answers) * 100 ) / len(answers)
correct_answers = [answers[question] == response_dict[question] for question in response_dict.keys()]
return (sum(correct_answers) * 100 ) / len(answers)
def get_questions(self):

View File

@ -86,7 +86,7 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "correct_option",
"fieldname": "result",
"fieldtype": "Select",
"hidden": 0,
"ignore_user_permissions": 0,
@ -123,8 +123,8 @@
"issingle": 0,
"istable": 1,
"max_attachments": 0,
"modified": "2018-10-15 16:17:35.779634",
"modified_by": "Administrator",
"modified": "2018-10-22 12:28:07.597474",
"modified_by": "jess@education.com",
"module": "Education",
"name": "Quiz Result",
"name_case": "",

View File

@ -66,8 +66,8 @@ def evaluate_quiz(quiz_response, **kwargs):
course_name = kwargs.get('course')
try:
quiz = frappe.get_doc("Quiz", quiz_name)
result, score = quiz.evaluate(quiz_response)
add_quiz_activity(course_name, quiz_name, result, score)
score = quiz.evaluate(quiz_response)
# add_quiz_activity(course_name, quiz_name, result, score)
return score
except frappe.DoesNotExistError:
frappe.throw("Quiz {0} does not exist".format(quiz_name))