2018-04-02 13:44:06 +02:00
|
|
|
from django.conf import settings
|
2018-03-02 12:01:51 +01:00
|
|
|
from django.db import models
|
|
|
|
|
|
|
|
|
|
|
|
class Room(models.Model):
|
|
|
|
class Meta:
|
2019-06-23 15:39:13 +02:00
|
|
|
verbose_name = "salle"
|
|
|
|
verbose_name_plural = "salles"
|
2018-03-02 12:01:51 +01:00
|
|
|
|
2019-06-23 15:39:13 +02:00
|
|
|
name = models.CharField("nom", max_length=300)
|
|
|
|
latitude = models.DecimalField(
|
|
|
|
"latitude", max_digits=11, decimal_places=8, blank=True, null=True
|
|
|
|
)
|
|
|
|
longitude = models.DecimalField(
|
|
|
|
"longitude", max_digits=11, decimal_places=8, blank=True, null=True
|
|
|
|
)
|
|
|
|
notes = models.TextField("notes", blank=True)
|
2018-03-02 12:01:51 +01:00
|
|
|
|
2018-03-03 18:16:27 +01:00
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
2018-03-02 12:01:51 +01:00
|
|
|
|
2018-03-13 09:06:28 +01:00
|
|
|
class Unit(models.Model):
|
|
|
|
class Meta:
|
2019-06-23 15:39:13 +02:00
|
|
|
verbose_name = "unité"
|
|
|
|
verbose_name_plural = "unités"
|
2018-03-13 09:06:28 +01:00
|
|
|
|
2019-06-23 15:39:13 +02:00
|
|
|
name = models.CharField("nom", max_length=50)
|
2018-03-13 09:06:28 +01:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
|
2018-03-13 09:24:12 +01:00
|
|
|
class WorkForm(models.Model):
|
|
|
|
class Meta:
|
2019-06-23 15:39:13 +02:00
|
|
|
verbose_name = "forme de travail"
|
|
|
|
verbose_name_plural = "formes de travail"
|
2018-03-13 09:24:12 +01:00
|
|
|
|
2019-06-23 15:39:13 +02:00
|
|
|
name = models.CharField("nom", max_length=300)
|
2018-03-13 09:24:12 +01:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
|
2018-03-02 12:01:51 +01:00
|
|
|
class Equipment(models.Model):
|
|
|
|
class Meta:
|
2019-06-23 15:39:13 +02:00
|
|
|
verbose_name = "machine"
|
|
|
|
verbose_name_plural = "machines"
|
2018-03-02 12:01:51 +01:00
|
|
|
|
2019-06-23 15:39:13 +02:00
|
|
|
name = models.CharField("nom", max_length=300)
|
2018-03-02 12:01:51 +01:00
|
|
|
room = models.ForeignKey(
|
2019-06-23 15:39:13 +02:00
|
|
|
verbose_name="salle",
|
2018-03-02 12:01:51 +01:00
|
|
|
to=Room,
|
|
|
|
on_delete=models.SET_NULL,
|
2019-06-23 15:39:13 +02:00
|
|
|
related_name="equipments",
|
|
|
|
null=True,
|
2018-03-02 12:01:51 +01:00
|
|
|
)
|
2018-03-13 09:06:28 +01:00
|
|
|
unit = models.ForeignKey(
|
2019-06-23 15:39:13 +02:00
|
|
|
verbose_name="unité", to=Unit, on_delete=models.PROTECT, null=True
|
2018-03-13 09:06:28 +01:00
|
|
|
)
|
2019-06-23 15:39:13 +02:00
|
|
|
default_work_form = models.ForeignKey(
|
|
|
|
verbose_name="forme de travail par défaut",
|
2018-03-13 09:24:12 +01:00
|
|
|
to=WorkForm,
|
|
|
|
on_delete=models.SET_NULL,
|
2019-06-23 15:39:13 +02:00
|
|
|
null=True,
|
|
|
|
)
|
|
|
|
default_repetition_number = models.PositiveIntegerField(
|
|
|
|
"nombre de répétitions par défaut", default=12
|
2018-03-13 09:24:12 +01:00
|
|
|
)
|
2018-03-02 12:01:51 +01:00
|
|
|
|
2018-03-03 18:16:27 +01:00
|
|
|
@property
|
|
|
|
def last_theoretical_max(self):
|
2019-06-23 15:39:13 +02:00
|
|
|
return self.theoretical_maxs.order_by("-date", "-pk").first()
|
2018-03-03 18:16:27 +01:00
|
|
|
|
|
|
|
def __str__(self):
|
2019-06-23 15:39:13 +02:00
|
|
|
return f"{self.name} ({self.room.name})"
|
2018-03-03 18:16:27 +01:00
|
|
|
|
2018-03-02 12:01:51 +01:00
|
|
|
|
|
|
|
class Setting(models.Model):
|
|
|
|
class Meta:
|
2019-06-23 15:39:13 +02:00
|
|
|
verbose_name = "réglage"
|
|
|
|
verbose_name_plural = "réglages"
|
2018-03-02 12:01:51 +01:00
|
|
|
|
|
|
|
equipment = models.ForeignKey(
|
2019-06-23 15:39:13 +02:00
|
|
|
verbose_name="machine",
|
2018-03-02 12:01:51 +01:00
|
|
|
to=Equipment,
|
|
|
|
on_delete=models.CASCADE,
|
2019-06-23 15:39:13 +02:00
|
|
|
related_name="settings",
|
2018-03-02 12:01:51 +01:00
|
|
|
)
|
2019-06-23 15:39:13 +02:00
|
|
|
name = models.CharField("nom", max_length=200)
|
|
|
|
value = models.CharField("valeur", max_length=200)
|
2018-03-02 12:01:51 +01:00
|
|
|
|
2018-03-03 18:16:27 +01:00
|
|
|
def __str__(self):
|
2019-06-23 15:39:13 +02:00
|
|
|
return f"{self.name}={self.value}"
|
2018-03-03 18:16:27 +01:00
|
|
|
|
2018-03-02 12:01:51 +01:00
|
|
|
|
|
|
|
class TheoreticalMax(models.Model):
|
|
|
|
class Meta:
|
2019-06-23 15:39:13 +02:00
|
|
|
verbose_name = "maximum théorique"
|
|
|
|
verbose_name_plural = "maximums théoriques"
|
2018-03-02 12:01:51 +01:00
|
|
|
|
|
|
|
equipment = models.ForeignKey(
|
2019-06-23 15:39:13 +02:00
|
|
|
verbose_name="machine",
|
2018-03-02 12:01:51 +01:00
|
|
|
to=Equipment,
|
|
|
|
on_delete=models.CASCADE,
|
2019-06-23 15:39:13 +02:00
|
|
|
related_name="theoretical_maxs",
|
2018-03-02 12:01:51 +01:00
|
|
|
)
|
2019-06-23 15:39:13 +02:00
|
|
|
date = models.DateField("date")
|
|
|
|
value = models.FloatField("valeur")
|
2018-03-02 12:01:51 +01:00
|
|
|
|
2018-03-03 18:16:27 +01:00
|
|
|
def __str__(self):
|
2019-06-23 15:39:13 +02:00
|
|
|
return f"{self.value} {self.equipment.unit.name} le {self.date:%d/%m/%Y}"
|
2018-03-03 18:16:27 +01:00
|
|
|
|
2018-03-02 12:01:51 +01:00
|
|
|
|
|
|
|
class Session(models.Model):
|
|
|
|
class Meta:
|
2019-06-23 15:39:13 +02:00
|
|
|
verbose_name = "séance"
|
|
|
|
verbose_name_plural = "séances"
|
2018-03-02 12:01:51 +01:00
|
|
|
|
2019-06-23 15:39:13 +02:00
|
|
|
start = models.DateTimeField("date et heure de début")
|
2018-03-02 12:01:51 +01:00
|
|
|
room = models.ForeignKey(
|
2019-06-23 15:39:13 +02:00
|
|
|
verbose_name="salle",
|
2018-03-02 12:01:51 +01:00
|
|
|
to=Room,
|
|
|
|
on_delete=models.SET_NULL,
|
2019-06-23 15:39:13 +02:00
|
|
|
related_name="sessions",
|
|
|
|
null=True,
|
|
|
|
)
|
|
|
|
default_theoretical_max_percentage = models.PositiveIntegerField(
|
|
|
|
"pourcentage par défaut", default=65
|
2018-03-02 12:01:51 +01:00
|
|
|
)
|
2019-06-23 15:39:13 +02:00
|
|
|
notes = models.TextField("notes", blank=True)
|
2018-03-02 12:01:51 +01:00
|
|
|
|
2018-03-04 09:23:35 +01:00
|
|
|
def __str__(self):
|
2018-04-02 13:44:06 +02:00
|
|
|
import pytz
|
2019-06-23 15:39:13 +02:00
|
|
|
|
2018-04-02 13:44:06 +02:00
|
|
|
server_timezone = pytz.timezone(settings.TIME_ZONE)
|
|
|
|
server = server_timezone.normalize(self.start.astimezone(server_timezone))
|
2019-06-23 15:39:13 +02:00
|
|
|
return f"{self.room} {server:%d/%m/%Y %H:%M} ({settings.TIME_ZONE})"
|
2018-03-04 09:23:35 +01:00
|
|
|
|
2018-03-02 12:01:51 +01:00
|
|
|
|
|
|
|
class Round(models.Model):
|
|
|
|
class Meta:
|
2019-06-23 15:39:13 +02:00
|
|
|
verbose_name = "série"
|
|
|
|
verbose_name_plural = "séries"
|
2018-03-02 12:01:51 +01:00
|
|
|
|
2019-06-23 15:39:13 +02:00
|
|
|
repetition_number = models.PositiveIntegerField("nombre de répétitions")
|
2018-03-02 12:01:51 +01:00
|
|
|
equipment = models.ForeignKey(
|
2019-06-23 15:39:13 +02:00
|
|
|
verbose_name="machine",
|
2018-03-02 12:01:51 +01:00
|
|
|
to=Equipment,
|
|
|
|
on_delete=models.CASCADE,
|
2019-06-23 15:39:13 +02:00
|
|
|
related_name="rounds",
|
2018-03-02 12:01:51 +01:00
|
|
|
)
|
2019-06-23 15:39:13 +02:00
|
|
|
theoretical_max_percentage = models.PositiveIntegerField("pourcentage")
|
|
|
|
chosen_weight = models.FloatField("charge choisie")
|
2018-03-02 12:01:51 +01:00
|
|
|
session = models.ForeignKey(
|
2019-06-23 15:39:13 +02:00
|
|
|
verbose_name="séance",
|
2018-03-02 12:01:51 +01:00
|
|
|
to=Session,
|
|
|
|
on_delete=models.CASCADE,
|
2019-06-23 15:39:13 +02:00
|
|
|
related_name="rounds",
|
2018-03-02 12:01:51 +01:00
|
|
|
)
|
2018-03-13 09:24:12 +01:00
|
|
|
work_form = models.ForeignKey(
|
2019-06-23 15:39:13 +02:00
|
|
|
verbose_name="forme de travail",
|
2018-03-13 09:24:12 +01:00
|
|
|
to=WorkForm,
|
|
|
|
on_delete=models.PROTECT,
|
2019-06-23 15:39:13 +02:00
|
|
|
null=True,
|
2018-03-13 09:24:12 +01:00
|
|
|
)
|
2019-06-23 15:39:13 +02:00
|
|
|
notes = models.TextField("notes", blank=True)
|
2019-06-23 16:06:52 +02:00
|
|
|
|
|
|
|
@property
|
|
|
|
def real_percentage(self):
|
|
|
|
theoretical_max = (
|
|
|
|
self.equipment.theoretical_maxs.filter(date__lte=self.session.start)
|
|
|
|
.order_by("-date")
|
|
|
|
.first()
|
|
|
|
)
|
2019-06-23 16:12:36 +02:00
|
|
|
return int(self.chosen_weight / theoretical_max.value * 1000) / 10
|