Jarvis/jarvis/people/templatetags/skill_doughnut.py

35 lines
1.3 KiB
Python

from django import template
from jarvis.objective.models import Skill
from jarvis.followup.models import LearnedSkill
register = template.Library()
@register.inclusion_tag("gymnasts/gymnast_level_doughnut.html")
def generate_skill_doughnut(gymnast_id):
"""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.
"""
skill_learned_by_phase = [0] * 5
learned_skills = (
LearnedSkill.objects.filter(gymnast=gymnast_id)
.order_by("skill_id", "-date")
.distinct("skill_id")
)
for learned_skill in learned_skills:
skill_learned_by_phase[learned_skill.learning_step] += 1
nb_skill = Skill.objects.all().count()
nb_unknown_skill = nb_skill - learned_skills.count()
return {
"lost_skill": skill_learned_by_phase[0],
"nb_skill_whith_help": skill_learned_by_phase[1],
"nb_skill_without_help": skill_learned_by_phase[2],
"nb_skill_chained": skill_learned_by_phase[3],
"nb_skill_masterised": skill_learned_by_phase[4],
"nb_unknown_skill": nb_unknown_skill,
}