From 45c845d23bb92c1b3311a5b21feb63ba06b61fe8 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Sun, 13 Feb 2022 15:50:16 +0100 Subject: [PATCH] was_capitalized / optim. -nt --- app/comp/res_common.py | 12 +++++- app/scodoc/sco_formsemestre_inscriptions.py | 17 ++++++--- app/scodoc/sco_moduleimpl_inscriptions.py | 8 +++- app/scodoc/sco_report.py | 42 ++++++++++----------- scodoc.py | 1 + 5 files changed, 52 insertions(+), 28 deletions(-) diff --git a/app/comp/res_common.py b/app/comp/res_common.py index 006cbe6b9..5b9ef625f 100644 --- a/app/comp/res_common.py +++ b/app/comp/res_common.py @@ -219,6 +219,7 @@ class ResultatsSemestre(ResultatsCache): if ue.type == UE_SPORT: return { "is_capitalized": False, + "was_capitalized": False, "is_external": False, "coef_ue": 0.0, "cur_moy_ue": 0.0, @@ -235,7 +236,10 @@ class ResultatsSemestre(ResultatsCache): self.validations = res_sem.load_formsemestre_validations(self.formsemestre) cur_moy_ue = self.etud_moy_ue[ue_id][etudid] moy_ue = cur_moy_ue - is_capitalized = False + is_capitalized = False # si l'UE prise en compte est une UE capitalisée + was_capitalized = ( + False # s'il y a precedemment une UE capitalisée (pas forcement meilleure) + ) if etudid in self.validations.ue_capitalisees.index: ue_cap = self._get_etud_ue_cap(etudid, ue) if ( @@ -243,6 +247,7 @@ class ResultatsSemestre(ResultatsCache): and not ue_cap.empty and not np.isnan(ue_cap["moy_ue"]) ): + was_capitalized = True if ue_cap["moy_ue"] > cur_moy_ue or np.isnan(cur_moy_ue): moy_ue = ue_cap["moy_ue"] is_capitalized = True @@ -251,6 +256,7 @@ class ResultatsSemestre(ResultatsCache): return { "is_capitalized": is_capitalized, + "was_capitalized": was_capitalized, "is_external": ue_cap["is_external"] if is_capitalized else ue.is_external, "coef_ue": coef_ue, "ects_pot": ue.ects or 0.0, @@ -425,6 +431,10 @@ class NotesTableCompat(ResultatsSemestre): ue_status_list.append(ue_status) return self.parcours.check_barre_ues(ue_status_list) + def etud_has_decision(self, etudid): + """True s'il y a une décision de jury pour cet étudiant""" + return self.get_etud_decision_ues(etudid) or self.get_etud_decision_sem(etudid) + def get_etud_decision_ues(self, etudid: int) -> dict: """Decisions du jury pour les UE de cet etudiant, ou None s'il n'y en pas eu. Ne tient pas compte des UE capitalisées. diff --git a/app/scodoc/sco_formsemestre_inscriptions.py b/app/scodoc/sco_formsemestre_inscriptions.py index 6ecfa32f2..3e398c837 100644 --- a/app/scodoc/sco_formsemestre_inscriptions.py +++ b/app/scodoc/sco_formsemestre_inscriptions.py @@ -32,14 +32,16 @@ import time import flask from flask import url_for, g, request +from app.comp import res_sem +from app.comp.res_common import NotesTableCompat +from app.models import FormSemestre import app.scodoc.sco_utils as scu from app import log from app.scodoc.scolog import logdb from app.scodoc.sco_exceptions import ScoException, ScoValueError -from app.scodoc.sco_permissions import Permission from app.scodoc.sco_codes_parcours import UE_STANDARD, UE_SPORT, UE_TYPE_NAME import app.scodoc.notesdb as ndb -from app.scodoc.TrivialFormulator import TrivialFormulator, TF +from app.scodoc.TrivialFormulator import TrivialFormulator from app.scodoc import sco_find_etud from app.scodoc import sco_formsemestre from app.scodoc import sco_moduleimpl @@ -186,7 +188,9 @@ def do_formsemestre_desinscription(etudid, formsemestre_id): raise ScoValueError("desinscription impossible: semestre verrouille") # -- Si decisions de jury, desinscription interdite - nt = sco_cache.NotesTableCache.get(formsemestre_id) + formsemestre = FormSemestre.query.get_or_404(formsemestre_id) + nt: NotesTableCompat = res_sem.load_formsemestre_results(formsemestre) + if nt.etud_has_decision(etudid): raise ScoValueError( "desinscription impossible: l'étudiant a une décision de jury (la supprimer avant si nécessaire)" @@ -475,7 +479,8 @@ def formsemestre_inscription_option(etudid, formsemestre_id): raise ScoValueError("Modification impossible: semestre verrouille") etud = sco_etud.get_etud_info(etudid=etudid, filled=True)[0] - nt = sco_cache.NotesTableCache.get(formsemestre_id) + formsemestre = FormSemestre.query.get_or_404(formsemestre_id) + nt: NotesTableCompat = res_sem.load_formsemestre_results(formsemestre) F = html_sco_header.sco_footer() H = [ @@ -785,7 +790,9 @@ def list_inscrits_ailleurs(formsemestre_id): Pour chacun, donne la liste des semestres. { etudid : [ liste de sems ] } """ - nt = sco_cache.NotesTableCache.get(formsemestre_id) # > get_etudids + formsemestre = FormSemestre.query.get_or_404(formsemestre_id) + nt: NotesTableCompat = res_sem.load_formsemestre_results(formsemestre) + etudids = nt.get_etudids() d = {} for etudid in etudids: diff --git a/app/scodoc/sco_moduleimpl_inscriptions.py b/app/scodoc/sco_moduleimpl_inscriptions.py index cbd9a3b0d..a0266219f 100644 --- a/app/scodoc/sco_moduleimpl_inscriptions.py +++ b/app/scodoc/sco_moduleimpl_inscriptions.py @@ -33,6 +33,10 @@ import flask from flask import url_for, g, request from flask_login import current_user +from app.comp import res_sem +from app.comp.res_common import NotesTableCompat +from app.models import FormSemestre + import app.scodoc.notesdb as ndb import app.scodoc.sco_utils as scu from app import log @@ -479,7 +483,9 @@ def get_etuds_with_capitalized_ue(formsemestre_id): returns { ue_id : [ { infos } ] } """ UECaps = scu.DictDefault(defaultvalue=[]) - nt = sco_cache.NotesTableCache.get(formsemestre_id) + formsemestre = FormSemestre.query.get_or_404(formsemestre_id) + nt: NotesTableCompat = res_sem.load_formsemestre_results(formsemestre) + inscrits = sco_formsemestre_inscriptions.do_formsemestre_inscription_list( args={"formsemestre_id": formsemestre_id} ) diff --git a/app/scodoc/sco_report.py b/app/scodoc/sco_report.py index 6c2582ef1..fff026471 100644 --- a/app/scodoc/sco_report.py +++ b/app/scodoc/sco_report.py @@ -39,14 +39,16 @@ from operator import itemgetter from flask import url_for, g, request import pydot +from app.comp import res_sem +from app.comp.res_common import NotesTableCompat +from app.models import FormSemestre + import app.scodoc.sco_utils as scu from app.models import FormationModalite from app.scodoc import notesdb as ndb from app.scodoc import html_sco_header from app.scodoc import sco_codes_parcours -from app.scodoc import sco_cache from app.scodoc import sco_etud -from app.scodoc import sco_excel from app.scodoc import sco_formsemestre from app.scodoc import sco_formsemestre_inscriptions from app.scodoc import sco_parcours_dut @@ -61,9 +63,9 @@ MAX_ETUD_IN_DESCR = 20 def formsemestre_etuds_stats(sem, only_primo=False): """Récupère liste d'etudiants avec etat et decision.""" - nt = sco_cache.NotesTableCache.get( - sem["formsemestre_id"] - ) # > get_table_moyennes_triees, identdict, get_etud_decision_sem, get_etud_etat, + formsemestre = FormSemestre.query.get_or_404(sem["formsemestre_id"]) + nt: NotesTableCompat = res_sem.load_formsemestre_results(formsemestre) + T = nt.get_table_moyennes_triees() # Construit liste d'étudiants du semestre avec leur decision etuds = [] @@ -400,9 +402,8 @@ def table_suivi_cohorte( logt("table_suivi_cohorte: start") # 1-- Liste des semestres posterieurs dans lesquels ont été les etudiants de sem - nt = sco_cache.NotesTableCache.get( - formsemestre_id - ) # > get_etudids, get_etud_decision_sem + formsemestre = FormSemestre.query.get_or_404(formsemestre_id) + nt: NotesTableCompat = res_sem.load_formsemestre_results(formsemestre) etudids = nt.get_etudids() logt("A: orig etuds set") @@ -456,9 +457,8 @@ def table_suivi_cohorte( s["members"] = orig_set.intersection(inset) nb_dipl = 0 # combien de diplomes dans ce semestre ? if s["semestre_id"] == nt.parcours.NB_SEM: - nt = sco_cache.NotesTableCache.get( - s["formsemestre_id"] - ) # > get_etud_decision_sem + s_formsemestre = FormSemestre.query.get_or_404(s["formsemestre_id"]) + nt: NotesTableCompat = res_sem.load_formsemestre_results(s_formsemestre) for etudid in s["members"]: dec = nt.get_etud_decision_sem(etudid) if dec and code_semestre_validant(dec["code"]): @@ -905,9 +905,9 @@ def _descr_etud_set(etudids): def _count_dem_reo(formsemestre_id, etudids): "count nb of demissions and reorientation in this etud set" - nt = sco_cache.NotesTableCache.get( - formsemestre_id - ) # > get_etud_etat, get_etud_decision_sem + formsemestre = FormSemestre.query.get_or_404(formsemestre_id) + nt: NotesTableCompat = res_sem.load_formsemestre_results(formsemestre) + dems = set() reos = set() for etudid in etudids: @@ -971,9 +971,9 @@ def get_codeparcoursetud(etud, prefix="", separator=""): i = len(sems) - 1 while i >= 0: s = sems[i] # 'sems' est a l'envers, du plus recent au plus ancien - nt = sco_cache.NotesTableCache.get( - s["formsemestre_id"] - ) # > get_etud_etat, get_etud_decision_sem + s_formsemestre = FormSemestre.query.get_or_404(s["formsemestre_id"]) + nt: NotesTableCompat = res_sem.load_formsemestre_results(s_formsemestre) + p.append(_codesem(s, prefix=prefix)) # code decisions jury de chaque semestre: if nt.get_etud_etat(etud["etudid"]) == "D": @@ -1017,7 +1017,8 @@ def tsp_etud_list( """ # log('tsp_etud_list(%s, bac="%s")' % (formsemestre_id,bac)) sem = sco_formsemestre.get_formsemestre(formsemestre_id) - nt = sco_cache.NotesTableCache.get(formsemestre_id) # > get_etudids, + formsemestre = FormSemestre.query.get_or_404(formsemestre_id) + nt: NotesTableCompat = res_sem.load_formsemestre_results(formsemestre) etudids = nt.get_etudids() etuds = [] bacs = set() @@ -1260,9 +1261,8 @@ def graph_parcours( nxt = {} etudid = etud["etudid"] for s in etud["sems"]: # du plus recent au plus ancien - nt = sco_cache.NotesTableCache.get( - s["formsemestre_id"] - ) # > get_etud_decision_sem, get_etud_etat + s_formsemestre = FormSemestre.query.get_or_404(s["formsemestre_id"]) + nt: NotesTableCompat = res_sem.load_formsemestre_results(s_formsemestre) dec = nt.get_etud_decision_sem(etudid) if nxt: if ( diff --git a/scodoc.py b/scodoc.py index 5b76ccb0e..4dc5165f7 100755 --- a/scodoc.py +++ b/scodoc.py @@ -434,6 +434,7 @@ def localize_logo(logo: str = None, dept: str = None): # migrate-scodoc7-dept-l @click.argument("xlsfile", type=click.File("rb")) @click.argument("zipfile", type=click.File("rb")) def photos_import_files(formsemestre_id: int, xlsfile: str, zipfile: str): + """Import des photos d'étudiants à partir d'une liste excel et d'un zip avec les images.""" import app as mapp from app.scodoc import sco_trombino, sco_photos from app.scodoc import notesdb as ndb