API: remet /formsemestre/<int:formsemestre_id>/etat_evals

This commit is contained in:
Emmanuel Viennet 2024-02-05 00:10:56 +01:00
parent 57d36927ac
commit 128b282186
3 changed files with 96 additions and 98 deletions

View File

@ -374,115 +374,114 @@ def formsemestre_etudiants(
return sorted(etuds, key=itemgetter("sort_key"))
# retrait (temporaire ? à discuter)
# @bp.route("/formsemestre/<int:formsemestre_id>/etat_evals")
# @api_web_bp.route("/formsemestre/<int:formsemestre_id>/etat_evals")
# @login_required
# @scodoc
# @permission_required(Permission.ScoView)
# @as_json
# def etat_evals(formsemestre_id: int):
# """
# Informations sur l'état des évaluations d'un formsemestre.
@bp.route("/formsemestre/<int:formsemestre_id>/etat_evals")
@api_web_bp.route("/formsemestre/<int:formsemestre_id>/etat_evals")
@login_required
@scodoc
@permission_required(Permission.ScoView)
@as_json
def etat_evals(formsemestre_id: int):
"""
Informations sur l'état des évaluations d'un formsemestre.
# formsemestre_id : l'id d'un semestre
formsemestre_id : l'id d'un semestre
# Exemple de résultat :
# [
# {
# "id": 1, // moduleimpl_id
# "titre": "Initiation aux réseaux informatiques",
# "evaluations": [
# {
# "id": 1,
# "description": null,
# "datetime_epreuve": null,
# "heure_fin": "09:00:00",
# "coefficient": "02.00"
# "is_complete": true,
# "nb_inscrits": 16,
# "nb_manquantes": 0,
# "ABS": 0,
# "ATT": 0,
# "EXC": 0,
# "saisie_notes": {
# "datetime_debut": "2021-09-11T00:00:00+02:00",
# "datetime_fin": "2022-08-25T00:00:00+02:00",
# "datetime_mediane": "2022-03-19T00:00:00+01:00"
# }
# },
# ...
# ]
# },
# ]
# """
# query = FormSemestre.query.filter_by(id=formsemestre_id)
# if g.scodoc_dept:
# query = query.filter_by(dept_id=g.scodoc_dept_id)
# formsemestre: FormSemestre = query.first_or_404(formsemestre_id)
# app.set_sco_dept(formsemestre.departement.acronym)
# nt: NotesTableCompat = res_sem.load_formsemestre_results(formsemestre)
Exemple de résultat :
[
{
"id": 1, // moduleimpl_id
"titre": "Initiation aux réseaux informatiques",
"evaluations": [
{
"id": 1,
"description": null,
"datetime_epreuve": null,
"heure_fin": "09:00:00",
"coefficient": "02.00"
"is_complete": true,
"nb_inscrits": 16,
"nb_manquantes": 0,
"ABS": 0,
"ATT": 0,
"EXC": 0,
"saisie_notes": {
"datetime_debut": "2021-09-11T00:00:00+02:00",
"datetime_fin": "2022-08-25T00:00:00+02:00",
"datetime_mediane": "2022-03-19T00:00:00+01:00"
}
},
...
]
},
]
"""
query = FormSemestre.query.filter_by(id=formsemestre_id)
if g.scodoc_dept:
query = query.filter_by(dept_id=g.scodoc_dept_id)
formsemestre: FormSemestre = query.first_or_404(formsemestre_id)
app.set_sco_dept(formsemestre.departement.acronym)
nt: NotesTableCompat = res_sem.load_formsemestre_results(formsemestre)
# result = []
# for modimpl_id in nt.modimpls_results:
# modimpl_results: ModuleImplResults = nt.modimpls_results[modimpl_id]
# modimpl: ModuleImpl = ModuleImpl.query.get_or_404(modimpl_id)
# modimpl_dict = modimpl.to_dict(convert_objects=True)
result = []
for modimpl_id in nt.modimpls_results:
modimpl_results: ModuleImplResults = nt.modimpls_results[modimpl_id]
modimpl: ModuleImpl = ModuleImpl.query.get_or_404(modimpl_id)
modimpl_dict = modimpl.to_dict(convert_objects=True, with_module=False)
# list_eval = []
# for evaluation_id in modimpl_results.evaluations_etat:
# eval_etat = modimpl_results.evaluations_etat[evaluation_id]
# evaluation = Evaluation.query.get_or_404(evaluation_id)
# eval_dict = evaluation.to_dict_api()
# eval_dict["etat"] = eval_etat.to_dict()
list_eval = []
for evaluation_id in modimpl_results.evaluations_etat:
eval_etat = modimpl_results.evaluations_etat[evaluation_id]
evaluation = Evaluation.query.get_or_404(evaluation_id)
eval_dict = evaluation.to_dict_api()
eval_dict["etat"] = eval_etat.to_dict()
# eval_dict["nb_inscrits"] = modimpl_results.nb_inscrits_module
# eval_dict["nb_notes_manquantes"] = len(
# modimpl_results.evals_etudids_sans_note[evaluation.id]
# )
# eval_dict["nb_notes_abs"] = sum(
# modimpl_results.evals_notes[evaluation.id] == scu.NOTES_ABSENCE
# )
# eval_dict["nb_notes_att"] = eval_etat.nb_attente
# eval_dict["nb_notes_exc"] = sum(
# modimpl_results.evals_notes[evaluation.id] == scu.NOTES_NEUTRALISE
# )
eval_dict["nb_inscrits"] = modimpl_results.nb_inscrits_module
eval_dict["nb_notes_manquantes"] = len(
modimpl_results.evals_etudids_sans_note[evaluation.id]
)
eval_dict["nb_notes_abs"] = sum(
modimpl_results.evals_notes[evaluation.id] == scu.NOTES_ABSENCE
)
eval_dict["nb_notes_att"] = eval_etat.nb_attente
eval_dict["nb_notes_exc"] = sum(
modimpl_results.evals_notes[evaluation.id] == scu.NOTES_NEUTRALISE
)
# # Récupération de toutes les notes de l'évaluation
# # eval["notes"] = modimpl_results.get_eval_notes_dict(evaluation_id)
# Récupération de toutes les notes de l'évaluation
# eval["notes"] = modimpl_results.get_eval_notes_dict(evaluation_id)
# notes = NotesNotes.query.filter_by(evaluation_id=evaluation.id).all()
notes = NotesNotes.query.filter_by(evaluation_id=evaluation.id).all()
# date_debut = None
# date_fin = None
# date_mediane = None
date_debut = None
date_fin = None
date_mediane = None
# # Si il y a plus d'une note saisie pour l'évaluation
# if len(notes) >= 1:
# # Tri des notes en fonction de leurs dates
# notes_sorted = sorted(notes, key=attrgetter("date"))
# Si il y a plus d'une note saisie pour l'évaluation
if len(notes) >= 1:
# Tri des notes en fonction de leurs dates
notes_sorted = sorted(notes, key=attrgetter("date"))
# date_debut = notes_sorted[0].date
# date_fin = notes_sorted[-1].date
date_debut = notes_sorted[0].date
date_fin = notes_sorted[-1].date
# # Note médiane
# date_mediane = notes_sorted[len(notes_sorted) // 2].date
# Note médiane
date_mediane = notes_sorted[len(notes_sorted) // 2].date
# eval_dict["saisie_notes"] = {
# "datetime_debut": date_debut.isoformat()
# if date_debut is not None
# else None,
# "datetime_fin": date_fin.isoformat() if date_fin is not None else None,
# "datetime_mediane": date_mediane.isoformat()
# if date_mediane is not None
# else None,
# }
eval_dict["saisie_notes"] = {
"datetime_debut": date_debut.isoformat()
if date_debut is not None
else None,
"datetime_fin": date_fin.isoformat() if date_fin is not None else None,
"datetime_mediane": date_mediane.isoformat()
if date_mediane is not None
else None,
}
# list_eval.append(eval_dict)
list_eval.append(eval_dict)
# modimpl_dict["evaluations"] = list_eval
# result.append(modimpl_dict)
# return result
modimpl_dict["evaluations"] = list_eval
result.append(modimpl_dict)
return result
@bp.route("/formsemestre/<int:formsemestre_id>/resultats")

View File

@ -188,12 +188,12 @@ class ModuleImplResults:
if evaluation.publish_incomplete:
# et en "imédiat", tous ceux sans note
eval_etudids_attente |= etudids_sans_note
# Synthèe pour état du module:
# Synthèse pour état du module:
self.etudids_attente |= eval_etudids_attente
self.evaluations_etat[evaluation.id] = EvaluationEtat(
evaluation_id=evaluation.id,
nb_attente=len(eval_etudids_attente),
nb_notes=nb_notes,
nb_notes=int(nb_notes),
is_complete=is_complete,
)
# au moins une note en attente (ATT ou manquante en mode "immédiat") dans ce modimpl:

View File

@ -619,7 +619,6 @@ def test_formsemestre_programme(api_headers):
assert verify_fields(sae, MODIMPL_FIELDS)
@pytest.mark.skip # XXX WIP
def test_etat_evals(api_headers): # voir si on maintient cette route ?
"""
Route : /formsemestre/<int:formsemestre_id>/etat_evals