Quiz eval utils
diff --git a/erpnext/education/doctype/question/question.py b/erpnext/education/doctype/question/question.py
index 1608fdd..048a90b 100644
--- a/erpnext/education/doctype/question/question.py
+++ b/erpnext/education/doctype/question/question.py
@@ -7,4 +7,14 @@
from frappe.model.document import Document
class Question(Document):
- pass
+
+ def get_answer(self):
+ options = self.get_all_children()
+ answers = [item.option for item in options if item.is_correct == True]
+ if len(answers) == 0:
+ frappe.throw("No correct answer is set for {0}".format(self.name))
+ return None
+ elif len(answers) == 1:
+ return answers[0]
+ else:
+ return answers
\ No newline at end of file
diff --git a/erpnext/education/doctype/quiz/quiz.py b/erpnext/education/doctype/quiz/quiz.py
index 2ecc485..0c3dd30 100644
--- a/erpnext/education/doctype/quiz/quiz.py
+++ b/erpnext/education/doctype/quiz/quiz.py
@@ -13,8 +13,13 @@
pass
- def evaluate_quiz(self):
- pass
+ def evaluate(self, response_dict):
+ self.get_questions()
+ answers = {q.name:q.get_answer() for q in self.get_questions()}
+ print(response_dict)
+ print(type(response_dict))
+ print(answers)
+ print(type(answers))
def get_questions(self):
diff --git a/erpnext/education/utils.py b/erpnext/education/utils.py
index 6d9c8e2..ba54c90 100644
--- a/erpnext/education/utils.py
+++ b/erpnext/education/utils.py
@@ -72,19 +72,26 @@
"""
import json
quiz_response = json.loads(quiz_response)
- correct_answers = [frappe.get_value('Question', name, 'correct_options') for name in quiz_response.keys()]
- selected_options = quiz_response.values()
- result = [selected == correct for selected, correct in zip(selected_options, correct_answers)]
+ quiz_name = kwargs.get('quiz')
try:
- score = int((result.count(True)/len(selected_options))*100)
- except ZeroDivisionError:
- score = 0
+ quiz = frappe.get_doc("Quiz", quiz_name)
+ result = quiz.evaluate(quiz_response)
+ return "Hello"
+ except frappe.DoesNotExistError:
+ frappe.throw("Quiz {0} does not exist".format(quiz_name))
+ # correct_answers = [frappe.get_value('Question', name, 'correct_options') for name in quiz_response.keys()]
+ # selected_options = quiz_response.values()
+ # result = [selected == correct for selected, correct in zip(selected_options, correct_answers)]
+ # try:
+ # score = int((result.count(True)/len(selected_options))*100)
+ # except ZeroDivisionError:
+ # score = 0
- kwargs['selected_options'] = selected_options
- kwargs['result'] = result
- kwargs['score'] = score
- add_activity('Quiz', **kwargs)
- return score
+ # kwargs['selected_options'] = selected_options
+ # kwargs['result'] = result
+ # kwargs['score'] = score
+ # add_activity('Quiz', **kwargs)
+ # return score
@frappe.whitelist()
def add_activity(content_type, **kwargs):
diff --git a/erpnext/www/lms/course.js b/erpnext/www/lms/course.js
index a25d00e..d24c024 100644
--- a/erpnext/www/lms/course.js
+++ b/erpnext/www/lms/course.js
@@ -8,7 +8,7 @@
method: "erpnext.education.utils.evaluate_quiz",
args: {
"quiz_response": form_object,
- "content": $('#content-holder').data('content'),
+ "quiz": $('#content-holder').data('content'),
"course": $('#content-holder').data('course'),
"program": $('#content-holder').data('program')
},
diff --git a/erpnext/www/lms/course.py b/erpnext/www/lms/course.py
index 35c2879..76b873a 100644
--- a/erpnext/www/lms/course.py
+++ b/erpnext/www/lms/course.py
@@ -24,9 +24,6 @@
context.next_content_type, context.next_content = get_next_content(content_name, content_type, current_course.get_content_info())
if content_type == "Quiz":
context.questions = current_content.get_questions()
- print(content_type)
- print(current_content.title)
- print(context.questions)
def get_next_content(c_name, c_type, content_list):
try:
diff --git a/erpnext/www/lms/templates/includes/quiz.html b/erpnext/www/lms/templates/includes/quiz.html
index 83f598e..1c7c600 100644
--- a/erpnext/www/lms/templates/includes/quiz.html
+++ b/erpnext/www/lms/templates/includes/quiz.html
@@ -2,9 +2,6 @@
<div class="question mt-4" id="{{ question.question }}" data-question="{{ question.name }}">
<h5>{{ loop_index }}{{ question.question }}</h5>
<div class="options ml-2">
- <div class="form-check pb-1 hidden">
- <input class="form-check-input" type="radio" name="{{ question['id'] }}" value="0" checked>
- </div>
{% for option in question.options %}
<div class="form-check pb-1">
<input class="form-check-input" type="radio" name="{{ question.name }}" id="{{loop_index}}-{{ option.option }}" value="{{ option.option }}">