quiz_activity: add quiz activity

Signed-off-by: Chinmay Pai <chinmaydpai@gmail.com>
diff --git a/erpnext/education/doctype/quiz/quiz.py b/erpnext/education/doctype/quiz/quiz.py
index 7b5da93..a7e5541 100644
--- a/erpnext/education/doctype/quiz/quiz.py
+++ b/erpnext/education/doctype/quiz/quiz.py
@@ -16,8 +16,8 @@
 	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):
diff --git a/erpnext/education/doctype/quiz_result/quiz_result.json b/erpnext/education/doctype/quiz_result/quiz_result.json
index 4451aaf..cb5ba1b 100644
--- a/erpnext/education/doctype/quiz_result/quiz_result.json
+++ b/erpnext/education/doctype/quiz_result/quiz_result.json
@@ -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": "", 
diff --git a/erpnext/education/utils.py b/erpnext/education/utils.py
index d0bf907..b0bf50e 100644
--- a/erpnext/education/utils.py
+++ b/erpnext/education/utils.py
@@ -66,28 +66,32 @@
 	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()