API: /formsemestre/<int:formsemestre_id>/resultats

This commit is contained in:
Emmanuel Viennet 2022-07-21 16:46:07 +02:00
parent d36a2950d3
commit cfd4448ca5
5 changed files with 62 additions and 5 deletions

View File

@ -18,7 +18,7 @@ from app.comp.moy_mod import ModuleImplResults
from app.comp.res_compat import NotesTableCompat from app.comp.res_compat import NotesTableCompat
from app.models import Evaluation, FormSemestre, FormSemestreEtape, ModuleImpl from app.models import Evaluation, FormSemestre, FormSemestreEtape, ModuleImpl
from app.scodoc.sco_bulletins import get_formsemestre_bulletin_etud_json from app.scodoc.sco_bulletins import get_formsemestre_bulletin_etud_json
from app.scodoc.sco_groups import get_etud_groups from app.scodoc import sco_groups
from app.scodoc.sco_permissions import Permission from app.scodoc.sco_permissions import Permission
from app.scodoc.sco_utils import ModuleType from app.scodoc.sco_utils import ModuleType
import app.scodoc.sco_utils as scu import app.scodoc.sco_utils as scu
@ -257,8 +257,9 @@ def formsemestre_etudiants(formsemestre_id: int, etat: str):
inscriptions = [ins for ins in formsemestre.inscriptions if ins.etat == etat] inscriptions = [ins for ins in formsemestre.inscriptions if ins.etat == etat]
etuds = [ins.etud.to_dict_short() for ins in inscriptions] etuds = [ins.etud.to_dict_short() for ins in inscriptions]
# Ajout des groupes de chaque étudiants # Ajout des groupes de chaque étudiants
# XXX A REVOIR: trop inefficace !
for etud in etuds: for etud in etuds:
etud["groups"] = get_etud_groups(etud["id"], formsemestre_id) etud["groups"] = sco_groups.get_etud_groups(etud["id"], formsemestre_id)
return jsonify(etuds) return jsonify(etuds)
@ -368,3 +369,28 @@ def etat_evals(formsemestre_id: int):
result.append(modimpl_dict) result.append(modimpl_dict)
return jsonify(result) return jsonify(result)
@bp.route("/formsemestre/<int:formsemestre_id>/resultats", methods=["GET"])
@token_auth.login_required
@token_permission_required(Permission.APIView)
def formsemestre_resultat(formsemestre_id: int):
"""Tableau récapitulatif des résultats
Pour chaque étudiant, son état, ses groupes, ses moyennes d'UE et de modules.
"""
formsemestre = FormSemestre.query.get_or_404(formsemestre_id)
app.set_sco_dept(formsemestre.departement.acronym)
res: NotesTableCompat = res_sem.load_formsemestre_results(formsemestre)
rows, footer_rows, titles, column_ids = res.get_table_recap(
convert_values=False,
include_evaluations=False,
mode_jury=False,
allow_html=False,
)
# Supprime les champs inutiles (mise en forme)
table = [{k: row[k] for k in row if not k[0] == "_"} for row in rows]
# Ajoute les groupes
etud_groups = sco_groups.get_formsemestre_etuds_groups(formsemestre_id)
for row in table:
row["partitions"] = etud_groups.get(row["etudid"], {})
return jsonify(table)

View File

@ -426,9 +426,16 @@ class ResultatsSemestre(ResultatsCache):
# --- TABLEAU RECAP # --- TABLEAU RECAP
def get_table_recap( def get_table_recap(
self, convert_values=False, include_evaluations=False, mode_jury=False self,
convert_values=False,
include_evaluations=False,
mode_jury=False,
allow_html=True,
): ):
"""Result: tuple avec """Table récap. des résultats.
allow_html: si vri, peut-mettre du HTML dans les valeurs
Result: tuple avec
- rows: liste de dicts { column_id : value } - rows: liste de dicts { column_id : value }
- titles: { column_id : title } - titles: { column_id : title }
- columns_ids: (liste des id de colonnes) - columns_ids: (liste des id de colonnes)
@ -591,7 +598,7 @@ class ResultatsSemestre(ResultatsCache):
row, row,
f"bonus_ue_{ue.id}", f"bonus_ue_{ue.id}",
f"Bonus {ue.acronyme}", f"Bonus {ue.acronyme}",
val_fmt_html, val_fmt_html if allow_html else val_fmt,
"col_ue_bonus", "col_ue_bonus",
idx, idx,
) )

View File

@ -179,6 +179,24 @@ def get_formsemestre_groups(formsemestre_id, with_default=False):
return partitions, partitions_etud_groups return partitions, partitions_etud_groups
def get_formsemestre_etuds_groups(formsemestre_id: int) -> dict:
"""{ etudid : { partition_id : group_id } }"""
infos = ndb.SimpleDictFetch(
"""SELECT etudid, p.id AS partition_id, gd.id AS group_id
FROM group_descr gd, group_membership gm, partition p
WHERE gd.partition_id = p.id
AND gm.group_id = gd.id
AND p.formsemestre_id = %(formsemestre_id)s
""",
{"formsemestre_id": formsemestre_id},
)
# -> {'etudid': 16483, 'group_id': 5317, 'partition_id': 2264},
d = collections.defaultdict(lambda: {})
for i in infos:
d[i["etudid"]][i["partition_id"]] = i["group_id"]
return d
def get_partition_groups(partition): def get_partition_groups(partition):
"""List of groups in this partition (list of dicts). """List of groups in this partition (list of dicts).
Some groups may be empty.""" Some groups may be empty."""

View File

@ -65,6 +65,8 @@ class DevConfig(Config):
os.environ.get("SCODOC_DATABASE_URI") or "postgresql:///SCODOC_DEV" os.environ.get("SCODOC_DATABASE_URI") or "postgresql:///SCODOC_DEV"
) )
SECRET_KEY = os.environ.get("DEV_SECRET_KEY") or "bb3faec7d9a34eb68a8e3e710087d87a" SECRET_KEY = os.environ.get("DEV_SECRET_KEY") or "bb3faec7d9a34eb68a8e3e710087d87a"
# pour le avoir url_for dans le shell:
# SERVER_NAME = os.environ.get("SCODOC_TEST_SERVER_NAME") or "localhost"
class TestConfig(DevConfig): class TestConfig(DevConfig):

View File

@ -176,6 +176,10 @@ POST_JSON(f"/partition/{2379}/delete")
# Recherche de formsemestres # Recherche de formsemestres
sems = GET(f"/formsemestres/query?etape_apo=V1RT&annee_scolaire=2021") sems = GET(f"/formsemestres/query?etape_apo=V1RT&annee_scolaire=2021")
# Table récap:
pp(GET(f"/formsemestre/1063/resultats")[0])
pp(GET(f"/formsemestre/880/resultats")[0])
# # sems est une liste de semestres (dictionnaires) # # sems est une liste de semestres (dictionnaires)
# for sem in sems: # for sem in sems: