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-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
|
|
|
|
|
|
|
|
|
|
|
def test_modules_conformity(test_client):
|
|
|
|
"""Vérification coefficients module<->UE vs poids des évaluations"""
|
|
|
|
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
|
|
|
|
c1, c2, c3 = 1.0, 2.0, 3.0
|
|
|
|
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"]
|
|
|
|
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-18 22:46:18 +01:00
|
|
|
modules_coefficients, _ues, _modules = moy_ue.df_load_ue_coefs(formation_id)
|
2021-11-17 10:28:51 +01:00
|
|
|
assert isinstance(modules_coefficients, pd.DataFrame)
|
|
|
|
assert modules_coefficients.shape == (nb_ues, nb_mods)
|
|
|
|
evals_poids = moy_mod.df_load_evaluations_poids(moduleimpl_id)
|
|
|
|
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(
|
|
|
|
modimpl, evals_poids, modules_coefficients
|
|
|
|
)
|