[WIP] refactoring/location-club-statistics #71
|
@ -146,5 +146,8 @@ class Club(models.Model):
|
||||||
courses = self.courses.filter(season=season)
|
courses = self.courses.filter(season=season)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"total_hours_paid": sum[x.total_number_of_paid_hours for x in courses]
|
"courses": 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]),
|
||||||
}
|
}
|
||||||
|
|
|
@ -285,8 +285,9 @@ def club_statistics(request, clubid):
|
||||||
gymnastsDict = {}
|
gymnastsDict = {}
|
||||||
gymnasts = []
|
gymnasts = []
|
||||||
courseList = []
|
courseList = []
|
||||||
|
|
||||||
for course in courses:
|
for course in courses:
|
||||||
nbtrainer = course.trainers.count()
|
|
||||||
list_of_gymnasts = Gymnast.objects.filter(to_gym__in=course.to_subgroup.all())
|
list_of_gymnasts = Gymnast.objects.filter(to_gym__in=course.to_subgroup.all())
|
||||||
gymnasts.extend(list_of_gymnasts)
|
gymnasts.extend(list_of_gymnasts)
|
||||||
nbgymnast = len(list_of_gymnasts)
|
nbgymnast = len(list_of_gymnasts)
|
||||||
|
@ -295,38 +296,8 @@ def club_statistics(request, clubid):
|
||||||
nbhour = __diffTime(course.hour_end, course.hour_begin) # timedelta
|
nbhour = __diffTime(course.hour_end, course.hour_begin) # timedelta
|
||||||
totalHoursByWeek += nbhour.seconds
|
totalHoursByWeek += nbhour.seconds
|
||||||
|
|
||||||
counted = course.get_total_occurence()
|
|
||||||
|
|
||||||
# select tous les unavailables liés au cours
|
|
||||||
unavailabilities = Unavailability.objects.filter(course=course)
|
|
||||||
for unavailable in unavailabilities:
|
|
||||||
counted -= unavailable.get_total_occurence()
|
|
||||||
|
|
||||||
totalCourses += counted
|
|
||||||
totalTimeForCourse = nbhour * counted # timedelta
|
|
||||||
totalHourForCourse = (totalTimeForCourse.days * 24) + (
|
|
||||||
totalTimeForCourse.seconds / 3600
|
|
||||||
)
|
|
||||||
totalHours += totalHourForCourse
|
|
||||||
totalHoursPaidForCourse = totalHourForCourse * nbtrainer
|
|
||||||
totalHoursPaid += totalHoursPaidForCourse
|
|
||||||
|
|
||||||
# tmp = int(nbhour.seconds/3600)
|
|
||||||
# hour = "%d:%02d" % (tmp, (nbhour.seconds - (tmp * 3600)) / 60)
|
|
||||||
hour = nbhour.seconds / 3600
|
hour = nbhour.seconds / 3600
|
||||||
|
|
||||||
courseList.append(
|
|
||||||
(
|
|
||||||
course,
|
|
||||||
nbtrainer,
|
|
||||||
nbgymnast,
|
|
||||||
hour,
|
|
||||||
counted,
|
|
||||||
totalHourForCourse,
|
|
||||||
totalHoursPaidForCourse,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
for gymnast in list_of_gymnasts:
|
for gymnast in list_of_gymnasts:
|
||||||
# print(gymnast)
|
# print(gymnast)
|
||||||
if gymnast.id not in gymnastsDict:
|
if gymnast.id not in gymnastsDict:
|
||||||
|
|
|
@ -62,8 +62,7 @@ class Gymnast(Markdownizable):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = "Gymnast"
|
verbose_name = "gymnaste"
|
||||||
verbose_name_plural = "Gymnasts"
|
|
||||||
ordering = ["user__last_name", "user__first_name"]
|
ordering = ["user__last_name", "user__first_name"]
|
||||||
|
|
||||||
GENDER_CHOICES = ((0, "Male"), (1, "Female"))
|
GENDER_CHOICES = ((0, "Male"), (1, "Female"))
|
||||||
|
@ -189,6 +188,12 @@ class Gymnast(Markdownizable):
|
||||||
period = pendulum.now() - pendulum.instance(self.created_at, "Europe/Brussels")
|
period = pendulum.now() - pendulum.instance(self.created_at, "Europe/Brussels")
|
||||||
return int(self.year_of_practice + period.in_years())
|
return int(self.year_of_practice + period.in_years())
|
||||||
|
|
||||||
|
def attendances(self, course):
|
||||||
|
"""Retourne les séances d'un cours où le gymnaste était présent
|
||||||
|
|
||||||
|
"""
|
||||||
|
return self.trainings.filter(course=course)
|
||||||
|
|
||||||
|
|
||||||
class Accident(Markdownizable):
|
class Accident(Markdownizable):
|
||||||
"""La classe `Accident` permet d'indiquer qu'un gymnaste est tombé durant un saut.
|
"""La classe `Accident` permet d'indiquer qu'un gymnaste est tombé durant un saut.
|
||||||
|
|
|
@ -0,0 +1,65 @@
|
||||||
|
"""Tests liés aux personnes, aux gymnastes, ..."""
|
||||||
|
|
||||||
|
from django.contrib.auth import get_user_model
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
from location.models import Club, Country, Place
|
||||||
|
from planning.models import Course, Training
|
||||||
|
|
||||||
|
from ..models import Gymnast
|
||||||
|
|
||||||
|
|
||||||
|
USER_MODEL = get_user_model()
|
||||||
|
|
||||||
|
|
||||||
|
class TestGymnast(TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.user1 = USER_MODEL.objects.create(username="james_bond", last_name="Bond", first_name="James")
|
||||||
|
self.club = Club.objects.create(
|
||||||
|
name="RCW",
|
||||||
|
place=Place.objects.create(
|
||||||
|
name="Somewhere",
|
||||||
|
postal=1080,
|
||||||
|
country=Country.objects.create(
|
||||||
|
namefr="Belgique",
|
||||||
|
isonum=56
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
self.course = Course.objects.create(
|
||||||
|
iso_day_number=2,
|
||||||
|
datebegin="2022-01-01",
|
||||||
|
dateend="2022-10-20",
|
||||||
|
hour_begin="08:30",
|
||||||
|
hour_end="20:00",
|
||||||
|
club=self.club
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_gymnast_should_return_lastname_and_firstname(self):
|
||||||
|
gymnast = Gymnast(user=self.user1)
|
||||||
|
self.assertEqual(str(gymnast), "Bond, James")
|
||||||
|
|
||||||
|
def test_gymnast_attendances_should_be_zero(self):
|
||||||
|
"""Vérifie qu'un gymnaste n'assiste par défaut à aucun entrainement"""
|
||||||
|
gymnast = Gymnast.objects.create(
|
||||||
|
user=self.user1,
|
||||||
|
birthdate="1980-01-01",
|
||||||
|
gender=0,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(gymnast.attendances(self.course).count(), 0)
|
||||||
|
|
||||||
|
def test_attendances_should_be_equals_two(self):
|
||||||
|
"""Vérifie que les entrainements auxquels le gymnaste a assisté sont bien pris en compte"""
|
||||||
|
gymnast = Gymnast.objects.create(
|
||||||
|
user=self.user1,
|
||||||
|
birthdate="1980-01-01",
|
||||||
|
gender=0,
|
||||||
|
)
|
||||||
|
Training.objects.create(gymnast=gymnast, course=self.course, trainingdate="2021-02-01")
|
||||||
|
|
||||||
|
self.assertEqual(gymnast.attendances(self.course).count(), 1)
|
||||||
|
|
||||||
|
Training.objects.create(gymnast=gymnast, course=self.course, trainingdate="2021-02-02")
|
||||||
|
|
||||||
|
self.assertEqual(gymnast.attendances(self.course).count(), 2)
|
|
@ -5,22 +5,6 @@ from .models import Gymnast, Accident
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
# class GymnastTestCase():
|
|
||||||
def test_gymnast_tostring():
|
|
||||||
g = Gymnast(lastname="Pauchou", firstname="Fred")
|
|
||||||
assert str(g) == "Pauchou, Fred"
|
|
||||||
|
|
||||||
def test_gymnaste_get_age():
|
|
||||||
g = Gymnast(lastname="Pauchou", firstname="Fred", birthdate=datetime.strptime('03/07/1985', '%d/%m/%Y'));
|
|
||||||
assert g.age == 35
|
|
||||||
|
|
||||||
def test_gymnaste_get_next_age():
|
|
||||||
g = Gymnast(lastname="Pauchou", firstname="Fred", birthdate=datetime.strptime('03/07/1985', '%d/%m/%Y'));
|
|
||||||
assert g.next_age == 36
|
|
||||||
|
|
||||||
def test_gymnaste_next_birthday():
|
|
||||||
g = Gymnast(lastname="Pauchou", firstname="Fred", birthdate=datetime.strptime('03/07/1985', '%d/%m/%Y'));
|
|
||||||
assert g.next_birthday == datetime.strptime('03/07/2021', '%d/%m/%Y')
|
|
||||||
|
|
||||||
def test_gymnast_known_skills():
|
def test_gymnast_known_skills():
|
||||||
# @Fred : Comment tester cela ?
|
# @Fred : Comment tester cela ?
|
||||||
|
|
|
@ -489,16 +489,12 @@ class Unavailability(Markdownizable, Temporizable):
|
||||||
|
|
||||||
|
|
||||||
class Training(models.Model):
|
class Training(models.Model):
|
||||||
"""Classe représentant les entraînements.
|
"""Un entraînement est une occurence d'un cours pendant lequel des gymnastes sont présents.
|
||||||
|
|
||||||
Un entraînement est une occurence d'un cours pendant lequel des gmnastes sont présents.
|
|
||||||
|
|
||||||
Un objet de cette classe lie donc un cours et un gymnaste à une date donnée.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = "Training"
|
verbose_name = "entraînement"
|
||||||
verbose_name_plural = "Trainings"
|
|
||||||
|
|
||||||
gymnast = models.ForeignKey(
|
gymnast = models.ForeignKey(
|
||||||
"people.Gymnast",
|
"people.Gymnast",
|
||||||
|
|
|
@ -1302,7 +1302,7 @@ def planningline_update(request, planninglineid=None):
|
||||||
else:
|
else:
|
||||||
form = PlanningLineForm(
|
form = PlanningLineForm(
|
||||||
initial={
|
initial={
|
||||||
"gymnast": planningline.gymnast.id,
|
"gymnast": planningline.gymnast.id,
|
||||||
"gymnast_related": planningline.gymnast,
|
"gymnast_related": planningline.gymnast,
|
||||||
"date": planningline.date,
|
"date": planningline.date,
|
||||||
"order": planningline.order,
|
"order": planningline.order,
|
||||||
|
|
Loading…
Reference in New Issue