2021-11-08 19:44:25 +01:00
|
|
|
"""
|
|
|
|
Test modèles évaluations avec poids BUT
|
|
|
|
"""
|
2021-11-17 10:28:51 +01:00
|
|
|
import numpy as np
|
|
|
|
import pandas as pd
|
2021-11-08 19:44:25 +01:00
|
|
|
|
|
|
|
from tests.unit import sco_fake_gen
|
|
|
|
from app import db
|
|
|
|
from app import models
|
2021-11-17 10:28:51 +01:00
|
|
|
from app.comp import moy_mod
|
|
|
|
from app.comp import moy_ue
|
|
|
|
from app.scodoc import sco_codes_parcours
|
2021-11-20 16:35:09 +01:00
|
|
|
from app.scodoc.sco_utils import NOTES_ATTENTE, NOTES_NEUTRALISE
|
2021-11-08 19:44:25 +01:00
|
|
|
|
|
|
|
"""
|
|
|
|
mapp.set_sco_dept("RT")
|
|
|
|
from app.auth.models import get_super_admin
|
|
|
|
admin_user = get_super_admin()
|
|
|
|
ctx.push()
|
|
|
|
login_user(admin_user)
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
2021-11-12 22:17:46 +01:00
|
|
|
def setup_formation_test():
|
2021-11-08 19:44:25 +01:00
|
|
|
G = sco_fake_gen.ScoFake(verbose=False)
|
|
|
|
_f = G.create_formation(
|
2021-11-17 10:28:51 +01:00
|
|
|
acronyme="F3",
|
|
|
|
titre="Formation 2",
|
|
|
|
titre_officiel="Titre officiel 2",
|
|
|
|
type_parcours=sco_codes_parcours.ParcoursBUT.TYPE_PARCOURS,
|
|
|
|
)
|
|
|
|
_ue1 = G.create_ue(
|
|
|
|
formation_id=_f["formation_id"], acronyme="UE1", titre="ue 1", semestre_idx=2
|
|
|
|
)
|
|
|
|
_ue2 = G.create_ue(
|
|
|
|
formation_id=_f["formation_id"], acronyme="UE2", titre="ue 2", semestre_idx=2
|
|
|
|
)
|
|
|
|
_ue3 = G.create_ue(
|
|
|
|
formation_id=_f["formation_id"], acronyme="UE3", titre="ue 3", semestre_idx=2
|
|
|
|
)
|
|
|
|
# une 4eme UE en dehors du semestre 2
|
|
|
|
_ = G.create_ue(
|
|
|
|
formation_id=_f["formation_id"], acronyme="UE41", titre="ue 41", semestre_idx=4
|
2021-11-08 19:44:25 +01:00
|
|
|
)
|
|
|
|
_mat = G.create_matiere(ue_id=_ue1["ue_id"], titre="matière test")
|
|
|
|
_mod = G.create_module(
|
|
|
|
matiere_id=_mat["matiere_id"],
|
|
|
|
code="TSM1",
|
|
|
|
coefficient=1.0,
|
|
|
|
titre="module test",
|
|
|
|
ue_id=_ue1["ue_id"],
|
|
|
|
formation_id=_f["formation_id"],
|
2021-11-17 10:28:51 +01:00
|
|
|
semestre_id=2,
|
2021-11-08 19:44:25 +01:00
|
|
|
)
|
2021-11-12 22:17:46 +01:00
|
|
|
return G, _f["id"], _ue1["id"], _ue2["id"], _ue3["id"], _mod["id"]
|
|
|
|
|
|
|
|
|
|
|
|
def test_evaluation_poids(test_client):
|
|
|
|
"""Association de poids vers les UE"""
|
|
|
|
G, formation_id, ue1_id, ue2_id, ue3_id, module_id = setup_formation_test()
|
2021-11-08 19:44:25 +01:00
|
|
|
sem = G.create_formsemestre(
|
2021-11-12 22:17:46 +01:00
|
|
|
formation_id=formation_id,
|
2021-11-08 19:44:25 +01:00
|
|
|
semestre_id=1,
|
|
|
|
date_debut="01/01/2021",
|
|
|
|
date_fin="30/06/2021",
|
|
|
|
) # formsemestre_id=716
|
|
|
|
mi = G.create_moduleimpl(
|
2021-11-12 22:17:46 +01:00
|
|
|
module_id=module_id,
|
2021-11-08 19:44:25 +01:00
|
|
|
formsemestre_id=sem["formsemestre_id"],
|
|
|
|
)
|
|
|
|
moduleimpl_id = mi["id"]
|
|
|
|
_e1 = G.create_evaluation(
|
|
|
|
moduleimpl_id=moduleimpl_id,
|
|
|
|
jour="01/01/2021",
|
|
|
|
description="evaluation 1",
|
|
|
|
coefficient=0,
|
|
|
|
)
|
|
|
|
evaluation_id = _e1["evaluation_id"] # evaluation_id=25246
|
2021-11-12 22:17:46 +01:00
|
|
|
# ue1_id=1684
|
|
|
|
# formation_id=199
|
2021-11-08 19:44:25 +01:00
|
|
|
#
|
2021-11-12 22:17:46 +01:00
|
|
|
e1 = models.Evaluation.query.get(evaluation_id)
|
|
|
|
ue1 = models.UniteEns.query.get(ue1_id)
|
2021-11-08 19:44:25 +01:00
|
|
|
assert e1.ue_poids == []
|
|
|
|
p1 = 3.14
|
|
|
|
e1.set_ue_poids(ue1, p1)
|
|
|
|
db.session.commit()
|
|
|
|
assert e1.get_ue_poids_dict()[ue1_id] == p1
|
2021-11-17 10:28:51 +01:00
|
|
|
ues = models.UniteEns.query.filter_by(
|
|
|
|
formation_id=formation_id, semestre_idx=2
|
|
|
|
).all()
|
2021-11-08 19:44:25 +01:00
|
|
|
poids = [1.0, 2.0, 3.0]
|
|
|
|
for (ue, p) in zip(ues, poids):
|
|
|
|
e1.set_ue_poids(ue, p)
|
|
|
|
assert len(e1.ue_poids) == len(ues)
|
|
|
|
assert e1.get_ue_poids_dict()[ues[1].id] == poids[1]
|
|
|
|
e1.set_ue_poids(ue1, p1)
|
|
|
|
db.session.commit()
|
|
|
|
poids2 = [10, 20]
|
|
|
|
e1.update_ue_poids_dict({ue.id: p for (ue, p) in zip(ues[:-1], poids2)})
|
|
|
|
assert e1.get_ue_poids_dict()[ues[0].id] == poids2[0]
|
|
|
|
assert e1.get_ue_poids_dict()[ues[1].id] == poids2[1]
|
|
|
|
assert e1.get_ue_poids_dict()[ues[2].id] == poids[2]
|
|
|
|
# Delete UE
|
|
|
|
db.session.delete(ues[2])
|
|
|
|
db.session.commit()
|
|
|
|
# Delete eval
|
|
|
|
db.session.delete(e1)
|
|
|
|
db.session.commit()
|
|
|
|
assert len(models.EvaluationUEPoids.query.all()) == 0
|
2021-11-12 22:17:46 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_modules_coefs(test_client):
|
|
|
|
"""Coefs vers les UE (BUT)"""
|
|
|
|
G, formation_id, ue1_id, ue2_id, ue3_id, module_id = setup_formation_test()
|
|
|
|
ue1 = models.UniteEns.query.get(ue1_id)
|
|
|
|
ue2 = models.UniteEns.query.get(ue2_id)
|
|
|
|
mod = models.Module.query.get(module_id)
|
|
|
|
coef = 2.5
|
|
|
|
mod.set_ue_coef(ue1, coef)
|
|
|
|
db.session.commit()
|
|
|
|
assert mod.ue_coefs[0].coef == coef
|
|
|
|
mod.set_ue_coef(ue2, 2 * coef)
|
|
|
|
db.session.commit()
|
|
|
|
assert set(mod.get_ue_coef_dict().values()) == {coef, 2 * coef}
|
|
|
|
assert set(mod.get_ue_coef_dict().keys()) == {ue1_id, ue2_id}
|
|
|
|
mod.delete_ue_coef(ue1)
|
|
|
|
db.session.commit()
|
|
|
|
assert len(mod.ue_coefs) == 1
|
2021-11-13 12:09:30 +01:00
|
|
|
# Gestion des coefs nuls:
|
|
|
|
mod.set_ue_coef(ue2, 0.0)
|
|
|
|
db.session.commit()
|
|
|
|
assert len(mod.ue_coefs) == 0
|
2021-11-17 10:28:51 +01:00
|
|
|
|
|
|
|
|
2021-11-20 16:35:09 +01:00
|
|
|
def _setup_module_evaluation(ue_coefs=(1.0, 2.0, 3.0)):
|
|
|
|
"""Utilisé dans plusieurs tests:
|
|
|
|
- création formation 3 UE, 1 module
|
|
|
|
- 1 semestre, 1 moduleimpl, 1 eval
|
|
|
|
"""
|
2021-11-17 10:28:51 +01:00
|
|
|
G, formation_id, ue1_id, ue2_id, ue3_id, module_id = setup_formation_test()
|
|
|
|
ue1 = models.UniteEns.query.get(ue1_id)
|
|
|
|
ue2 = models.UniteEns.query.get(ue2_id)
|
|
|
|
ue3 = models.UniteEns.query.get(ue3_id)
|
|
|
|
mod = models.Module.query.get(module_id)
|
|
|
|
nb_ues = 3 # 3 UEs dans ce test
|
|
|
|
nb_mods = 1 # 1 seul module
|
|
|
|
# Coef du module vers les UE
|
2021-11-20 16:35:09 +01:00
|
|
|
c1, c2, c3 = ue_coefs
|
2021-11-17 10:28:51 +01:00
|
|
|
coefs_mod = {ue1.id: c1, ue2.id: c2, ue3.id: c3}
|
|
|
|
mod.set_ue_coef_dict(coefs_mod)
|
|
|
|
assert mod.get_ue_coef_dict() == coefs_mod
|
|
|
|
# Mise en place:
|
|
|
|
sem = G.create_formsemestre(
|
|
|
|
formation_id=formation_id,
|
|
|
|
semestre_id=2,
|
|
|
|
date_debut="01/01/2021",
|
|
|
|
date_fin="30/06/2021",
|
|
|
|
)
|
|
|
|
mi = G.create_moduleimpl(
|
|
|
|
module_id=module_id,
|
|
|
|
formsemestre_id=sem["formsemestre_id"],
|
|
|
|
)
|
|
|
|
moduleimpl_id = mi["id"]
|
|
|
|
modimpl = models.ModuleImpl.query.get(moduleimpl_id)
|
|
|
|
assert modimpl.formsemestre.formation.get_parcours().APC_SAE # BUT
|
|
|
|
# Check ModuleImpl
|
|
|
|
ues = modimpl.formsemestre.query_ues().all()
|
|
|
|
assert len(ues) == 3
|
|
|
|
#
|
|
|
|
_e1 = G.create_evaluation(
|
|
|
|
moduleimpl_id=moduleimpl_id,
|
|
|
|
jour="01/01/2021",
|
|
|
|
description="evaluation 1",
|
|
|
|
coefficient=0,
|
|
|
|
)
|
|
|
|
evaluation_id = _e1["evaluation_id"]
|
2021-11-20 16:35:09 +01:00
|
|
|
return formation_id, evaluation_id, ue1, ue2, ue3
|
|
|
|
|
|
|
|
|
|
|
|
def test_module_conformity(test_client):
|
|
|
|
"""Vérification coefficients module<->UE vs poids des évaluations"""
|
|
|
|
formation_id, evaluation_id, ue1, ue2, ue3 = _setup_module_evaluation()
|
|
|
|
semestre_idx = 2
|
|
|
|
nb_ues = 3 # 3 UEs dans ce test
|
|
|
|
nb_mods = 1 # 1 seul module
|
2021-11-17 10:28:51 +01:00
|
|
|
nb_evals = 1 # 1 seule evaluation pour l'instant
|
|
|
|
p1, p2, p3 = 1.0, 2.0, 0.0 # poids de l'éval vers les UE 1, 2 et 3
|
|
|
|
evaluation = models.Evaluation.query.get(evaluation_id)
|
|
|
|
evaluation.set_ue_poids_dict({ue1.id: p1, ue2.id: p2})
|
|
|
|
assert evaluation.get_ue_poids_dict() == {ue1.id: p1, ue2.id: p2}
|
|
|
|
# On n'est pas conforme car p3 est nul alors que c3 est non nul
|
2021-11-20 16:35:09 +01:00
|
|
|
modules_coefficients, _ues, _modules = moy_ue.df_load_ue_coefs(
|
|
|
|
formation_id, semestre_idx
|
|
|
|
)
|
2021-11-17 10:28:51 +01:00
|
|
|
assert isinstance(modules_coefficients, pd.DataFrame)
|
|
|
|
assert modules_coefficients.shape == (nb_ues, nb_mods)
|
2021-11-20 16:35:09 +01:00
|
|
|
evals_poids = moy_mod.df_load_evaluations_poids(evaluation.moduleimpl_id)
|
2021-11-17 10:28:51 +01:00
|
|
|
assert isinstance(evals_poids, pd.DataFrame)
|
|
|
|
assert all(evals_poids.dtypes == np.float64)
|
|
|
|
assert evals_poids.shape == (nb_evals, nb_ues)
|
|
|
|
assert not moy_mod.check_moduleimpl_conformity(
|
2021-11-20 16:35:09 +01:00
|
|
|
evaluation.moduleimpl, evals_poids, modules_coefficients
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def test_module_moy():
|
|
|
|
"""Vérification calcul moyenne d'un module
|
|
|
|
(calcul bas niveau)
|
|
|
|
"""
|
|
|
|
# Repris du notebook CalculNotesBUT.ipynb
|
|
|
|
data = [ # Les notes de chaque étudiant dans les 2 evals:
|
|
|
|
{
|
|
|
|
"EVAL1": 11.0,
|
|
|
|
"EVAL2": 16.0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"EVAL1": np.NaN, # une absence (NaN)
|
|
|
|
"EVAL2": 17.0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"EVAL1": 13.0,
|
|
|
|
"EVAL2": NOTES_NEUTRALISE, # une abs EXC
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"EVAL1": 14.0,
|
|
|
|
"EVAL2": 19.0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"EVAL1": NOTES_ATTENTE, # une ATT (traitée comme EXC)
|
|
|
|
"EVAL2": np.NaN, # et une ABS
|
|
|
|
},
|
|
|
|
]
|
|
|
|
evals_notes = pd.DataFrame(
|
|
|
|
data, index=["etud1", "etud2", "etud3", "etud4", "etud5"]
|
2021-11-17 10:28:51 +01:00
|
|
|
)
|
2021-11-20 16:35:09 +01:00
|
|
|
# Poids des évaluations (1 ligne / évaluation)
|
|
|
|
data = [
|
|
|
|
{"UE1": 1, "UE2": 0, "UE3": 0},
|
|
|
|
{"UE1": 2, "UE2": 5, "UE3": 0},
|
|
|
|
]
|
|
|
|
evals_poids = pd.DataFrame(data, index=["EVAL1", "EVAL2"], dtype=float)
|
|
|
|
etud_moy_module_df = moy_mod.compute_module_moy(evals_notes, evals_poids)
|
|
|
|
NAN = 666.0 # pour pouvoir comparer NaN et NaN (car NaN != NaN)
|
|
|
|
r = etud_moy_module_df.fillna(NAN)
|
|
|
|
tuple(r.loc["etud1"]) == (14 + 1 / 3, 16.0, NAN)
|
|
|
|
tuple(r.loc["etud2"]) == (11 + 1 / 3, 17.0, NAN)
|
|
|
|
tuple(r.loc["etud3"]) == (13, NAN, NAN)
|
|
|
|
tuple(r.loc["etud4"]) == (17 + 1 / 3, 19, NAN)
|
|
|
|
tuple(r.loc["etud5"]) == (0.0, 0.0, NAN)
|
|
|
|
# note: les notes UE3 sont toutes NAN car les poids vers l'UE3 sont nuls
|