2023-07-10 17:38:50 +02:00
|
|
|
##############################################################################
|
|
|
|
# ScoDoc
|
2023-12-31 23:04:06 +01:00
|
|
|
# Copyright (c) 1999 - 2024 Emmanuel Viennet. All rights reserved.
|
2023-07-10 17:38:50 +02:00
|
|
|
# See LICENSE
|
|
|
|
##############################################################################
|
|
|
|
|
2024-04-22 15:05:31 +02:00
|
|
|
"""Liste simple d'étudiants"""
|
|
|
|
|
2024-04-10 15:09:32 +02:00
|
|
|
import datetime
|
2023-07-10 17:38:50 +02:00
|
|
|
from flask import g, url_for
|
2023-07-26 13:27:57 +02:00
|
|
|
from app import log
|
|
|
|
from app.models import FormSemestre, Identite, Justificatif
|
2023-07-10 17:38:50 +02:00
|
|
|
from app.tables import table_builder as tb
|
|
|
|
from app.scodoc import sco_preferences
|
2023-07-26 13:27:57 +02:00
|
|
|
from app.scodoc import sco_utils as scu
|
2024-04-10 15:09:32 +02:00
|
|
|
import app.scodoc.sco_assiduites as scass
|
|
|
|
from app.scodoc.sco_exceptions import ScoValueError
|
2023-07-10 17:38:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
class TableAssi(tb.Table):
|
2023-10-26 13:12:22 +02:00
|
|
|
"""Table listant les statistiques d'assiduité des étudiants
|
2024-02-08 15:56:58 +01:00
|
|
|
L'id de la ligne est etudid, et le row stocke etud.
|
|
|
|
|
|
|
|
On considère les assiduités entre les dates indiquées.
|
|
|
|
|
|
|
|
Si formsemestre_modimpls est spécifié, restreint aux assiduités associées à des
|
|
|
|
moduleimpls de ce formsemestre.
|
2024-02-08 11:05:57 +01:00
|
|
|
|
|
|
|
Si convert_values, transforme les nombre en chaines ("12.34"), pour le html.
|
2023-07-10 17:38:50 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
etuds: list[Identite] = None,
|
|
|
|
dates: tuple[str, str] = None,
|
2023-07-26 13:27:57 +02:00
|
|
|
formsemestre: FormSemestre = None,
|
2024-02-08 15:56:58 +01:00
|
|
|
formsemestre_modimpls: FormSemestre | None = None,
|
2024-02-08 11:05:57 +01:00
|
|
|
convert_values=False,
|
2023-07-10 17:38:50 +02:00
|
|
|
**kwargs,
|
|
|
|
):
|
2024-02-27 15:59:48 +01:00
|
|
|
self.rows: list["RowAssi"] = [] # juste pour que VSCode nous aide sur .rows
|
2023-12-15 01:31:15 +01:00
|
|
|
classes = ["gt_table"]
|
2024-04-10 15:09:32 +02:00
|
|
|
try:
|
|
|
|
self.dates = [
|
|
|
|
datetime.datetime.fromisoformat(str(dates[0]) + "T00:00"),
|
|
|
|
datetime.datetime.fromisoformat(str(dates[1]) + "T00:00"),
|
|
|
|
]
|
|
|
|
except ValueError as exc:
|
|
|
|
raise ScoValueError("invalid dates") from exc
|
2023-07-26 13:27:57 +02:00
|
|
|
self.formsemestre = formsemestre
|
2024-02-08 15:56:58 +01:00
|
|
|
self.formsemestre_modimpls = formsemestre_modimpls
|
2024-02-08 11:05:57 +01:00
|
|
|
if convert_values:
|
|
|
|
self.fmt_num = lambda x: f"{x:2.3g}"
|
|
|
|
else:
|
|
|
|
self.fmt_num = lambda x: x
|
2023-07-10 17:38:50 +02:00
|
|
|
super().__init__(
|
|
|
|
row_class=RowAssi,
|
|
|
|
classes=classes,
|
|
|
|
**kwargs,
|
|
|
|
with_foot_titles=False,
|
|
|
|
)
|
|
|
|
self.add_etuds(etuds)
|
|
|
|
|
|
|
|
def add_etuds(self, etuds: list[Identite]):
|
|
|
|
"Ajoute des étudiants à la table"
|
|
|
|
for etud in etuds:
|
|
|
|
row = self.row_class(self, etud)
|
|
|
|
row.add_etud_cols()
|
|
|
|
self.add_row(row)
|
|
|
|
|
|
|
|
|
|
|
|
class RowAssi(tb.Row):
|
|
|
|
"Ligne de la table assiduité"
|
|
|
|
|
|
|
|
# pour le moment très simple, extensible (codes, liens bulletins, ...)
|
|
|
|
def __init__(self, table: TableAssi, etud: Identite, *args, **kwargs):
|
2023-07-26 13:27:57 +02:00
|
|
|
# Etat de l'inscription au formsemestre
|
|
|
|
if "classes" not in kwargs:
|
|
|
|
kwargs["classes"] = []
|
|
|
|
try:
|
|
|
|
inscription = table.formsemestre.etuds_inscriptions[etud.id]
|
|
|
|
if inscription.etat == scu.DEMISSION:
|
|
|
|
kwargs["classes"].append("etuddem")
|
|
|
|
except KeyError:
|
|
|
|
log(f"RowAssi: etudid {etud.id} non inscrit à {table.formsemestre.id}")
|
|
|
|
kwargs["classes"].append("non_inscrit") # ne devrait pas arriver !
|
|
|
|
|
2023-07-10 17:38:50 +02:00
|
|
|
super().__init__(table, etud.id, *args, **kwargs)
|
|
|
|
self.etud = etud
|
|
|
|
self.dates = table.dates
|
|
|
|
|
|
|
|
def add_etud_cols(self):
|
|
|
|
"""Ajoute les colonnes"""
|
|
|
|
etud = self.etud
|
2024-02-08 11:05:57 +01:00
|
|
|
fmt_num = self.table.fmt_num
|
2023-07-10 17:38:50 +02:00
|
|
|
self.table.group_titles.update(
|
|
|
|
{
|
|
|
|
"etud_codes": "Codes",
|
|
|
|
"identite_detail": "",
|
|
|
|
"identite_court": "",
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2023-07-20 15:53:59 +02:00
|
|
|
bilan_etud = url_for(
|
|
|
|
"assiduites.bilan_etud", scodoc_dept=g.scodoc_dept, etudid=etud.id
|
|
|
|
)
|
2024-04-10 15:09:32 +02:00
|
|
|
self.add_cell(
|
|
|
|
"etudid",
|
|
|
|
"etudid",
|
|
|
|
etud.etudid,
|
|
|
|
"etudinfo",
|
|
|
|
only_excel=True,
|
|
|
|
)
|
|
|
|
self.add_cell(
|
|
|
|
"code_nip",
|
|
|
|
"code_nip",
|
|
|
|
etud.code_nip,
|
|
|
|
"etudinfo",
|
|
|
|
only_excel=True,
|
|
|
|
)
|
2023-07-10 17:38:50 +02:00
|
|
|
self.add_cell(
|
|
|
|
"nom_disp",
|
|
|
|
"Nom",
|
|
|
|
etud.nom_disp(),
|
2023-07-20 15:53:59 +02:00
|
|
|
"etudinfo",
|
|
|
|
attrs={"id": str(etud.id)},
|
2023-07-10 17:38:50 +02:00
|
|
|
data={"order": etud.sort_key},
|
|
|
|
target=bilan_etud,
|
2023-07-20 15:53:59 +02:00
|
|
|
target_attrs={"class": "discretelink"},
|
2023-07-10 17:38:50 +02:00
|
|
|
)
|
|
|
|
self.add_cell(
|
|
|
|
"prenom",
|
|
|
|
"Prénom",
|
2023-07-20 15:53:59 +02:00
|
|
|
etud.prenom_str,
|
|
|
|
"etudinfo",
|
|
|
|
attrs={"id": str(etud.id)},
|
2023-07-10 17:38:50 +02:00
|
|
|
data={"order": etud.sort_key},
|
|
|
|
target=bilan_etud,
|
2023-07-20 15:53:59 +02:00
|
|
|
target_attrs={"class": "discretelink"},
|
2023-07-10 17:38:50 +02:00
|
|
|
)
|
|
|
|
stats = self._get_etud_stats(etud)
|
|
|
|
for key, value in stats.items():
|
2024-04-22 15:05:31 +02:00
|
|
|
if key == "present" and sco_preferences.get_preference(
|
|
|
|
"non_present",
|
|
|
|
dept_id=g.scodoc_dept_id,
|
|
|
|
formsemestre_id=self.table.formsemestre.id,
|
|
|
|
):
|
|
|
|
continue
|
|
|
|
|
2024-02-08 11:05:57 +01:00
|
|
|
self.add_cell(key, value[0], fmt_num(value[1] - value[2]), "assi_stats")
|
2023-10-09 15:48:00 +02:00
|
|
|
if key != "present":
|
|
|
|
self.add_cell(
|
|
|
|
key + "_justi",
|
|
|
|
value[0] + " Justifiées",
|
2024-02-08 11:05:57 +01:00
|
|
|
fmt_num(value[2]),
|
2023-10-09 15:48:00 +02:00
|
|
|
"assi_stats",
|
|
|
|
)
|
2023-07-10 17:38:50 +02:00
|
|
|
|
|
|
|
compte_justificatifs = scass.filter_by_date(
|
|
|
|
etud.justificatifs, Justificatif, self.dates[0], self.dates[1]
|
2023-09-12 09:41:50 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
compte_justificatifs_att = compte_justificatifs.filter(Justificatif.etat == 2)
|
2023-07-10 17:38:50 +02:00
|
|
|
|
2023-09-12 09:41:50 +02:00
|
|
|
self.add_cell(
|
|
|
|
"justificatifs_att",
|
|
|
|
"Justificatifs en Attente",
|
2024-02-08 11:05:57 +01:00
|
|
|
fmt_num(compte_justificatifs_att.count()),
|
2023-09-12 09:41:50 +02:00
|
|
|
)
|
|
|
|
self.add_cell(
|
2024-02-08 11:05:57 +01:00
|
|
|
"justificatifs", "Justificatifs", fmt_num(compte_justificatifs.count())
|
2023-09-12 09:41:50 +02:00
|
|
|
)
|
2023-07-10 17:38:50 +02:00
|
|
|
|
|
|
|
def _get_etud_stats(self, etud: Identite) -> dict[str, list[str, float, float]]:
|
2024-01-18 17:05:43 +01:00
|
|
|
"""
|
2024-02-08 11:05:57 +01:00
|
|
|
Renvoie le comptage (dans la métrique du département) des différents états
|
|
|
|
d'assiduité d'un étudiant.
|
2024-02-08 15:56:58 +01:00
|
|
|
Considère les dates.
|
2024-01-18 17:05:43 +01:00
|
|
|
|
|
|
|
Returns :
|
|
|
|
{
|
|
|
|
"<etat>" : [<Etat version lisible>, <nb total etat>, <nb just etat>]
|
|
|
|
}
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
# Préparation du retour
|
2023-07-10 17:38:50 +02:00
|
|
|
retour: dict[str, tuple[str, float, float]] = {
|
2023-07-20 15:53:59 +02:00
|
|
|
"absent": ["Absences", 0.0, 0.0],
|
2023-12-16 22:53:02 +01:00
|
|
|
"retard": ["Retards", 0.0, 0.0],
|
|
|
|
"present": ["Présences", 0.0, 0.0],
|
2023-07-10 17:38:50 +02:00
|
|
|
}
|
|
|
|
|
2024-01-18 17:05:43 +01:00
|
|
|
# Récupération de la métrique du département
|
2023-08-22 15:43:10 +02:00
|
|
|
assi_metric = scu.translate_assiduites_metric(
|
|
|
|
sco_preferences.get_preference("assi_metrique", dept_id=g.scodoc_dept_id),
|
2023-08-13 22:40:16 +02:00
|
|
|
)
|
2023-07-10 17:38:50 +02:00
|
|
|
|
2024-01-18 17:05:43 +01:00
|
|
|
compte_etat: dict[str, dict] = scass.get_assiduites_stats(
|
|
|
|
assiduites=etud.assiduites,
|
|
|
|
metric=assi_metric,
|
|
|
|
filtered={
|
|
|
|
"date_debut": self.dates[0],
|
|
|
|
"date_fin": self.dates[1],
|
|
|
|
"etat": "absent,present,retard", # pour tout compter d'un coup
|
2024-02-08 15:56:58 +01:00
|
|
|
"formsemestre_modimpls": self.table.formsemestre_modimpls,
|
2024-01-18 17:05:43 +01:00
|
|
|
"split": 1, # afin d'avoir la division des stats en état, etatjust, etatnonjust
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
2024-01-21 23:15:44 +01:00
|
|
|
# Pour chaque état on met à jour les valeurs de retour
|
2023-07-10 17:38:50 +02:00
|
|
|
for etat, valeur in retour.items():
|
2024-01-18 17:05:43 +01:00
|
|
|
valeur[1] = compte_etat[etat][assi_metric]
|
|
|
|
if etat != "present":
|
|
|
|
valeur[2] = compte_etat[etat]["justifie"][assi_metric]
|
2023-07-10 17:38:50 +02:00
|
|
|
return retour
|
|
|
|
|
|
|
|
|
|
|
|
def etuds_sorted_from_ids(etudids) -> list[Identite]:
|
|
|
|
"Liste triée d'etuds à partir d'une collections d'etudids"
|
|
|
|
etuds = [Identite.get_etud(etudid) for etudid in etudids]
|
|
|
|
return sorted(etuds, key=lambda etud: etud.sort_key)
|