From 504b12cadbb9aa02f589368178937be8de4a7665 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Sat, 20 Nov 2021 17:21:51 +0100 Subject: [PATCH] evaluation_listenotes: petite optim --- app/api/auth.py | 1 - app/scodoc/sco_etud.py | 4 ++-- app/scodoc/sco_groups.py | 6 ++++-- app/scodoc/sco_liste_notes.py | 28 +++++++++++----------------- app/scodoc/sco_placement.py | 13 +++---------- app/scodoc/sco_saisie_notes.py | 31 ++++++++++++++++++++----------- 6 files changed, 40 insertions(+), 43 deletions(-) diff --git a/app/api/auth.py b/app/api/auth.py index bb8464e0..958001ee 100644 --- a/app/api/auth.py +++ b/app/api/auth.py @@ -33,7 +33,6 @@ token_auth = HTTPTokenAuth() @basic_auth.verify_password def verify_password(username, password): - # breakpoint() user = User.query.filter_by(user_name=username).first() if user and user.check_password(password): return user diff --git a/app/scodoc/sco_etud.py b/app/scodoc/sco_etud.py index 5fc1242f..4c96f526 100644 --- a/app/scodoc/sco_etud.py +++ b/app/scodoc/sco_etud.py @@ -657,8 +657,8 @@ def log_unknown_etud(): def get_etud_info(etudid=False, code_nip=False, filled=False) -> list: """infos sur un etudiant (API). If not found, returns empty list. - On peut specifier etudid ou code_nip - ou bien cherche dans les argumenst de la requête courante: + On peut spécifier etudid ou code_nip + ou bien cherche dans les arguments de la requête courante: etudid, code_nip, code_ine (dans cet ordre). """ if etudid is None: diff --git a/app/scodoc/sco_groups.py b/app/scodoc/sco_groups.py index 4d84f2a2..f8b84fb4 100644 --- a/app/scodoc/sco_groups.py +++ b/app/scodoc/sco_groups.py @@ -1424,6 +1424,8 @@ def do_evaluation_listeetuds_groups( evaluation. Si include_dems, compte aussi les etudiants démissionnaires (sinon, par défaut, seulement les 'I') + + Résultat: [ (etudid, etat) ], où etat='I', 'D', 'DEF' """ # nb: pour notes_table / do_evaluation_etat, getallstudents est vrai et include_dems faux fromtables = [ @@ -1448,7 +1450,7 @@ def do_evaluation_listeetuds_groups( # requete complete req = ( - "SELECT distinct Im.etudid FROM " + "SELECT distinct Im.etudid, Isem.etat FROM " + ", ".join(fromtables) + """ WHERE Isem.etudid = Im.etudid and Im.moduleimpl_id = M.id @@ -1463,7 +1465,7 @@ def do_evaluation_listeetuds_groups( cnx = ndb.GetDBConnexion() cursor = cnx.cursor() cursor.execute(req, {"evaluation_id": evaluation_id}) - return [x[0] for x in cursor] + return cursor.fetchall() def do_evaluation_listegroupes(evaluation_id, include_default=False): diff --git a/app/scodoc/sco_liste_notes.py b/app/scodoc/sco_liste_notes.py index 8df208fa..1cd71d61 100644 --- a/app/scodoc/sco_liste_notes.py +++ b/app/scodoc/sco_liste_notes.py @@ -222,7 +222,7 @@ def _make_table_notes( with_emails=False, group_ids=[], ): - """Generate table for evaluations marks""" + """Table liste notes (une seule évaluation ou toutes celles d'un module)""" if not evals: return "

Aucune évaluation !

