quiz_activity: add quiz activity
Signed-off-by: Chinmay Pai <chinmaydpai@gmail.com>
This commit is contained in:
parent
3bf71a2df6
commit
3574ac3f5e
@ -16,8 +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 = [answers[question] == response_dict[question] for question in response_dict.keys()]
|
||||
return (sum(correct_answers) * 100 ) / len(answers)
|
||||
correct_answers = {question: (answers[question] == response_dict[question]) for question in response_dict.keys()}
|
||||
return correct_answers, (sum(correct_answers.values()) * 100 ) / len(answers)
|
||||
|
||||
|
||||
def get_questions(self):
|
||||
|
@ -123,8 +123,8 @@
|
||||
"issingle": 0,
|
||||
"istable": 1,
|
||||
"max_attachments": 0,
|
||||
"modified": "2018-10-22 12:28:07.597474",
|
||||
"modified_by": "jess@education.com",
|
||||
"modified": "2018-10-22 03:38:29.007162",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Education",
|
||||
"name": "Quiz Result",
|
||||
"name_case": "",
|
||||
|
@ -66,28 +66,32 @@ def evaluate_quiz(quiz_response, **kwargs):
|
||||
course_name = kwargs.get('course')
|
||||
try:
|
||||
quiz = frappe.get_doc("Quiz", quiz_name)
|
||||
score = quiz.evaluate(quiz_response)
|
||||
# add_quiz_activity(course_name, quiz_name, result, score)
|
||||
answers, score = quiz.evaluate(quiz_response)
|
||||
add_quiz_activity(course_name, quiz_name, score, answers, quiz_response)
|
||||
return score
|
||||
except frappe.DoesNotExistError:
|
||||
frappe.throw("Quiz {0} does not exist".format(quiz_name))
|
||||
return None
|
||||
|
||||
|
||||
def add_quiz_activity(course, quiz, result, score):
|
||||
def add_quiz_activity(course, quiz, score, answers, quiz_response):
|
||||
print(course, quiz, result, score)
|
||||
enrollment = get_course_enrollment(course, frappe.session.user)
|
||||
answer_list = list(answers.values())
|
||||
if not enrollment:
|
||||
enrollment = add_course_enrollment(course, frappe.session.user)
|
||||
frappe.throw("The user is not enrolled for the course {course}".format(course=course))
|
||||
activity = frappe.get_doc({
|
||||
"doctype": "Quiz Activity",
|
||||
"enrollment": enrollment.name,
|
||||
"quiz": quiz,
|
||||
"score": score,
|
||||
# "date": frappe.getdate(),
|
||||
"date": frappe.getdate()
|
||||
})
|
||||
for response in result:
|
||||
activity.append("result", response)
|
||||
for i in len(quiz_response):
|
||||
activity.append("result",
|
||||
{
|
||||
"selected_option": quiz_response[i],
|
||||
"result": answer_list[i]})
|
||||
activity.save()
|
||||
frappe.db.commit()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user