From 0c05c4f31d38be92abd8ec83e15291ab9a55c83a Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Mon, 27 Jun 2022 18:41:54 +0200 Subject: [PATCH] =?UTF-8?q?Jury=20BUT:=20fix=20pour=20cas=20GB=20avec=20Na?= =?UTF-8?q?N=20+=20pr=C3=A9sentation=20btableau=20multi-parcours?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/but/jury_but_recap.py | 52 +++++++++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 10 deletions(-) diff --git a/app/but/jury_but_recap.py b/app/but/jury_but_recap.py index dc30f4f3..a3a0e0a6 100644 --- a/app/but/jury_but_recap.py +++ b/app/but/jury_but_recap.py @@ -8,6 +8,7 @@ """ import time +import numpy as np from flask import g, url_for from app.but import jury_but @@ -182,9 +183,16 @@ def build_table_jury_but_html( class RowCollector: """Une ligne de la table""" - def __init__(self, cells: dict = None, titles: dict = None, convert_values=True): + def __init__( + self, + cells: dict = None, + titles: dict = None, + convert_values=True, + column_classes: dict = None, + ): self.titles = titles self.row = cells or {} # col_id : str + self.column_classes = column_classes # col_id : str, css class self.idx = 0 self.last_etud_cell_idx = 0 if convert_values: @@ -198,6 +206,17 @@ class RowCollector: def __getitem__(self, key): return self.row[key] + def get_row_dict(self): + "La ligne, comme un dict" + # create empty cells + for col_id in self.titles: + if col_id not in self.row: + self.row[col_id] = "" + klass = self.column_classes.get(col_id) + if klass: + self.row[f"_{col_id}_class"] = klass + return self.row + def add_cell( self, col_id: str, @@ -205,8 +224,9 @@ class RowCollector: content: str, classes: str = "", idx: int = None, + column_class="", ): - "Add a row to our table. classes is a list of css class names" + """Add a row to our table. classes is a list of css class names""" self.idx = idx if idx is not None else self.idx self.row[col_id] = content if classes: @@ -216,6 +236,7 @@ class RowCollector: self.titles[f"_{col_id}_col_order"] = self.idx if classes: self.titles[f"_{col_id}_class"] = classes + self.column_classes[col_id] = column_class self.idx += 1 def add_etud_cells(self, etud: Identite, formsemestre: FormSemestre): @@ -254,13 +275,18 @@ class RowCollector: if val < BUT_BARRE_UE8: note_class = " moy_ue_warning" # notes très basses self.add_cell( - col_id, dec_ue.ue.acronyme, self.fmt_note(val), "col_ue" + note_class + col_id, + dec_ue.ue.acronyme, + self.fmt_note(val), + "col_ue" + note_class, + column_class="col_ue", ) self.add_cell( col_id + "_code", dec_ue.ue.acronyme, dec_ue.code_valide or "", "col_ue_code recorded_code", + column_class="col_ue", ) def add_rcue_cells(self, dec_rcue: DecisionsProposeesRCUE): @@ -308,7 +334,11 @@ class RowCollector: if len(deca.rcues_annee) > 0: # permet un tri par nb de niveaux validables + moyenne gen indicative S_pair if deca.res_pair and deca.etud.id in deca.res_pair.etud_moy_gen: - moy_gen_d = f"{int(deca.res_pair.etud_moy_gen[deca.etud.id]*1000):05}" + moy = deca.res_pair.etud_moy_gen[deca.etud.id] + if np.isnan(moy): + moy_gen_d = "x" + else: + moy_gen_d = f"{int(moy*1000):05}" else: moy_gen_d = "x" self["_rcues_validables_order"] = f"{deca.nb_validables:04d}-{moy_gen_d}" @@ -326,11 +356,12 @@ def get_table_jury_but( """Construit la table des résultats annuels pour le jury BUT""" res2: ResultatsSemestreBUT = res_sem.load_formsemestre_results(formsemestre2) titles = {} # column_id : title + column_classes = {} rows = [] for etudid in formsemestre2.etuds_inscriptions: etud: Identite = Identite.query.get(etudid) deca = jury_but.DecisionsProposeesAnnee(etud, formsemestre2) - row = RowCollector(titles=titles) + row = RowCollector(titles=titles, column_classes=column_classes) row.add_etud_cells(etud, formsemestre2) row.idx = 100 # laisse place pour les colonnes de groupes # --- Nombre de niveaux @@ -365,10 +396,11 @@ def get_table_jury_but( """, "col_lien_saisie_but", ) - rows.append(row.row) - if len(rows) > 0: - res2.recap_add_partitions(rows, titles, col_idx=row.last_etud_cell_idx + 1) + rows.append(row) + rows_dict = [row.get_row_dict() for row in rows] + if len(rows_dict) > 0: + res2.recap_add_partitions(rows_dict, titles, col_idx=row.last_etud_cell_idx + 1) column_ids = [title for title in titles if not title.startswith("_")] column_ids.sort(key=lambda col_id: titles.get("_" + col_id + "_col_order", 1000)) - rows.sort(key=lambda row: row["_nom_disp_order"]) - return rows, titles, column_ids + rows_dict.sort(key=lambda row: row["_nom_disp_order"]) + return rows_dict, titles, column_ids