[WIP] refactoring/location-club-statistics #71
|
@ -54,24 +54,30 @@ class Place(models.Model):
|
|||
class GymnastStatistics():
|
||||
def __init__(self, gymnast):
|
||||
self.gymnast = gymnast
|
||||
self.number_of_courses_by_week = 0
|
||||
self.number_of_courses = 0
|
||||
self.number_of_hours_by_week = timedelta()
|
||||
self.number_of_trainings = 0
|
||||
self.number_of_attendance = 0
|
||||
self.number_of_absences = 0
|
||||
self.number_of_training_hours = 0
|
||||
self.number_of_attended_trainings = 0
|
||||
self.number_of_attendance_hours = timedelta()
|
||||
self.percentage_of_attendance = 0
|
||||
self.number_of_hours_of_absence = 0
|
||||
self.percentage_of_absence = 0
|
||||
|
||||
self.number_of_absences = 0
|
||||
self.number_of_attendance = 0
|
||||
|
||||
def add_course(self, course):
|
||||
"""Ajoute le fait que ce gymnaste a assisté à un cours"""
|
||||
self.number_of_trainings += 1
|
||||
self.number_of_training_hours += course.number_of
|
||||
self.number_of_courses += 1
|
||||
|
||||
def percentage_of_absence(self):
|
||||
return int(self.number_of_hours_of_absence / self.number_of_training_hours) * 100
|
||||
self.number_of_attended_trainings += self.gymnast.attendances(course).count()
|
||||
self.total_number_of_trainings += course.total_number_of_trainings
|
||||
|
||||
self.number_of_attendance_hours += self.gymnast.attendances(course).count() * course.duration
|
||||
self.number_of_total_hours += course.number_of_total_hours
|
||||
|
||||
def percentage_of_attended_hours(self):
|
||||
return int(self.number_of_attendance_hours / self.number_of_total_hours) * 100
|
||||
|
||||
def percentage_of_attended_trainings(self):
|
||||
return int(self.number_of_attended_trainings / self.total_number_of_trainings) * 100
|
||||
|
||||
|
||||
class Club(models.Model):
|
||||
|
@ -145,8 +151,14 @@ class Club(models.Model):
|
|||
|
||||
courses = self.courses.filter(season=season)
|
||||
|
||||
all_gymnasts = {}
|
||||
|
||||
|
||||
|
||||
return {
|
||||
"gymnasts": all_gymnasts,
|
||||
"courses": courses,
|
||||
"number_of_trainings": sum([x.number_of_trainings for x in courses])
|
||||
"number_of_occured_courses": sum([x.get_number_of_real_occurrences for x in courses]),
|
||||
"total_hours": sum([x.total_number_of_hours for x in courses]),
|
||||
"total_hours_paid": sum([x.total_number_of_paid_hours for x in courses]),
|
||||
|
|
|
@ -320,14 +320,10 @@ def club_statistics(request, clubid):
|
|||
|
||||
# print(str(gymnast) + ' : ' + str(nbattendance) + ' for ' + str(course) )
|
||||
|
||||
gymnastsDict[gymnast.id]["nbcoursebyweek"] += 1
|
||||
gymnastsDict[gymnast.id]["nbhourbyweek"] += nbhour # timedelta
|
||||
gymnastsDict[gymnast.id]["nbtraining"] += counted
|
||||
gymnastsDict[gymnast.id]["nbattendance"] += nbattendance
|
||||
gymnastsDict[gymnast.id]["nbhourtraining"] += totalHourForCourse
|
||||
gymnastsDict[gymnast.id]["nbhourattendance"] += (
|
||||
nbhour * nbattendance
|
||||
) # timedelta
|
||||
|
||||
|
||||
# print(gymnastsDict[gymnast.id])
|
||||
|
||||
|
|
|
@ -346,6 +346,10 @@ class Course(Markdownizable, Temporizable):
|
|||
def get_number_of_planned_occurrences(self):
|
||||
return self.get_total_occurence()
|
||||
|
||||
@property
|
||||
def total_number_of_trainings(self):
|
||||
return Training.objects.filter(course=course).count()
|
||||
|
||||
@property
|
||||
def get_number_of_real_occurrences(self) -> int:
|
||||
"""Retourne le nombre de fois où le cours a réellement été donné.
|
||||
|
|
Loading…
Reference in New Issue