From 3bf71a2df6fcf35108c48e294af0eefb7deb9aa1 Mon Sep 17 00:00:00 2001 From: scmmishra Date: Mon, 22 Oct 2018 12:30:59 +0530 Subject: [PATCH] Quiz Logic --- erpnext/education/doctype/quiz/quiz.py | 5 ++--- erpnext/education/doctype/quiz_result/quiz_result.json | 6 +++--- erpnext/education/utils.py | 4 ++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/erpnext/education/doctype/quiz/quiz.py b/erpnext/education/doctype/quiz/quiz.py index 4bb6a7895a..7b5da9378d 100644 --- a/erpnext/education/doctype/quiz/quiz.py +++ b/erpnext/education/doctype/quiz/quiz.py @@ -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): diff --git a/erpnext/education/doctype/quiz_result/quiz_result.json b/erpnext/education/doctype/quiz_result/quiz_result.json index 7b32694871..4451aaf512 100644 --- a/erpnext/education/doctype/quiz_result/quiz_result.json +++ b/erpnext/education/doctype/quiz_result/quiz_result.json @@ -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": "", diff --git a/erpnext/education/utils.py b/erpnext/education/utils.py index a3763c19ab..d0bf9075fd 100644 --- a/erpnext/education/utils.py +++ b/erpnext/education/utils.py @@ -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))