from django.db import models from datetime import date from django.db.models.deletion import CASCADE from people.models import Gymnast from planning.models import Event class Chrono(models.Model): """ Représente les chronos (de chandelles ou de série) enregistrés pour un(e) gymnaste. """ TYPE_CHOICES = ((0, "10 |"), (1, "Routine")) SCORE_TYPE_CHOICE = ((0, "Chrono"), (1, "ToF")) class Meta: verbose_name = "Chrono" verbose_name_plural = "Chronos" ordering = ["date", "gymnast"] # unique_together = ("gymnast", "skill") gymnast = models.ForeignKey( Gymnast, verbose_name="gymnast", related_name="chronos", on_delete=models.CASCADE, ) type = models.PositiveSmallIntegerField( choices=TYPE_CHOICES, verbose_name="Chrono type" ) score_type = models.PositiveSmallIntegerField( choices=SCORE_TYPE_CHOICE, verbose_name="Score type" ) score = models.DecimalField(max_digits=5, decimal_places=3) tof = models.DecimalField(max_digits=5, decimal_places=3, blank=True, null=True) date = models.DateField(default=date.today, verbose_name="Date") def __str__(self): return "%s - %s (%s - %s)" % ( self.gymnast, self.score, self.date, self.type, ) class Skill(models.Model): """ Représente la ligne d'apprentissage. """ class Meta: verbose_name = "Skill" verbose_name_plural = 'Skills' ordering = ['short_label'] short_label = models.CharField(verbose_name="Short label", max_length=50, null=False, blank=False) long_label = models.CharField(verbose_name="Long label", max_length=255, null=False, blank=False) difficulty = models.DecimalField( max_digits=3, decimal_places=1, verbose_name="Difficulty" ) level = models.PositiveSmallIntegerField(default=0) rank = models.PositiveSmallIntegerField(default=0) numeric_notation = models.CharField(max_length=25) ancestor = models.ManyToManyField("self") def __str__(self): return "%s (%s) - %s" % ( self.short_label, self.numeric_notation, self.difficulty ) class LearnedSkill(models.Model): """ Représente la capacité d'un gymnaste à savori faire un skill de la ligne d'apprentissage. """ TYPE_CHOICES = ((0, "No"), (1, "With help"), (2, "Without help"), (3, "Chained")) class Meta: verbose_name = 'Learned Skill' verbose_name_plural = 'Learned Skills' unique_together = ('gymnast', 'skill', 'date') gymnast = models.ForeignKey( Gymnast, verbose_name='gymnast', related_name='can_do_skill', on_delete=models.CASCADE, ) skill = models.ForeignKey( Skill, verbose_name='Skill', related_name='done_by_gymnasts', on_delete=models.CASCADE, ) cando = models.PositiveSmallIntegerField( choices=TYPE_CHOICES, verbose_name="Can do type" ) date = models.DateField(default=date.today, verbose_name="Date") class Point(models.Model): """ Représente les points obtenus lors d'une compétition. """ ROUTINETYPE_CHOICE = ((0, "Routine 1"), (1, "Routine 2"), (2, "Final")) gymnast = models.ForeignKey(Gymnast, on_delete=models.CASCADE, default=None) event = models.ForeignKey(Event, on_delete=models.CASCADE, default=None) routine_type = models.PositiveSmallIntegerField(choices=ROUTINETYPE_CHOICE) point_execution = models.DecimalField(max_digits=5, decimal_places=3) point_difficulty = models.DecimalField(max_digits=3, decimal_places=1) point_time_of_flight = models.DecimalField(max_digits=5, decimal_places=3) point_horizontal_displacement = models.DecimalField(max_digits=4, decimal_places=3) penality = models.DecimalField(max_digits=3, decimal_places=1) total = models.DecimalField(max_digits=6, decimal_places=3) def __str__(self): return "%s - %s" % ( self.gymnast, self.total, )