Fix some unit tests

This commit is contained in:
Emmanuel Viennet 2022-04-21 22:54:06 +02:00
parent 14aabab746
commit b4f5634f2b
3 changed files with 24 additions and 15 deletions

View File

@ -271,7 +271,7 @@ def compute_ue_moys_apc(
)
# Annule les coefs des modules NaN
modimpl_coefs_etuds_no_nan = np.where(np.isnan(sem_cube), 0.0, modimpl_coefs_etuds)
if modimpl_coefs_etuds_no_nan.dtype == np.object: # arrive sur des tableaux vides
if modimpl_coefs_etuds_no_nan.dtype == object: # arrive sur des tableaux vides
modimpl_coefs_etuds_no_nan = modimpl_coefs_etuds_no_nan.astype(np.float)
#
# Version vectorisée
@ -356,7 +356,7 @@ def compute_ue_moys_classic(
modimpl_coefs_etuds_no_nan = np.where(
np.isnan(sem_matrix), 0.0, modimpl_coefs_etuds
)
if modimpl_coefs_etuds_no_nan.dtype == np.object: # arrive sur des tableaux vides
if modimpl_coefs_etuds_no_nan.dtype == object: # arrive sur des tableaux vides
modimpl_coefs_etuds_no_nan = modimpl_coefs_etuds_no_nan.astype(np.float)
# --------------------- Calcul des moyennes d'UE
ue_modules = np.array(
@ -367,7 +367,7 @@ 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)
if coefs.dtype == np.object: # arrive sur des tableaux vides
if coefs.dtype == object: # arrive sur des tableaux vides
coefs = coefs.astype(np.float)
with np.errstate(invalid="ignore"): # ignore les 0/0 (-> NaN)
etud_moy_ue = (
@ -462,7 +462,7 @@ def compute_mat_moys_classic(
modimpl_coefs_etuds_no_nan = np.where(
np.isnan(sem_matrix), 0.0, modimpl_coefs_etuds
)
if modimpl_coefs_etuds_no_nan.dtype == np.object: # arrive sur des tableaux vides
if modimpl_coefs_etuds_no_nan.dtype == object: # arrive sur des tableaux vides
modimpl_coefs_etuds_no_nan = modimpl_coefs_etuds_no_nan.astype(np.float)
etud_moy_mat = (modimpl_coefs_etuds_no_nan * sem_matrix_inscrits).sum(

View File

@ -204,7 +204,7 @@ class ScoFake(object):
abbrev=None,
ects=None,
code_apogee=None,
module_type=None,
module_type=scu.ModuleType.STANDARD,
) -> int:
oid = sco_edit_module.do_module_create(locals())
oids = sco_edit_module.module_list(args={"module_id": oid})

View File

@ -2,20 +2,15 @@
Test calcul moyennes UE
"""
import numpy as np
from numpy.lib.nanfunctions import _nanquantile_1d
import pandas as pd
from tests.unit import setup
from tests.unit import sco_fake_gen
from app import db
from app import models
from app.comp import moy_mod
from app.comp import moy_ue
from app.comp import inscr_mod
from app.models import FormSemestre, Evaluation, ModuleImplInscription
from app.models.etudiants import Identite
from app.scodoc import sco_codes_parcours, sco_saisie_notes
from app.scodoc.sco_utils import NOTES_ATTENTE, NOTES_NEUTRALISE
from app.scodoc import sco_saisie_notes
from app.scodoc.sco_codes_parcours import UE_SPORT
from app.scodoc.sco_utils import NOTES_NEUTRALISE
from app.scodoc import sco_exceptions
@ -69,9 +64,20 @@ def test_ue_moy(test_client):
_ = sco_saisie_notes.notes_add(G.default_user, evaluation2.id, [(etudid, n2)])
# Recalcul des moyennes
sem_cube, _, _ = moy_ue.notes_sem_load_cube(formsemestre)
# Masque de tous les modules _sauf_ les bonus (sport)
modimpl_mask = [
modimpl.module.ue.type != UE_SPORT
for modimpl in formsemestre.modimpls_sorted
]
etuds = formsemestre.etuds.all()
etud_moy_ue = moy_ue.compute_ue_moys_apc(
sem_cube, etuds, modimpls, ues, modimpl_inscr_df, modimpl_coefs_df
sem_cube,
etuds,
modimpls,
ues,
modimpl_inscr_df,
modimpl_coefs_df,
modimpl_mask,
)
return etud_moy_ue
@ -113,8 +119,11 @@ def test_ue_moy(test_client):
# Recalcule les notes:
sem_cube, _, _ = moy_ue.notes_sem_load_cube(formsemestre)
etuds = formsemestre.etuds.all()
modimpl_mask = [
modimpl.module.ue.type != UE_SPORT for modimpl in formsemestre.modimpls_sorted
]
etud_moy_ue = moy_ue.compute_ue_moys_apc(
sem_cube, etuds, modimpls, ues, modimpl_inscr_df, modimpl_coefs_df
sem_cube, etuds, modimpls, ues, modimpl_inscr_df, modimpl_coefs_df, modimpl_mask
)
assert etud_moy_ue[ue1.id][etudid] == n1
assert etud_moy_ue[ue2.id][etudid] == n1