Update opolka/ScoDoc from ScoDoc/ScoDoc #2

Merged
opolka merged 1272 commits from ScoDoc/ScoDoc:master into master 2024-05-27 09:11:04 +02:00
2 changed files with 76 additions and 30 deletions
Showing only changes of commit 48d7ef3d72 - Show all commits

View File

@ -946,8 +946,8 @@ def _count_manager(requested) -> tuple[str, dict]:
est_just: str = requested.args.get("est_just") est_just: str = requested.args.get("est_just")
if est_just is not None: if est_just is not None:
trues: tuple[str] = ("v", "t", "vrai", "true") trues: tuple[str] = ("v", "t", "vrai", "true", "1")
falses: tuple[str] = ("f", "faux", "false") falses: tuple[str] = ("f", "faux", "false", "0")
if est_just.lower() in trues: if est_just.lower() in trues:
filtered["est_just"] = True filtered["est_just"] = True
@ -960,6 +960,12 @@ def _count_manager(requested) -> tuple[str, dict]:
if user_id is not False: if user_id is not False:
filtered["user_id"] = user_id 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) return (metric, filtered)
@ -1015,8 +1021,8 @@ def _filter_manager(requested, assiduites_query: Query) -> Query:
est_just: str = requested.args.get("est_just") est_just: str = requested.args.get("est_just")
if est_just is not None: if est_just is not None:
trues: tuple[str] = ("v", "t", "vrai", "true") trues: tuple[str] = ("v", "t", "vrai", "true", "1")
falses: tuple[str] = ("f", "faux", "false") falses: tuple[str] = ("f", "faux", "false", "0")
if est_just.lower() in trues: if est_just.lower() in trues:
assiduites_query: Query = scass.filter_assiduites_by_est_just( 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 delta: timedelta = assi.date_fin - assi.date_debut
if delta.days > 0: if delta.days > 0:
# raise Exception(self.hours)
self.compute_long_assiduite(assi) self.compute_long_assiduite(assi)
continue continue
@ -186,37 +185,78 @@ def get_assiduites_stats(
if filtered is not None: if filtered is not None:
deb, fin = None, None deb, fin = None, None
for key in filtered: for key in filtered:
if key == "etat": match key:
assiduites = filter_assiduites_by_etat(assiduites, filtered[key]) case "etat":
elif key == "date_fin": assiduites = filter_assiduites_by_etat(assiduites, filtered[key])
fin = filtered[key] case "date_fin":
elif key == "date_debut": fin = filtered[key]
deb = filtered[key] case "date_debut":
elif key == "moduleimpl_id": deb = filtered[key]
assiduites = filter_by_module_impl(assiduites, filtered[key]) case "moduleimpl_id":
elif key == "formsemestre": assiduites = filter_by_module_impl(assiduites, filtered[key])
assiduites = filter_by_formsemestre( case "formsemestre":
assiduites, Assiduite, filtered[key] assiduites = filter_by_formsemestre(
) assiduites, Assiduite, filtered[key]
elif key == "est_just": )
assiduites = filter_assiduites_by_est_just(assiduites, filtered[key]) case "est_just":
elif key == "user_id": assiduites = filter_assiduites_by_est_just(
assiduites = filter_by_user_id(assiduites, filtered[key]) assiduites, filtered[key]
)
case "user_id":
assiduites = filter_by_user_id(assiduites, filtered[key])
if (deb, fin) != (None, None): if (deb, fin) != (None, None):
assiduites = filter_by_date(assiduites, Assiduite, deb, fin) 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(",") metrics: list[str] = metric.split(",")
output: dict = {} 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: if key in metrics:
output[key] = val output_etat[key] = val
return output if output else count return output_etat if output_etat else count_etat
def filter_assiduites_by_etat(assiduites: Assiduite, etat: str) -> Query: 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 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( def filter_by_user_id(