" E = evals[0] @@ -247,7 +247,7 @@ def _make_table_notes( gr_title = sco_groups.listgroups_abbrev(groups) gr_title_filename = sco_groups.listgroups_filename(groups) - etudids = sco_groups.do_evaluation_listeetuds_groups( + etudid_etats = sco_groups.do_evaluation_listeetuds_groups( E["evaluation_id"], groups, include_dems=True ) @@ -285,24 +285,20 @@ def _make_table_notes( return str(r) K = keymgr() - for etudid in etudids: + for etudid, etat in etudid_etats: css_row_class = None # infos identite etudiant etud = sco_etud.get_etud_info(etudid=etudid, filled=True)[0] - # infos inscription - inscr = sco_formsemestre_inscriptions.do_formsemestre_inscription_list( - {"etudid": etudid, "formsemestre_id": M["formsemestre_id"]} - )[0] - if inscr["etat"] == "I": # si inscrit, indique groupe + if etat == "I": # si inscrit, indique groupe groups = sco_groups.get_etud_groups(etudid, sem) grc = sco_groups.listgroups_abbrev(groups) else: - if inscr["etat"] == "D": + if etat == "D": grc = "DEM" # attention: ce code est re-ecrit plus bas, ne pas le changer (?) css_row_class = "etuddem" else: - grc = inscr["etat"] + grc = etat code = "" # code pour listings anonyme, à la place du nom if sco_preferences.get_preference("anonymous_lst_code") == "INE": @@ -435,7 +431,7 @@ def _make_table_notes( gl = "&with_emails%3Alist=yes" + gl if len(evals) == 1: evalname = "%s-%s" % (Mod["code"], ndb.DateDMYtoISO(E["jour"])) - hh = "%s, %s (%d étudiants)" % (E["description"], gr_title, len(etudids)) + hh = "%s, %s (%d étudiants)" % (E["description"], gr_title, len(etudid_etats)) filename = scu.make_filename("notes_%s_%s" % (evalname, gr_title_filename)) caption = hh pdf_title = "%(description)s (%(jour)s)" % e @@ -713,10 +709,6 @@ def evaluation_check_absences(evaluation_id): if not E["jour"]: return [], [], [], [], [] # evaluation sans date - etudids = sco_groups.do_evaluation_listeetuds_groups( - evaluation_id, getallstudents=True - ) - am, pm, demijournee = _eval_demijournee(E) # Liste les absences à ce moment: @@ -736,7 +728,9 @@ def evaluation_check_absences(evaluation_id): ExcNonSignalee = [] # note EXC mais pas noté absent ExcNonJust = [] # note EXC mais absent non justifie AbsButExc = [] # note ABS mais justifié - for etudid in etudids: + for etudid, _ in sco_groups.do_evaluation_listeetuds_groups( + evaluation_id, getallstudents=True + ): if etudid in NotesDB: val = NotesDB[etudid]["value"] if ( @@ -761,7 +755,7 @@ def evaluation_check_absences(evaluation_id): def evaluation_check_absences_html(evaluation_id, with_header=True, show_ok=True): - """Affiche etat verification absences d'une evaluation""" + """Affiche état vérification absences d'une évaluation""" E = sco_evaluation_db.do_evaluation_list({"evaluation_id": evaluation_id})[0] am, pm, demijournee = _eval_demijournee(E) diff --git a/app/scodoc/sco_placement.py b/app/scodoc/sco_placement.py index 5c7128bf..165a766b 100644 --- a/app/scodoc/sco_placement.py +++ b/app/scodoc/sco_placement.py @@ -303,24 +303,17 @@ class PlacementRunner: get_all_students = None in [ g["group_name"] for g in self.groups ] # tous les etudiants - etudids = sco_groups.do_evaluation_listeetuds_groups( + etudid_etats = sco_groups.do_evaluation_listeetuds_groups( self.evaluation_id, self.groups, getallstudents=get_all_students, include_dems=True, ) listetud = [] # liste de couples (nom,prenom) - for etudid in etudids: + for etudid, etat in etudid_etats: # infos identite etudiant (xxx sous-optimal: 1/select par etudiant) ident = sco_etud.etudident_list(ndb.GetDBConnexion(), {"etudid": etudid})[0] - # infos inscription - inscr = sco_formsemestre_inscriptions.do_formsemestre_inscription_list( - { - "etudid": etudid, - "formsemestre_id": self.moduleimpl_data["formsemestre_id"], - } - )[0] - if inscr["etat"] != "D": + if etat != "D": nom = ident["nom"].upper() prenom = ident["prenom"].lower().capitalize() etudid = ident["etudid"] diff --git a/app/scodoc/sco_saisie_notes.py b/app/scodoc/sco_saisie_notes.py index b6c000ab..bd075df1 100644 --- a/app/scodoc/sco_saisie_notes.py +++ b/app/scodoc/sco_saisie_notes.py @@ -309,11 +309,11 @@ def do_evaluation_set_missing(evaluation_id, value, dialog_confirmed=False): raise AccessDenied("Modification des notes impossible pour %s" % current_user) # NotesDB = sco_evaluation_db.do_evaluation_get_all_notes(evaluation_id) - etudids = sco_groups.do_evaluation_listeetuds_groups( + etudid_etats = sco_groups.do_evaluation_listeetuds_groups( evaluation_id, getallstudents=True, include_dems=False ) notes = [] - for etudid in etudids: # pour tous les inscrits + for etudid, _ in etudid_etats: # pour tous les inscrits if etudid not in NotesDB: # pas de note notes.append((etudid, value)) # Check value @@ -468,12 +468,15 @@ def _notes_add(user, evaluation_id: int, notes: list, comment=None, do_it=True): *time.localtime()[:6] ) # datetime.datetime.now().isoformat() # Verifie inscription et valeur note - _ = {}.fromkeys( - sco_groups.do_evaluation_listeetuds_groups( + inscrits = { + x[0] + for x in sco_groups.do_evaluation_listeetuds_groups( evaluation_id, getallstudents=True, include_dems=True ) - ) + } for (etudid, value) in notes: + if etudid not in inscrits: + raise NoteProcessError("etudiant non inscrit dans ce module") if not ((value is None) or (type(value) == type(1.0))): raise NoteProcessError( "etudiant %s: valeur de note invalide (%s)" % (etudid, value) @@ -816,9 +819,12 @@ def feuille_saisie_notes(evaluation_id, group_ids=[]): gr_title_filename = "tous" else: getallstudents = False - etudids = sco_groups.do_evaluation_listeetuds_groups( - evaluation_id, groups, getallstudents=getallstudents, include_dems=True - ) + etudids = [ + x[0] + for x in sco_groups.do_evaluation_listeetuds_groups( + evaluation_id, groups, getallstudents=getallstudents, include_dems=True + ) + ] # une liste de liste de chaines: lignes de la feuille de calcul L = [] @@ -1059,9 +1065,12 @@ def _form_saisie_notes(E, M, group_ids, destination=""): evaluation_id = E["evaluation_id"] formsemestre_id = M["formsemestre_id"] - etudids = sco_groups.do_evaluation_listeetuds_groups( - evaluation_id, getallstudents=True, include_dems=True - ) + etudids = [ + x[0] + for x in sco_groups.do_evaluation_listeetuds_groups( + evaluation_id, getallstudents=True, include_dems=True + ) + ] if not etudids: return '
Aucun étudiant sélectionné !
'