MonScoDocEssai/app/comp/res_but.py

106 lines
3.9 KiB
Python
Raw Normal View History

2021-12-30 23:58:38 +01:00
##############################################################################
# ScoDoc
2022-01-01 14:51:28 +01:00
# Copyright (c) 1999 - 2022 Emmanuel Viennet. All rights reserved.
2021-12-30 23:58:38 +01:00
# See LICENSE
##############################################################################
"""Résultats semestres BUT
"""
2022-01-16 23:47:52 +01:00
import pandas as pd
2021-12-30 23:58:38 +01:00
from app.comp import moy_ue, moy_sem, inscr_mod
2022-01-07 15:08:45 +01:00
from app.comp.res_common import NotesTableCompat
2022-01-25 10:45:13 +01:00
from app.comp.bonus_spo import BonusSport
from app.models import ScoDocSiteConfig
from app.scodoc.sco_codes_parcours import UE_SPORT
2021-12-30 23:58:38 +01:00
class ResultatsSemestreBUT(NotesTableCompat):
"""Résultats BUT: organisation des calculs"""
_cached_attrs = NotesTableCompat._cached_attrs + (
"modimpl_coefs_df",
"modimpls_evals_poids",
"sem_cube",
)
def __init__(self, formsemestre):
super().__init__(formsemestre)
if not self.load_cached():
self.compute()
self.store()
def compute(self):
"Charge les notes et inscriptions et calcule les moyennes d'UE et gen."
(
self.sem_cube,
self.modimpls_evals_poids,
self.modimpls_results,
) = moy_ue.notes_sem_load_cube(self.formsemestre)
self.modimpl_inscr_df = inscr_mod.df_load_modimpl_inscr(self.formsemestre)
self.modimpl_coefs_df, _, _ = moy_ue.df_load_modimpl_coefs(
self.formsemestre, modimpls=self.formsemestre.modimpls_sorted
2021-12-30 23:58:38 +01:00
)
# l'idx de la colonne du mod modimpl.id est
# modimpl_coefs_df.columns.get_loc(modimpl.id)
# idx de l'UE: modimpl_coefs_df.index.get_loc(ue.id)
2022-01-25 10:45:13 +01:00
# Elimine les coefs des modimpl bonus sports:
modimpls_sport = [
modimpl
for modimpl in self.formsemestre.modimpls_sorted
if modimpl.module.ue.type == UE_SPORT
]
for modimpl in modimpls_sport:
self.modimpl_coefs_df[modimpl.id] = 0
2021-12-30 23:58:38 +01:00
self.etud_moy_ue = moy_ue.compute_ue_moys_apc(
self.sem_cube,
self.etuds,
2022-01-25 10:45:13 +01:00
self.formsemestre.modimpls_sorted,
2021-12-30 23:58:38 +01:00
self.ues,
self.modimpl_inscr_df,
self.modimpl_coefs_df,
2021-12-30 23:58:38 +01:00
)
2022-01-16 23:47:52 +01:00
# Les coefficients d'UE ne sont pas utilisés en APC
self.etud_coef_ue_df = pd.DataFrame(
1.0, index=self.etud_moy_ue.index, columns=self.etud_moy_ue.columns
)
2022-01-26 22:59:53 +01:00
2022-01-25 10:45:13 +01:00
# --- Bonus Sport & Culture
if len(modimpls_sport) > 0:
bonus_class = ScoDocSiteConfig.get_bonus_sport_class()
if bonus_class is not None:
bonus: BonusSport = bonus_class(
self.formsemestre,
self.sem_cube,
self.ues,
self.modimpl_inscr_df,
self.modimpl_coefs_df.transpose(),
self.etud_moy_gen,
self.etud_moy_ue,
)
self.bonus_ues = bonus.get_bonus_ues()
if self.bonus_ues is not None:
self.etud_moy_ue += self.bonus_ues # somme les dataframes
self.etud_moy_ue.clip(lower=0.0, upper=20.0, inplace=True)
2022-01-25 10:45:13 +01:00
2022-01-26 22:59:53 +01:00
# Moyenne générale indicative:
# (note: le bonus sport a déjà été appliqué aux moyenens d'UE, et impacte
# donc la moyenne indicative)
2022-01-26 22:59:53 +01:00
self.etud_moy_gen = moy_sem.compute_sem_moys_apc(
self.etud_moy_ue, self.modimpl_coefs_df
2022-01-26 22:59:53 +01:00
)
2021-12-30 23:58:38 +01:00
self.etud_moy_gen_ranks = moy_sem.comp_ranks_series(self.etud_moy_gen)
def get_etud_mod_moy(self, moduleimpl_id: int, etudid: int) -> float:
"""La moyenne de l'étudiant dans le moduleimpl
En APC, il s'agit d'une moyenne indicative sans valeur.
Result: valeur float (peut être naN) ou chaîne "NI" (non inscrit ou DEM)
"""
mod_idx = self.modimpl_coefs_df.columns.get_loc(moduleimpl_id)
etud_idx = self.etud_index[etudid]
# moyenne sur les UE:
return self.sem_cube[etud_idx, mod_idx].mean()