From 15aa786ddb7b91aac27f508d36acca24aefd2750 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Tue, 15 Feb 2022 13:21:57 +0100 Subject: [PATCH] Fix: calcul moy. gen. classique si aucun coef (mauvaise gestion du NaN). --- app/comp/moy_ue.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/comp/moy_ue.py b/app/comp/moy_ue.py index b0a534e51..e4aac3353 100644 --- a/app/comp/moy_ue.py +++ b/app/comp/moy_ue.py @@ -38,8 +38,8 @@ from app.comp import moy_mod from app.models.formsemestre import FormSemestre from app.scodoc import sco_codes_parcours from app.scodoc import sco_preferences -from app.scodoc.sco_codes_parcours import UE_SPORT -from app.scodoc.sco_utils import ModuleType +from app.scodoc.sco_codes_parcours import NOTES_TOLERANCE, UE_SPORT +from app.scodoc.sco_utils import NOTES_PRECISION, ModuleType def df_load_module_coefs(formation_id: int, semestre_idx: int = None) -> pd.DataFrame: @@ -358,10 +358,12 @@ def compute_ue_moys_classic( ) # nb_ue x nb_etuds x nb_mods : coefs prenant en compte NaN et inscriptions coefs = (modimpl_coefs_etuds_no_nan_stacked * ue_modules).swapaxes(1, 2) - with np.errstate(invalid="ignore"): # ignore les 0/0 (-> NaN) - etud_moy_ue = ( - np.sum(coefs * sem_matrix_inscrits, axis=2) / np.sum(coefs, axis=2) - ).T + # Ici c'est une division apr un scalaire, pas NumPy: il faut tester + sum_coefs = np.sum(coefs, axis=2) + if abs(sum_coefs) > NOTES_PRECISION: + etud_moy_ue = (np.sum(coefs * sem_matrix_inscrits, axis=2) / sum_coefs).T + else: + etud_moy_ue = np.nan etud_moy_ue_df = pd.DataFrame( etud_moy_ue, index=modimpl_inscr_df.index, columns=[ue.id for ue in ues] )