Merge branch 'master' of https://scodoc.org/git/viennet/ScoDoc into refactor_nt

This commit is contained in:
Emmanuel Viennet 2022-01-17 00:30:39 +01:00
commit 54b1ce7bfb
6 changed files with 37 additions and 31 deletions

View File

@ -131,8 +131,7 @@ def notes_sem_assemble_cube(modimpls_notes: list[pd.DataFrame]) -> np.ndarray:
(DataFrames rendus par compute_module_moy, (etud x UE))
Resultat: ndarray (etud x module x UE)
"""
if len(modimpls_notes) == 0:
return np.zeros((0, 0, 0), dtype=float)
assert len(modimpls_notes)
modimpls_notes_arr = [df.values for df in modimpls_notes]
modimpls_notes = np.stack(modimpls_notes_arr)
# passe de (mod x etud x ue) à (etud x mod x UE)
@ -162,8 +161,13 @@ def notes_sem_load_cube(formsemestre: FormSemestre) -> tuple:
etuds_moy_module = mod_results.compute_module_moy(evals_poids)
modimpls_results[modimpl.id] = mod_results
modimpls_notes.append(etuds_moy_module)
if len(modimpls_notes):
cube = notes_sem_assemble_cube(modimpls_notes)
else:
nb_etuds = formsemestre.etuds.count()
cube = np.zeros((nb_etuds, 0, 0), dtype=float)
return (
notes_sem_assemble_cube(modimpls_notes),
cube,
modimpls_evals_poids,
modimpls_results,
)
@ -195,8 +199,12 @@ def compute_ue_moys_apc(
Resultat: DataFrame columns UE, rows etudid
"""
nb_etuds, nb_modules, nb_ues = sem_cube.shape
assert len(etuds) == nb_etuds
assert len(modimpls) == nb_modules
if nb_modules == 0 or nb_etuds == 0:
return pd.DataFrame(
index=modimpl_inscr_df.index, columns=modimpl_coefs_df.index
)
assert len(etuds) == nb_etuds
assert len(ues) == nb_ues
assert modimpl_inscr_df.shape[0] == nb_etuds
assert modimpl_inscr_df.shape[1] == nb_modules
@ -204,10 +212,6 @@ def compute_ue_moys_apc(
assert modimpl_coefs_df.shape[1] == nb_modules
modimpl_inscr = modimpl_inscr_df.values
modimpl_coefs = modimpl_coefs_df.values
if nb_etuds == 0:
return pd.DataFrame(
index=modimpl_inscr_df.index, columns=modimpl_coefs_df.index
)
# Duplique les inscriptions sur les UEs:
modimpl_inscr_stacked = np.stack([modimpl_inscr] * nb_ues, axis=2)
# Enlève les NaN du numérateur:

View File

@ -191,6 +191,7 @@ def compute_user_formula(
return user_moy
# XXX OBSOLETE
def compute_moduleimpl_moyennes(nt, modimpl):
"""Retourne dict { etudid : note_moyenne } pour tous les etuds inscrits
au moduleimpl mod, la liste des evaluations "valides" (toutes notes entrées
@ -228,22 +229,23 @@ def compute_moduleimpl_moyennes(nt, modimpl):
user_expr = moduleimpl_has_expression(modimpl)
attente = False
# recupere les notes de toutes les evaluations
# récupere les notes de toutes les evaluations
eval_rattr = None
for e in evals:
e["nb_inscrits"] = e["etat"]["nb_inscrits"]
NotesDB = sco_evaluation_db.do_evaluation_get_all_notes(
# XXX OBSOLETE
notes_db = sco_evaluation_db.do_evaluation_get_all_notes(
e["evaluation_id"]
) # toutes, y compris demissions
# restreint aux étudiants encore inscrits à ce module
notes = [
NotesDB[etudid]["value"] for etudid in NotesDB if (etudid in insmod_set)
notes_db[etudid]["value"] for etudid in notes_db if (etudid in insmod_set)
]
e["nb_notes"] = len(notes)
e["nb_abs"] = len([x for x in notes if x is None])
e["nb_neutre"] = len([x for x in notes if x == NOTES_NEUTRALISE])
e["nb_att"] = len([x for x in notes if x == NOTES_ATTENTE])
e["notes"] = NotesDB
e["notes"] = notes_db
if e["etat"]["evalattente"]:
attente = True

View File

@ -85,7 +85,7 @@ def evaluation_check_absences(evaluation_id):
Justs = set([x["etudid"] for x in Just]) # ensemble des etudiants avec justif
# Les notes:
NotesDB = sco_evaluation_db.do_evaluation_get_all_notes(evaluation_id)
notes_db = sco_evaluation_db.do_evaluation_get_all_notes(evaluation_id)
ValButAbs = [] # une note mais noté absent
AbsNonSignalee = [] # note ABS mais pas noté absent
ExcNonSignalee = [] # note EXC mais pas noté absent
@ -94,8 +94,8 @@ def evaluation_check_absences(evaluation_id):
for etudid, _ in sco_groups.do_evaluation_listeetuds_groups(
evaluation_id, getallstudents=True
):
if etudid in NotesDB:
val = NotesDB[etudid]["value"]
if etudid in notes_db:
val = notes_db[etudid]["value"]
if (
val != None and val != scu.NOTES_NEUTRALISE and val != scu.NOTES_ATTENTE
) and etudid in As:

View File

@ -306,8 +306,8 @@ def do_evaluation_delete(evaluation_id):
raise AccessDenied(
"Modification évaluation impossible pour %s" % current_user.get_nomplogin()
)
NotesDB = do_evaluation_get_all_notes(evaluation_id) # { etudid : value }
notes = [x["value"] for x in NotesDB.values()]
notes_db = do_evaluation_get_all_notes(evaluation_id) # { etudid : value }
notes = [x["value"] for x in notes_db.values()]
if notes:
raise ScoValueError(
"Impossible de supprimer cette évaluation: il reste des notes"

View File

@ -653,11 +653,11 @@ def _add_eval_columns(
notes = [] # liste des notes numeriques, pour calcul histogramme uniquement
evaluation_id = e["evaluation_id"]
e_o = Evaluation.query.get(evaluation_id) # XXX en attendant ré-écriture
NotesDB = sco_evaluation_db.do_evaluation_get_all_notes(evaluation_id)
notes_db = sco_evaluation_db.do_evaluation_get_all_notes(evaluation_id)
for row in rows:
etudid = row["etudid"]
if etudid in NotesDB:
val = NotesDB[etudid]["value"]
if etudid in notes_db:
val = notes_db[etudid]["value"]
if val is None:
nb_abs += 1
if val == scu.NOTES_ATTENTE:
@ -674,12 +674,12 @@ def _add_eval_columns(
nb_notes = nb_notes + 1
sum_notes += val
val_fmt = scu.fmt_note(val, keep_numeric=keep_numeric)
comment = NotesDB[etudid]["comment"]
comment = notes_db[etudid]["comment"]
if comment is None:
comment = ""
explanation = "%s (%s) %s" % (
NotesDB[etudid]["date"].strftime("%d/%m/%y %Hh%M"),
sco_users.user_info(NotesDB[etudid]["uid"])["nomcomplet"],
notes_db[etudid]["date"].strftime("%d/%m/%y %Hh%M"),
sco_users.user_info(notes_db[etudid]["uid"])["nomcomplet"],
comment,
)
else:

View File

@ -308,13 +308,13 @@ def do_evaluation_set_missing(evaluation_id, value, dialog_confirmed=False):
# XXX imaginer un redirect + msg erreur
raise AccessDenied("Modification des notes impossible pour %s" % current_user)
#
NotesDB = sco_evaluation_db.do_evaluation_get_all_notes(evaluation_id)
notes_db = sco_evaluation_db.do_evaluation_get_all_notes(evaluation_id)
etudid_etats = sco_groups.do_evaluation_listeetuds_groups(
evaluation_id, getallstudents=True, include_demdef=False
)
notes = []
for etudid, _ in etudid_etats: # pour tous les inscrits
if etudid not in NotesDB: # pas de note
if etudid not in notes_db: # pas de note
notes.append((etudid, value))
# Check value
L, invalids, _, _, _ = _check_notes(notes, E, M["module"])
@ -393,18 +393,18 @@ def evaluation_suppress_alln(evaluation_id, dialog_confirmed=False):
):
# On a le droit de modifier toutes les notes
# recupere les etuds ayant une note
NotesDB = sco_evaluation_db.do_evaluation_get_all_notes(evaluation_id)
notes_db = sco_evaluation_db.do_evaluation_get_all_notes(evaluation_id)
elif sco_permissions_check.can_edit_notes(
current_user, E["moduleimpl_id"], allow_ens=True
):
# Enseignant associé au module: ne peut supprimer que les notes qu'il a saisi
NotesDB = sco_evaluation_db.do_evaluation_get_all_notes(
notes_db = sco_evaluation_db.do_evaluation_get_all_notes(
evaluation_id, by_uid=current_user.id
)
else:
raise AccessDenied("Modification des notes impossible pour %s" % current_user)
notes = [(etudid, scu.NOTES_SUPPRESS) for etudid in NotesDB.keys()]
notes = [(etudid, scu.NOTES_SUPPRESS) for etudid in notes_db.keys()]
if not dialog_confirmed:
nb_changed, nb_suppress, existing_decisions = notes_add(
@ -493,7 +493,7 @@ def notes_add(
"etudiant %s: valeur de note invalide (%s)" % (etudid, value)
)
# Recherche notes existantes
NotesDB = sco_evaluation_db.do_evaluation_get_all_notes(evaluation_id)
notes_db = sco_evaluation_db.do_evaluation_get_all_notes(evaluation_id)
# Met a jour la base
cnx = ndb.GetDBConnexion()
cursor = cnx.cursor(cursor_factory=ndb.ScoDocCursor)
@ -507,7 +507,7 @@ def notes_add(
try:
for (etudid, value) in notes:
changed = False
if etudid not in NotesDB:
if etudid not in notes_db:
# nouvelle note
if value != scu.NOTES_SUPPRESS:
if do_it:
@ -530,7 +530,7 @@ def notes_add(
changed = True
else:
# il y a deja une note
oldval = NotesDB[etudid]["value"]
oldval = notes_db[etudid]["value"]
if type(value) != type(oldval):
changed = True
elif type(value) == type(1.0) and (