summaryrefslogtreecommitdiff
path: root/yaksh/models.py
diff options
context:
space:
mode:
authorPrabhu Ramachandran2018-01-15 12:23:52 +0530
committerGitHub2018-01-15 12:23:52 +0530
commit1445358b4ee548edd16a8d42026b080b7d92a0c4 (patch)
tree99b437d71f841cb1ac9f26266d7e7de04031f340 /yaksh/models.py
parent3abbc557c57eaf2f3d08222034f9a720a1e7a1ed (diff)
parentef22478a11d518982f38a6a0d4d84f6f8ba5e492 (diff)
downloadonline_test-1445358b4ee548edd16a8d42026b080b7d92a0c4.tar.gz
online_test-1445358b4ee548edd16a8d42026b080b7d92a0c4.tar.bz2
online_test-1445358b4ee548edd16a8d42026b080b7d92a0c4.zip
Merge pull request #422 from adityacp/show_course_status
Show course status
Diffstat (limited to 'yaksh/models.py')
-rw-r--r--yaksh/models.py36
1 files changed, 31 insertions, 5 deletions
diff --git a/yaksh/models.py b/yaksh/models.py
index d4a73fa..f0d1b2e 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -1,4 +1,4 @@
-from __future__ import unicode_literals
+from __future__ import unicode_literals, division
from datetime import datetime, timedelta
import json
import random
@@ -453,12 +453,16 @@ class LearningModule(models.Model):
ordered_units = learning_module.learning_unit.order_by("order")
status_list = [unit.get_completion_status(user, course)
for unit in ordered_units]
- if all([status == "completed" for status in status_list]):
- return "completed"
+
+ if not status_list:
+ default_status = "no units"
+ elif all([status == "completed" for status in status_list]):
+ default_status = "completed"
elif "inprogress" in status_list:
- return "inprogress"
+ default_status = "inprogress"
else:
- return "not attempted"
+ default_status = "not attempted"
+ return default_status
def is_prerequisite_passed(self, user, course):
""" Check if prerequisite module is completed """
@@ -481,6 +485,17 @@ class LearningModule(models.Model):
def has_prerequisite(self):
return self.check_prerequisite
+ def get_module_complete_percent(self, course, user):
+ units = self.get_learning_units()
+ if not units:
+ percent = 0.0
+ else:
+ status_list = [unit.get_completion_status(user, course)
+ for unit in units]
+ count = status_list.count("completed")
+ percent = round((count / len(units)) * 100)
+ return percent
+
def __str__(self):
return self.name
@@ -681,6 +696,17 @@ class Course(models.Model):
next_index = 0
return modules.get(id=module_ids[next_index])
+ def percent_completed(self, user):
+ modules = self.get_learning_modules()
+ if not modules:
+ percent = 0.0
+ else:
+ status_list = [module.get_module_complete_percent(self, user)
+ for module in modules]
+ count = sum(status_list)
+ percent = round((count / len(modules)))
+ return percent
+
def __str__(self):
return self.name