From 3dfb6f07bd0487791be7d494466caba177c67972 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Thu, 10 Feb 2022 22:19:15 +0100 Subject: [PATCH] Fix: calculs si aucun module --- app/comp/bonus_spo.py | 11 ++++++++--- app/comp/moy_ue.py | 14 ++++++++++++-- app/comp/res_classic.py | 2 ++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/app/comp/bonus_spo.py b/app/comp/bonus_spo.py index 60361c32c..7ea125972 100644 --- a/app/comp/bonus_spo.py +++ b/app/comp/bonus_spo.py @@ -87,6 +87,8 @@ class BonusSport: for m in formsemestre.modimpls_sorted ] ) + if not len(modimpl_mask): + modimpl_mask = np.s_[:] # il n'y a rien, on prend tout donc rien self.modimpls_spo = [ modimpl for i, modimpl in enumerate(formsemestre.modimpls_sorted) @@ -134,9 +136,12 @@ class BonusSport: modimpl_inscr_spo, sem_modimpl_moys_no_nan, 0.0 ) modimpl_coefs_spo = modimpl_coefs_spo.T - modimpl_coefs_etuds = np.where( - modimpl_inscr_spo, np.stack([modimpl_coefs_spo] * nb_etuds), 0.0 - ) + if nb_etuds == 0: + modimpl_coefs_etuds = modimpl_inscr_spo # vide + else: + modimpl_coefs_etuds = np.where( + modimpl_inscr_spo, np.stack([modimpl_coefs_spo] * nb_etuds), 0.0 + ) # Annule les coefs des modules NaN (nb_etuds x nb_mod_sport) modimpl_coefs_etuds_no_nan = np.where( np.isnan(sem_modimpl_moys_spo), 0.0, modimpl_coefs_etuds diff --git a/app/comp/moy_ue.py b/app/comp/moy_ue.py index 8a8057ac3..1d50edc1e 100644 --- a/app/comp/moy_ue.py +++ b/app/comp/moy_ue.py @@ -310,6 +310,15 @@ def compute_ue_moys_classic( les coefficients effectifs de chaque UE pour chaque étudiant (sommes de coefs de modules pris en compte) """ + if not len(modimpl_mask): # aucun module + # etud_moy_gen_s, etud_moy_ue_df, etud_coef_ue_df + return ( + pd.Series( + [0.0] * len(modimpl_inscr_df.index), index=modimpl_inscr_df.index + ), + pd.DataFrame(), + pd.DataFrame(), + ) # Restreint aux modules sélectionnés: sem_matrix = sem_matrix[:, modimpl_mask] modimpl_inscr = modimpl_inscr_df.values[:, modimpl_mask] @@ -415,8 +424,9 @@ def compute_malus( for m in formsemestre.modimpls_sorted ] ) - malus_moys = sem_modimpl_moys[:, modimpl_mask].sum(axis=1) - malus[ue.id] = malus_moys + if len(modimpl_mask): + malus_moys = sem_modimpl_moys[:, modimpl_mask].sum(axis=1) + malus[ue.id] = malus_moys malus.fillna(0.0, inplace=True) return malus diff --git a/app/comp/res_classic.py b/app/comp/res_classic.py index 0d8f32423..0a892f4b2 100644 --- a/app/comp/res_classic.py +++ b/app/comp/res_classic.py @@ -209,6 +209,8 @@ def notes_sem_assemble_matrix(modimpls_notes: list[pd.Series]) -> np.ndarray: (Series rendus par compute_module_moy, index: etud) Resultat: ndarray (etud x module) """ + if not len(modimpls_notes): + return np.zeros((0, 0), dtype=float) modimpls_notes_arr = [s.values for s in modimpls_notes] modimpls_notes = np.stack(modimpls_notes_arr) # passe de (mod x etud) à (etud x mod)