forked from ScoDoc/ScoDoc
Form. classiques: calcul de la moyenne gen. avec coefs d'UE
This commit is contained in:
parent
8570096eff
commit
c8459901b0
@ -36,6 +36,7 @@ from app.models import UniteEns, Module, ModuleImpl, ModuleUECoef
|
|||||||
from app.comp import moy_mod
|
from app.comp import moy_mod
|
||||||
from app.models.formsemestre import FormSemestre
|
from app.models.formsemestre import FormSemestre
|
||||||
from app.scodoc import sco_codes_parcours
|
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_codes_parcours import UE_SPORT
|
||||||
from app.scodoc.sco_utils import ModuleType
|
from app.scodoc.sco_utils import ModuleType
|
||||||
|
|
||||||
@ -314,7 +315,7 @@ def compute_ue_moys_classic(
|
|||||||
|
|
||||||
nb_etuds, nb_modules = sem_matrix.shape
|
nb_etuds, nb_modules = sem_matrix.shape
|
||||||
assert len(modimpl_coefs) == nb_modules
|
assert len(modimpl_coefs) == nb_modules
|
||||||
nb_ues = len(ues)
|
nb_ues = len(ues) # en comptant bonus
|
||||||
|
|
||||||
# Enlève les NaN du numérateur:
|
# Enlève les NaN du numérateur:
|
||||||
sem_matrix_no_nan = np.nan_to_num(sem_matrix, nan=0.0)
|
sem_matrix_no_nan = np.nan_to_num(sem_matrix, nan=0.0)
|
||||||
@ -329,13 +330,8 @@ def compute_ue_moys_classic(
|
|||||||
modimpl_coefs_etuds_no_nan = np.where(
|
modimpl_coefs_etuds_no_nan = np.where(
|
||||||
np.isnan(sem_matrix), 0.0, modimpl_coefs_etuds
|
np.isnan(sem_matrix), 0.0, modimpl_coefs_etuds
|
||||||
)
|
)
|
||||||
# Calcul des moyennes générales:
|
|
||||||
with np.errstate(invalid="ignore"): # ignore les 0/0 (-> NaN)
|
# --------------------- Calcul des moyennes d'UE
|
||||||
etud_moy_gen = np.sum(
|
|
||||||
modimpl_coefs_etuds_no_nan * sem_matrix_inscrits, axis=1
|
|
||||||
) / np.sum(modimpl_coefs_etuds_no_nan, axis=1)
|
|
||||||
etud_moy_gen_s = pd.Series(etud_moy_gen, index=modimpl_inscr_df.index)
|
|
||||||
# Calcul des moyennes d'UE
|
|
||||||
ue_modules = np.array(
|
ue_modules = np.array(
|
||||||
[[m.module.ue == ue for m in formsemestre.modimpls_sorted] for ue in ues]
|
[[m.module.ue == ue for m in formsemestre.modimpls_sorted] for ue in ues]
|
||||||
)[..., np.newaxis][:, modimpl_mask, :]
|
)[..., np.newaxis][:, modimpl_mask, :]
|
||||||
@ -351,9 +347,35 @@ def compute_ue_moys_classic(
|
|||||||
etud_moy_ue_df = pd.DataFrame(
|
etud_moy_ue_df = pd.DataFrame(
|
||||||
etud_moy_ue, index=modimpl_inscr_df.index, columns=[ue.id for ue in ues]
|
etud_moy_ue, index=modimpl_inscr_df.index, columns=[ue.id for ue in ues]
|
||||||
)
|
)
|
||||||
etud_coef_ue_df = pd.DataFrame(
|
|
||||||
coefs.sum(axis=2).T,
|
# --------------------- Calcul des moyennes générales
|
||||||
index=modimpl_inscr_df.index, # etudids
|
if sco_preferences.get_preference("use_ue_coefs", formsemestre.id):
|
||||||
columns=[ue.id for ue in ues],
|
# Cas avec coefficients d'UE forcés: (on met à zéro l'UE bonus)
|
||||||
)
|
etud_coef_ue_df = pd.DataFrame(
|
||||||
|
{ue.id: ue.coefficient if ue.type != UE_SPORT else 0.0 for ue in ues},
|
||||||
|
index=modimpl_inscr_df.index,
|
||||||
|
columns=[ue.id for ue in ues],
|
||||||
|
)
|
||||||
|
# remplace NaN par zéros dans les moyennes d'UE
|
||||||
|
etud_moy_ue_df_no_nan = etud_moy_ue_df.fillna(0.0, inplace=False)
|
||||||
|
# annule les coef d'UE si la moyenne d'UE est NaN
|
||||||
|
etud_coef_ue_df_no_nan = etud_coef_ue_df.where(etud_moy_ue_df.notna(), 0.0)
|
||||||
|
with np.errstate(invalid="ignore"): # ignore les 0/0 (-> NaN)
|
||||||
|
etud_moy_gen_s = (etud_coef_ue_df_no_nan * etud_moy_ue_df_no_nan).sum(
|
||||||
|
axis=1
|
||||||
|
) / etud_coef_ue_df_no_nan.sum(axis=1)
|
||||||
|
else:
|
||||||
|
# Cas normal: pondère directement les modules
|
||||||
|
etud_coef_ue_df = pd.DataFrame(
|
||||||
|
coefs.sum(axis=2).T,
|
||||||
|
index=modimpl_inscr_df.index, # etudids
|
||||||
|
columns=[ue.id for ue in ues],
|
||||||
|
)
|
||||||
|
with np.errstate(invalid="ignore"): # ignore les 0/0 (-> NaN)
|
||||||
|
etud_moy_gen = np.sum(
|
||||||
|
modimpl_coefs_etuds_no_nan * sem_matrix_inscrits, axis=1
|
||||||
|
) / np.sum(modimpl_coefs_etuds_no_nan, axis=1)
|
||||||
|
|
||||||
|
etud_moy_gen_s = pd.Series(etud_moy_gen, index=modimpl_inscr_df.index)
|
||||||
|
|
||||||
return etud_moy_gen_s, etud_moy_ue_df, etud_coef_ue_df
|
return etud_moy_gen_s, etud_moy_ue_df, etud_coef_ue_df
|
||||||
|
Loading…
Reference in New Issue
Block a user