Add date comparison for plan and minor modification

This commit is contained in:
Gregory Trullemans 2022-10-17 10:58:39 +02:00
parent 4237a957dd
commit f71dbd0d06
5 changed files with 62 additions and 30 deletions

View File

@ -111,7 +111,9 @@
<a href="{% url 'skill_details' skill.id %}">{{ skill.long_label }}</a>
</td>
<td>
{% if skill.is_past %}<span class="text-danger"><b>{% endif %}
{{ skill.plan_date | date:"d-m-Y" }}
{% if skill.is_past %}</b></span>{% endif %}
</td>
<td>{{ skill.difficulty }}</td>
<td>{{ skill.level }}</td>

View File

@ -17,6 +17,8 @@ from ultron.people.models import Gymnast
from ultron.planning.models import Event
from ultron.tools.models import get_number_of_weeks_between
from functools import lru_cache
def login(request):
"""
@ -72,6 +74,11 @@ def next_birthdays(request, number_of_birthday):
return birthday_list
# @lru_cache()
# def get_last_updated_gymnasts(expiration_date):
# ...
@login_required
@require_http_methods(["GET"])
def home(request):
@ -82,6 +89,7 @@ def home(request):
"date_begin"
)[:10]
# mettre tout ca en cache.
last_updated_gymnast = Gymnast.objects.filter(
Q(mindstate__created_at__gt=request.user.last_login)
| Q(points__created_at__gt=request.user.last_login)

View File

@ -7,29 +7,56 @@ register = template.Library()
@register.inclusion_tag("people/gymnasts/gymnast_level_doughnut.html")
def generate_skill_doughnut(gymnast_id):
"""
Récupère les différents nombres de skill du gymnaste (masterised, chained, without help,
""" Récupère pour un gymnaste la quantité de skill dans chaque phase d'apprentissage (with help,
withoutRécupère les différents nombres de skill du gymnaste (masterised, chained, without help,
with help or no) à la dernière date connue et les renvoie pour en faire un graphique.
"""
base_queryset = LearnedSkill.objects.filter(gymnast=gymnast_id).order_by("-date")
# base_queryset = LearnedSkill.objects.filter(gymnast=gymnast_id).order_by("-date")
total = 0
skills_capacity = [0] * 5
checked_skills = set()
for learned_skill in base_queryset:
if learned_skill not in checked_skills:
checked_skills.add(learned_skill)
skills_capacity[learned_skill.learning_step] += 1
total += 1
# total = 0
# skills_capacity = [0] * 5
# checked_skills = set()
# for learned_skill in base_queryset:
# if learned_skill not in checked_skills:
# checked_skills.add(learned_skill)
# skills_capacity[learned_skill.learning_step] += 1
# total += 1
skill_whith_help = (
Skill.objects.filter(known_by__gymnast=gymnast_id, known_by__learning_step=1)
.exclude(known_by__gymnast=gymnast_id, known_by__learning_step__gte=2)
.distinct()
.count()
)
skill_without_help = (
Skill.objects.filter(known_by__gymnast=gymnast_id, known_by__learning_step=2)
.exclude(known_by__gymnast=gymnast_id, known_by__learning_step=3)
.distinct()
.count()
)
skill_chained = (
Skill.objects.filter(known_by__gymnast=gymnast_id, known_by__learning_step=3)
.exclude(known_by__gymnast=gymnast_id, known_by__learning_step=4)
.distinct()
.count()
)
skill_masterised = (
Skill.objects.filter(known_by__gymnast=gymnast_id, known_by__learning_step__gte=4)
.distinct()
.count()
)
nb_skill = Skill.objects.all().count()
nb_unknown_skill = nb_skill - total
nb_unknown_skill = nb_skill - skill_whith_help - skill_without_help - skill_chained - skill_masterised
return {
"nb_skill_masterised": skills_capacity[4],
"nb_skill_chained": skills_capacity[3],
"nb_skill_without_help": skills_capacity[2],
"nb_skill_whith_help": skills_capacity[1],
"lost_skill": skills_capacity[0],
"nb_skill_whith_help": skill_whith_help,
"nb_skill_without_help": skill_without_help,
"nb_skill_chained": skill_chained,
"nb_skill_masterised": skill_masterised,
# "lost_skill": skills_capacity[0],
"nb_unknown_skill": nb_unknown_skill,
}

View File

@ -4,7 +4,7 @@ from django.contrib.auth.models import Group
from django.contrib.auth import get_user_model
User = get_user_model()
from django.db.models import Q, F, Avg
from django.db.models import BooleanField, ExpressionWrapper, Q, F, Avg
from django.db.models.functions import TruncDay
from django.http import HttpResponse, HttpResponseRedirect, JsonResponse
from django.shortcuts import render, get_object_or_404
@ -462,7 +462,13 @@ def gymnast_display_skill(request, gymnast_id):
planified_skill = (
Skill.objects.filter(plan__gymnast=gymnast.id)
.order_by("-plan__date")
.annotate(plan_date=F("plan__date"))
.annotate(
plan_date=F("plan__date"),
is_past=ExpressionWrapper(
Q(plan__date__lte=pendulum.now().date()),
output_field=BooleanField()
)
)
)
context["planified_skill"] = planified_skill
@ -488,12 +494,6 @@ def gymnast_display_skill(request, gymnast_id):
.distinct()
)
skill_not_chained = (
Skill.objects.filter(known_by__gymnast=gymnast_id, known_by__learning_step=2)
.exclude(known_by__gymnast=gymnast.id, known_by__learning_step=3)
.distinct()
)
skill_chained = (
Skill.objects.filter(known_by__gymnast=gymnast_id, known_by__learning_step=3)
.exclude(known_by__gymnast=gymnast.id, known_by__learning_step=4)
@ -502,7 +502,6 @@ def gymnast_display_skill(request, gymnast_id):
context["gymnast"] = gymnast
context["skill_whith_help"] = skill_whith_help
context["skill_not_chained"] = skill_not_chained
context["skill_without_help"] = skill_without_help
context["skill_chained"] = skill_chained
context["gymnast_nb_known_skills"] = gymnast_nb_known_skills

View File

@ -91,10 +91,6 @@ class Seasonisable(models.Model):
self.season, self.week_number = from_date_to_week_number(self.date)
super().save(*args, **kwargs)
# @property
# def is_past(self):
# return pendulum.now().date() > self.date
class TemporizableQuerySet(models.QuerySet):
"""