diff options
author | prathamesh | 2018-02-08 14:29:38 +0530 |
---|---|---|
committer | adityacp | 2018-03-21 17:32:41 +0530 |
commit | b3f5721f3cf4225902000f2f76e5138135383792 (patch) | |
tree | 21ab4b9c9d4ad5d900c1de15f7254faea689094b /grades/models.py | |
parent | 06abd01fd28eb10aafd18dd60b790549e0233edc (diff) | |
download | online_test-b3f5721f3cf4225902000f2f76e5138135383792.tar.gz online_test-b3f5721f3cf4225902000f2f76e5138135383792.tar.bz2 online_test-b3f5721f3cf4225902000f2f76e5138135383792.zip |
Add weightage for Quiz and Create Grading System App
App Name: grades
Grading System provides with the grade for a given value.
It contains different grade ranges.
Has its own default grading system.
Allows you to modify and add grading system wth grade ranges.
To be done:
- Need to add README
- Good UI
- There are fields like can_be_used and order in models for future use.
- More tests
App name: Yaksh
Now every quiz has a default weightage of 100%, can be changed.
An aggregate is calculated for a given course.
Using grades app a grade is provide to the aggregate value.
Diffstat (limited to 'grades/models.py')
-rw-r--r-- | grades/models.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/grades/models.py b/grades/models.py new file mode 100644 index 0000000..33895bb --- /dev/null +++ b/grades/models.py @@ -0,0 +1,49 @@ +from django.db import models +from django.contrib.auth.models import User + +# Create your models here. + +class GradingSystem(models.Model): + name = models.CharField(max_length=255, unique=True) + description = models.TextField(default='About the grading system!') + can_be_used = models.BooleanField(default=False) + creator = models.ForeignKey(User, null=True, blank=True) + + def get_grade(self, marks): + ranges = self.graderange_set.all() + lower_limits = ranges.values_list('lower_limit', flat=True) + upper_limits = ranges.values_list('upper_limit', flat=True) + lower_limit = self._get_lower_limit(marks, lower_limits) + upper_limit = self._get_upper_limit(marks, upper_limits) + grade_range = ranges.filter(lower_limit=lower_limit, + upper_limit=upper_limit).first() + if grade_range: + return grade_range.grade + + def _get_upper_limit(self, marks, upper_limits): + greater_than = [upper_limit for upper_limit in upper_limits + if upper_limit > marks] + if greater_than: + return min(greater_than, key=lambda x: x-marks) + + def _get_lower_limit(self, marks, lower_limits): + less_than = [] + for lower_limit in lower_limits: + if lower_limit == marks: + return lower_limit + if lower_limit < marks: + less_than.append(lower_limit) + if less_than: + return max(less_than, key=lambda x: x-marks) + + def __str__(self): + return self.name.title() + + +class GradeRange(models.Model): + system = models.ForeignKey(GradingSystem) + order = models.IntegerField(default=0) + lower_limit = models.FloatField() + upper_limit = models.FloatField() + grade = models.CharField(max_length=10) + description = models.CharField(max_length=127, null=True, blank=True) |