2021-12-11 12:39:53 +01:00
|
|
|
# -*- mode: python -*-
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# Gestion scolarite IUT
|
|
|
|
#
|
2022-01-01 14:49:42 +01:00
|
|
|
# Copyright (c) 1999 - 2022 Emmanuel Viennet. All rights reserved.
|
2021-12-11 12:39:53 +01:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
# Emmanuel Viennet emmanuel.viennet@viennet.net
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
"""Fonctions de calcul des moyennes de semestre (indicatives dans le BUT)
|
|
|
|
"""
|
|
|
|
import numpy as np
|
|
|
|
import pandas as pd
|
|
|
|
|
2022-03-14 00:01:08 +01:00
|
|
|
from flask import flash, g, Markup, url_for
|
|
|
|
from app.models.formations import Formation
|
2021-12-11 12:39:53 +01:00
|
|
|
|
2022-02-27 20:32:38 +01:00
|
|
|
|
|
|
|
def compute_sem_moys_apc_using_coefs(
|
2022-01-16 23:47:52 +01:00
|
|
|
etud_moy_ue_df: pd.DataFrame, modimpl_coefs_df: pd.DataFrame
|
|
|
|
) -> pd.Series:
|
|
|
|
"""Calcule les moyennes générales indicatives de tous les étudiants
|
2021-12-11 12:39:53 +01:00
|
|
|
= moyenne des moyennes d'UE, pondérée par la somme de leurs coefs
|
|
|
|
|
|
|
|
etud_moy_ue_df: DataFrame, colonnes ue_id, lignes etudid
|
2022-01-25 10:45:13 +01:00
|
|
|
modimpl_coefs_df: DataFrame, colonnes moduleimpl_id, lignes UE (sans ue bonus)
|
2021-12-11 12:39:53 +01:00
|
|
|
|
|
|
|
Result: panda Series, index etudid, valeur float (moyenne générale)
|
|
|
|
"""
|
|
|
|
moy_gen = (etud_moy_ue_df * modimpl_coefs_df.values.sum(axis=1)).sum(
|
|
|
|
axis=1
|
|
|
|
) / modimpl_coefs_df.values.sum()
|
|
|
|
return moy_gen
|
2021-12-12 10:17:02 +01:00
|
|
|
|
|
|
|
|
2022-02-27 20:32:38 +01:00
|
|
|
def compute_sem_moys_apc_using_ects(
|
2022-03-14 00:01:08 +01:00
|
|
|
etud_moy_ue_df: pd.DataFrame, ects: list, formation_id=None, skip_empty_ues=False
|
2022-02-27 20:32:38 +01:00
|
|
|
) -> pd.Series:
|
|
|
|
"""Calcule les moyennes générales indicatives de tous les étudiants
|
|
|
|
= moyenne des moyennes d'UE, pondérée par leurs ECTS.
|
|
|
|
|
|
|
|
etud_moy_ue_df: DataFrame, colonnes ue_id, lignes etudid
|
|
|
|
ects: liste de floats ou None, 1 par UE
|
|
|
|
|
2022-03-14 00:01:08 +01:00
|
|
|
Si skip_empty_ues: ne compte pas les UE non notées.
|
|
|
|
Sinon (par défaut), une UE non notée compte comme zéro.
|
|
|
|
|
2022-02-27 20:32:38 +01:00
|
|
|
Result: panda Series, index etudid, valeur float (moyenne générale)
|
|
|
|
"""
|
|
|
|
try:
|
2022-03-14 00:01:08 +01:00
|
|
|
if skip_empty_ues:
|
|
|
|
# annule les coefs des UE sans notes (NaN)
|
2022-03-18 22:40:04 +01:00
|
|
|
ects = np.where(etud_moy_ue_df.isna(), 0.0, np.array(ects, dtype=float))
|
2022-03-14 00:01:08 +01:00
|
|
|
# ects est devenu nb_etuds x nb_ues
|
|
|
|
moy_gen = (etud_moy_ue_df * ects).sum(axis=1) / ects.sum(axis=1)
|
|
|
|
else:
|
|
|
|
moy_gen = (etud_moy_ue_df * ects).sum(axis=1) / sum(ects)
|
2022-02-27 20:32:38 +01:00
|
|
|
except TypeError:
|
|
|
|
if None in ects:
|
2022-03-14 00:01:08 +01:00
|
|
|
formation = Formation.query.get(formation_id)
|
|
|
|
flash(
|
|
|
|
Markup(
|
|
|
|
f"""Calcul moyenne générale impossible: ECTS des UE manquants !<br>
|
|
|
|
(formation: <a href="{url_for("notes.ue_table",
|
|
|
|
scodoc_dept=g.scodoc_dept, formation_id=formation_id)}">{formation.get_titre_version()}</a>)"""
|
|
|
|
)
|
|
|
|
)
|
2022-02-28 11:00:24 +01:00
|
|
|
moy_gen = pd.Series(np.NaN, index=etud_moy_ue_df.index)
|
2022-02-27 20:32:38 +01:00
|
|
|
else:
|
|
|
|
raise
|
|
|
|
return moy_gen
|
|
|
|
|
|
|
|
|
2022-02-13 13:58:09 +01:00
|
|
|
def comp_ranks_series(notes: pd.Series) -> (pd.Series, pd.Series):
|
2022-01-16 23:47:52 +01:00
|
|
|
"""Calcul rangs à partir d'une séries ("vecteur") de notes (index etudid, valeur
|
|
|
|
numérique) en tenant compte des ex-aequos.
|
|
|
|
|
2022-03-22 08:58:47 +01:00
|
|
|
Result: couple (tuple)
|
|
|
|
Series { etudid : rang:str } où rang est une chaine decrivant le rang,
|
|
|
|
Series { etudid : rang:int } le rang comme un nombre
|
2021-12-12 10:17:02 +01:00
|
|
|
"""
|
2022-03-22 08:58:47 +01:00
|
|
|
if (notes is None) or (len(notes) == 0):
|
|
|
|
return (pd.Series([], dtype=object), pd.Series([], dtype=int))
|
2021-12-12 10:17:02 +01:00
|
|
|
notes = notes.sort_values(ascending=False) # Serie, tri par ordre décroissant
|
2022-02-13 13:58:09 +01:00
|
|
|
rangs_str = pd.Series(index=notes.index, dtype=str) # le rang est une chaîne
|
|
|
|
rangs_int = pd.Series(index=notes.index, dtype=int) # le rang numérique pour tris
|
2021-12-12 10:17:02 +01:00
|
|
|
N = len(notes)
|
|
|
|
nb_ex = 0 # nb d'ex-aequo consécutifs en cours
|
|
|
|
notes_i = notes.iat
|
|
|
|
for i, etudid in enumerate(notes.index):
|
|
|
|
# test ex-aequo
|
|
|
|
if i < (N - 1):
|
|
|
|
next = notes_i[i + 1]
|
|
|
|
else:
|
|
|
|
next = None
|
|
|
|
val = notes_i[i]
|
|
|
|
if nb_ex:
|
2022-02-13 13:58:09 +01:00
|
|
|
rangs_int[etudid] = i + 1 - nb_ex
|
2021-12-12 10:17:02 +01:00
|
|
|
srang = "%d ex" % (i + 1 - nb_ex)
|
|
|
|
if val == next:
|
|
|
|
nb_ex += 1
|
|
|
|
else:
|
|
|
|
nb_ex = 0
|
|
|
|
else:
|
|
|
|
if val == next:
|
2022-02-13 13:58:09 +01:00
|
|
|
rangs_int[etudid] = i + 1 - nb_ex
|
2021-12-12 10:17:02 +01:00
|
|
|
srang = "%d ex" % (i + 1 - nb_ex)
|
|
|
|
nb_ex = 1
|
|
|
|
else:
|
2022-02-13 13:58:09 +01:00
|
|
|
rangs_int[etudid] = i + 1
|
2021-12-12 10:17:02 +01:00
|
|
|
srang = "%d" % (i + 1)
|
2022-02-13 13:58:09 +01:00
|
|
|
rangs_str[etudid] = srang
|
|
|
|
return rangs_str, rangs_int
|