Refactors clubs statistics
This commit is contained in:
parent
00df7cbd0b
commit
0bff7e0f66
|
@ -81,23 +81,8 @@ def __getEventInfo(request):
|
||||||
.. todo:: il refuse mon 'filter' que ce soit avant ou après le 'next(5)'. Une idée ?
|
.. todo:: il refuse mon 'filter' que ce soit avant ou après le 'next(5)'. Une idée ?
|
||||||
next_event = Event.objects.filter(club__in=(request.session["clubid"], )).next(5)
|
next_event = Event.objects.filter(club__in=(request.session["clubid"], )).next(5)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# rest = 0
|
|
||||||
# counted = 0
|
|
||||||
# event_list = []
|
|
||||||
# today = pendulum.now().date()
|
|
||||||
next_event_list = Event.objects.next(5)
|
next_event_list = Event.objects.next(5)
|
||||||
|
|
||||||
# for event in next_event:
|
|
||||||
# counted = event.get_number_of_occurence_to_event(today)
|
|
||||||
# # print('pouf !')
|
|
||||||
|
|
||||||
# unavailabilities = Unavailability.objects.filter(datebegin__lte=event.datebegin.date(), dateend__gte=today)
|
|
||||||
# for unavailable in unavailabilities:
|
|
||||||
# counted -= unavailable.get_total_occurence()
|
|
||||||
|
|
||||||
# event_list.append((event, counted, int((counted/16)*100)))
|
|
||||||
|
|
||||||
return next_event_list
|
return next_event_list
|
||||||
|
|
||||||
|
|
||||||
|
@ -130,18 +115,9 @@ def __getCourseInfo(request):
|
||||||
else:
|
else:
|
||||||
rest = int((tmp.days + 1) / 7)
|
rest = int((tmp.days + 1) / 7)
|
||||||
|
|
||||||
# # select tous les unavailables liés au cours
|
|
||||||
# unavailabilities = Unavailability.objects.filter(course=course)
|
|
||||||
# for unavailable in unavailabilities:
|
|
||||||
# tmp = unavailable.get_total_occurence()
|
|
||||||
# counted -= tmp
|
|
||||||
# rest -= tmp # si un unavailability.date < today, on soustrait quand même de rest ??? Si oui => BUG !!!!
|
|
||||||
|
|
||||||
courses_left += rest
|
courses_left += rest
|
||||||
courses_done += counted - rest
|
courses_done += counted - rest
|
||||||
|
|
||||||
# courses.append((course, counted, (counted - rest)))
|
|
||||||
|
|
||||||
return courses, courses_done, courses_left
|
return courses, courses_done, courses_left
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -170,10 +170,14 @@ class GymnastStatistics():
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def club_statistics(request, clubid):
|
def club_statistics(request, clubid):
|
||||||
"""
|
"""Construit les statistiques d'un club, pour une saison choisie
|
||||||
Renvoie les statistiques d'un club pour une saison choisie.
|
|
||||||
|
|
||||||
.. todo:: tenir compte de la saison.
|
Questions:
|
||||||
|
Tu dis que cela construit les stats d'un club __pour une saison__...
|
||||||
|
Mais je ne vois pas la saison dans les paramètres...
|
||||||
|
|
||||||
|
Todo:
|
||||||
|
* Tenir compte de la saison.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
courses = Course.objects.filter(club__in=clubid).order_by(
|
courses = Course.objects.filter(club__in=clubid).order_by(
|
||||||
|
@ -189,13 +193,12 @@ def club_statistics(request, clubid):
|
||||||
courseList = []
|
courseList = []
|
||||||
|
|
||||||
for course in courses:
|
for course in courses:
|
||||||
nbtrainer = course.trainers.count()
|
number_of_trainers = 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)
|
number_of_gymnasts = len(list_of_gymnasts)
|
||||||
# gymnasts = set(gymnasts.extend(Gymnast.objects.filter(to_gym__in=course.to_subgroup.all())))
|
|
||||||
|
|
||||||
nbhour = __diffTime(course.hour_end, course.hour_begin) # timedelta
|
nbhour = __diffTime(course.hour_end, course.hour_begin)
|
||||||
totalHoursByWeek += nbhour.seconds
|
totalHoursByWeek += nbhour.seconds
|
||||||
|
|
||||||
counted = course.get_total_occurence()
|
counted = course.get_total_occurence()
|
||||||
|
@ -211,7 +214,7 @@ def club_statistics(request, clubid):
|
||||||
totalTimeForCourse.seconds / 3600
|
totalTimeForCourse.seconds / 3600
|
||||||
)
|
)
|
||||||
totalHours += totalHourForCourse
|
totalHours += totalHourForCourse
|
||||||
totalHoursPaidForCourse = totalHourForCourse * nbtrainer
|
totalHoursPaidForCourse = totalHourForCourse * number_of_trainers
|
||||||
totalHoursPaid += totalHoursPaidForCourse
|
totalHoursPaid += totalHoursPaidForCourse
|
||||||
|
|
||||||
# tmp = int(nbhour.seconds/3600)
|
# tmp = int(nbhour.seconds/3600)
|
||||||
|
@ -221,8 +224,8 @@ def club_statistics(request, clubid):
|
||||||
courseList.append(
|
courseList.append(
|
||||||
(
|
(
|
||||||
course,
|
course,
|
||||||
nbtrainer,
|
number_of_trainers,
|
||||||
nbgymnast,
|
number_of_gymnasts,
|
||||||
hour,
|
hour,
|
||||||
counted,
|
counted,
|
||||||
totalHourForCourse,
|
totalHourForCourse,
|
||||||
|
|
|
@ -279,8 +279,8 @@ class Course(Markdownizable, Temporizable):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = "Course"
|
verbose_name = "Cours"
|
||||||
verbose_name_plural = "Courses"
|
verbose_name_plural = "Cours"
|
||||||
|
|
||||||
DAY_CHOICE = (
|
DAY_CHOICE = (
|
||||||
(1, "Lundi"),
|
(1, "Lundi"),
|
||||||
|
@ -317,8 +317,12 @@ class Course(Markdownizable, Temporizable):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def duration(self):
|
def duration(self):
|
||||||
"""
|
"""Renvoie la durée d'un cours en heures
|
||||||
Renvoie la durée d'un cours en heures
|
|
||||||
|
Examples:
|
||||||
|
>>> course = Course(hour_begin=20, hour_end=22)
|
||||||
|
>>> course.duration
|
||||||
|
2
|
||||||
"""
|
"""
|
||||||
date_begin = pendulum.datetime(
|
date_begin = pendulum.datetime(
|
||||||
2000, 1, 1, self.hour_begin.hour, self.hour_begin.minute
|
2000, 1, 1, self.hour_begin.hour, self.hour_begin.minute
|
||||||
|
|
|
@ -1,7 +1,39 @@
|
||||||
|
"""Tests liés au modèle de l'application planning"""
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime, time
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from ..models import get_number_of_weeks_between, Season
|
|
||||||
|
from location.models import Club, Place, Country
|
||||||
|
|
||||||
|
from ..models import get_number_of_weeks_between, Season, Course
|
||||||
|
|
||||||
|
|
||||||
|
class TestCourse(TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def test_course_duration(self):
|
||||||
|
"""Vérifie le calcul de durée d'un cours"""
|
||||||
|
course = Course.objects.create(
|
||||||
|
iso_day_number=2,
|
||||||
|
datebegin=datetime(2021, 1, 1),
|
||||||
|
dateend=datetime(2021, 9, 30),
|
||||||
|
hour_begin=time(hour=19, minute=30),
|
||||||
|
hour_end=time(hour=22, minute=45),
|
||||||
|
club=Club.objects.create(
|
||||||
|
name="RCW",
|
||||||
|
place=Place.objects.create(
|
||||||
|
name="Somewhere",
|
||||||
|
postal=1080,
|
||||||
|
country=Country.objects.create(
|
||||||
|
namefr="Belgique",
|
||||||
|
isonum=56
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(course.duration, 2)
|
||||||
|
|
||||||
|
|
||||||
class TestUtils(TestCase):
|
class TestUtils(TestCase):
|
||||||
|
|
Loading…
Reference in New Issue