Assiduites : fix Décompte absences #693

This commit is contained in:
iziram 2023-09-04 09:08:40 +02:00
parent 3fe5595cae
commit 48d7ef3d72
2 changed files with 76 additions and 30 deletions

View File

@ -946,8 +946,8 @@ def _count_manager(requested) -> tuple[str, dict]:
est_just: str = requested.args.get("est_just")
if est_just is not None:
trues: tuple[str] = ("v", "t", "vrai", "true")
falses: tuple[str] = ("f", "faux", "false")
trues: tuple[str] = ("v", "t", "vrai", "true", "1")
falses: tuple[str] = ("f", "faux", "false", "0")
if est_just.lower() in trues:
filtered["est_just"] = True
@ -960,6 +960,12 @@ def _count_manager(requested) -> tuple[str, dict]:
if user_id is not False:
filtered["user_id"] = user_id
# cas 9 : split
split = requested.args.get("split", False)
if split is not False:
filtered["split"] = True
return (metric, filtered)
@ -1015,8 +1021,8 @@ def _filter_manager(requested, assiduites_query: Query) -> Query:
est_just: str = requested.args.get("est_just")
if est_just is not None:
trues: tuple[str] = ("v", "t", "vrai", "true")
falses: tuple[str] = ("f", "faux", "false")
trues: tuple[str] = ("v", "t", "vrai", "true", "1")
falses: tuple[str] = ("f", "faux", "false", "0")
if est_just.lower() in trues:
assiduites_query: Query = scass.filter_assiduites_by_est_just(

View File

@ -152,7 +152,6 @@ class CountCalculator:
delta: timedelta = assi.date_fin - assi.date_debut
if delta.days > 0:
# raise Exception(self.hours)
self.compute_long_assiduite(assi)
continue
@ -186,37 +185,78 @@ def get_assiduites_stats(
if filtered is not None:
deb, fin = None, None
for key in filtered:
if key == "etat":
assiduites = filter_assiduites_by_etat(assiduites, filtered[key])
elif key == "date_fin":
fin = filtered[key]
elif key == "date_debut":
deb = filtered[key]
elif key == "moduleimpl_id":
assiduites = filter_by_module_impl(assiduites, filtered[key])
elif key == "formsemestre":
assiduites = filter_by_formsemestre(
assiduites, Assiduite, filtered[key]
)
elif key == "est_just":
assiduites = filter_assiduites_by_est_just(assiduites, filtered[key])
elif key == "user_id":
assiduites = filter_by_user_id(assiduites, filtered[key])
match key:
case "etat":
assiduites = filter_assiduites_by_etat(assiduites, filtered[key])
case "date_fin":
fin = filtered[key]
case "date_debut":
deb = filtered[key]
case "moduleimpl_id":
assiduites = filter_by_module_impl(assiduites, filtered[key])
case "formsemestre":
assiduites = filter_by_formsemestre(
assiduites, Assiduite, filtered[key]
)
case "est_just":
assiduites = filter_assiduites_by_est_just(
assiduites, filtered[key]
)
case "user_id":
assiduites = filter_by_user_id(assiduites, filtered[key])
if (deb, fin) != (None, None):
assiduites = filter_by_date(assiduites, Assiduite, deb, fin)
calculator: CountCalculator = CountCalculator()
calculator.compute_assiduites(assiduites)
count: dict = calculator.to_dict()
metrics: list[str] = metric.split(",")
output: dict = {}
calculator: CountCalculator = CountCalculator()
for key, val in count.items():
if "split" not in filtered:
calculator.compute_assiduites(assiduites)
count: dict = calculator.to_dict()
for key, val in count.items():
if key in metrics:
output[key] = val
return output if output else count
etats: list[str] = (
filtered["etat"].split(",")
if "etat" in filtered
else ["absent", "present", "retard"]
)
for etat in etats:
output[etat] = _count_assiduites_etat(etat, assiduites, calculator, metrics)
if "est_just" not in filtered:
output[etat]["justifie"] = _count_assiduites_etat(
etat, assiduites, calculator, metrics, justifie=True
)
return output
def _count_assiduites_etat(
etat: str,
assiduites: Query,
calculator: CountCalculator,
metrics: list[str],
justifie: bool = False,
):
calculator.reset()
etat_num: int = scu.EtatAssiduite.get(etat, -1)
assiduites_etat: Query = assiduites.filter(Assiduite.etat == etat_num)
if justifie:
assiduites_etat = assiduites_etat.filter(Assiduite.est_just == True)
calculator.compute_assiduites(assiduites_etat)
count_etat: dict = calculator.to_dict()
output_etat: dict = {}
for key, val in count_etat.items():
if key in metrics:
output[key] = val
return output if output else count
output_etat[key] = val
return output_etat if output_etat else count_etat
def filter_assiduites_by_etat(assiduites: Assiduite, etat: str) -> Query:
@ -232,7 +272,7 @@ def filter_assiduites_by_est_just(assiduites: Assiduite, est_just: bool) -> Quer
"""
Filtrage d'une collection d'assiduites en fonction de s'ils sont justifiés
"""
return assiduites.filter_by(est_just=est_just)
return assiduites.filter(Assiduite.est_just == est_just)
def filter_by_user_id(