forked from ScoDoc/ScoDoc
87 lines
3.4 KiB
Python
87 lines
3.4 KiB
Python
|
"""
|
||
|
Test calcul moyennes UE
|
||
|
"""
|
||
|
import numpy as np
|
||
|
import pandas as pd
|
||
|
from tests.unit import setup
|
||
|
|
||
|
from app.models.etudiants import Identite
|
||
|
|
||
|
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 Evaluation, formsemestre
|
||
|
from app.scodoc import sco_codes_parcours, sco_saisie_notes
|
||
|
from app.scodoc.sco_utils import NOTES_ATTENTE, NOTES_NEUTRALISE
|
||
|
|
||
|
|
||
|
def test_ue_moy(test_client):
|
||
|
"""Test calcul moyenne UE avec saisie des notes via ScoDoc"""
|
||
|
ue_coefs = (1.0, 2.0, 3.0) # coefs des modules vers les 3 UE
|
||
|
nb_ues = len(ue_coefs)
|
||
|
nb_mods = 2 # 2 modules
|
||
|
(
|
||
|
G,
|
||
|
formation_id,
|
||
|
sem,
|
||
|
evaluation_ids,
|
||
|
ue1,
|
||
|
ue2,
|
||
|
ue3,
|
||
|
) = setup.build_modules_with_evaluations(ue_coefs=ue_coefs, nb_mods=nb_mods)
|
||
|
assert len(evaluation_ids) == nb_mods
|
||
|
formsemestre_id = sem["formsemestre_id"]
|
||
|
formsemestre = models.FormSemestre.query.get(formsemestre_id)
|
||
|
evaluation1 = models.Evaluation.query.get(evaluation_ids[0])
|
||
|
evaluation2 = models.Evaluation.query.get(evaluation_ids[1])
|
||
|
etud = G.create_etud(nom="test")
|
||
|
G.inscrit_etudiant(sem, etud)
|
||
|
etudid = etud["etudid"]
|
||
|
# e1 est l'éval du module 1, et e2 l'éval du module 2
|
||
|
e1p1, e1p2, e1p3 = 1.0, 2.0, 3.0 # poids de l'éval 1 vers les UE 1, 2 et 3
|
||
|
e2p1, e2p2, e2p3 = 3.0, 1.0, 5.0 # poids de l'éval 2 vers les UE
|
||
|
evaluation1.set_ue_poids_dict({ue1.id: e1p1, ue2.id: e1p2, ue3.id: e1p3})
|
||
|
evaluation2.set_ue_poids_dict({ue1.id: e2p1, ue2.id: e2p2, ue3.id: e2p3})
|
||
|
# Les coefs des évaluations:
|
||
|
coef_e1, coef_e2 = 7.0, 11.0
|
||
|
evaluation1.coefficient = coef_e1
|
||
|
evaluation2.coefficient = coef_e2
|
||
|
# Les moduleimpls
|
||
|
modimpls = [evaluation1.moduleimpl, evaluation2.moduleimpl]
|
||
|
# Check inscriptions modules
|
||
|
modimpl_inscr_df = inscr_mod.df_load_modimpl_inscr(formsemestre_id)
|
||
|
assert (modimpl_inscr_df.values == np.array([[1, 1]])).all()
|
||
|
# Coefs des modules vers les UE:
|
||
|
modimpl_coefs_df, ues, modimpls = moy_ue.df_load_modimpl_coefs(formsemestre)
|
||
|
assert modimpl_coefs_df.shape == (nb_ues, nb_mods)
|
||
|
assert len(ues) == nb_ues
|
||
|
assert len(modimpls) == nb_mods
|
||
|
assert (modimpl_coefs_df.values == np.array([ue_coefs] * nb_mods).transpose()).all()
|
||
|
|
||
|
# --- Change les notes et recalcule les moyennes
|
||
|
# (rappel: on a deux évaluations: evaluation1, evaluation2, et un seul étudiant)
|
||
|
def change_notes(n1, n2):
|
||
|
# Saisie d'une note dans chaque éval
|
||
|
_ = sco_saisie_notes.notes_add(G.default_user, evaluation1.id, [(etudid, n1)])
|
||
|
_ = sco_saisie_notes.notes_add(G.default_user, evaluation2.id, [(etudid, n2)])
|
||
|
# Recalcul des moyennes
|
||
|
sem_cube = moy_ue.notes_sem_load_cube(formsemestre_id)
|
||
|
etuds = formsemestre.etuds.all()
|
||
|
etud_moy_ue = moy_ue.compute_ue_moys(
|
||
|
sem_cube, etuds, modimpls, ues, modimpl_inscr_df, modimpl_coefs_df
|
||
|
)
|
||
|
return etud_moy_ue
|
||
|
|
||
|
# Cas simple: 1 eval / module, notes normales,
|
||
|
# coefs non nuls.
|
||
|
n1, n2 = 5.0, 13.0 # notes aux 2 evals (1 dans chaque module)
|
||
|
etud_moy_ue = change_notes(5.0, 13.0)
|
||
|
assert etud_moy_ue.shape == (1, nb_ues) # 1 étudiant
|
||
|
assert etud_moy_ue[ue1.id][etudid] == (n1 + n2) / 2
|
||
|
assert etud_moy_ue[ue2.id][etudid] == (n1 + n2) / 2
|
||
|
assert etud_moy_ue[ue3.id][etudid] == (n1 + n2) / 2
|
||
|
#
|