pedagogy: grade averages for UVs

This commit is contained in:
Antoine Bartuccio 2019-07-04 18:07:51 +02:00
parent 4f7a8661ba
commit 205f93569a
Signed by: klmp200
GPG Key ID: E7245548C53F904B
2 changed files with 33 additions and 0 deletions

View File

@ -51,6 +51,33 @@ class UV(models.Model):
""" """
return user.is_subscribed return user.is_subscribed
def __grade_average_generic(self, field):
comments = self.comments.filter(**{field + "__gte": 0})
if not comments.exists():
return -1
return int(sum(comments.values_list(field, flat=True)) / comments.count())
@cached_property
def grade_global_average(self):
return self.__grade_average_generic("grade_global")
@cached_property
def grade_utility_average(self):
return self.__grade_average_generic("grade_utility")
@cached_property
def grade_interest_average(self):
return self.__grade_average_generic("grade_interest")
@cached_property
def grade_teaching_average(self):
return self.__grade_average_generic("grade_teaching")
@cached_property
def grade_work_load_average(self):
return self.__grade_average_generic("grade_work_load")
def __str__(self): def __str__(self):
return self.code return self.code

View File

@ -14,6 +14,12 @@
<p>{{ object.key_concepts|markdown }}</p> <p>{{ object.key_concepts|markdown }}</p>
<p>{% trans %}UV manager: {% endtrans %}{{ object.manager }}</p> <p>{% trans %}UV manager: {% endtrans %}{{ object.manager }}</p>
<p>{{ object.grade_global_average }}</p>
<p>{{ object.grade_utility_average }}</p>
<p>{{ object.grade_interest_average }}</p>
<p>{{ object.grade_teaching_average }}</p>
<p>{{ object.grade_work_load_average }}</p>
{% if object.comments.exists() %} {% if object.comments.exists() %}
<h2>{% trans %}Comments{% endtrans %}</h2> <h2>{% trans %}Comments{% endtrans %}</h2>
{% for comment in object.comments.all() %} {% for comment in object.comments.all() %}