2021-12-11 12:39:53 +01:00
|
|
|
# -*- mode: python -*-
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# Gestion scolarite IUT
|
|
|
|
#
|
2023-12-31 23:04:06 +01:00
|
|
|
# Copyright (c) 1999 - 2024 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
|
|
|
|
|
2023-07-11 06:57:38 +02:00
|
|
|
from flask import flash, g, url_for
|
|
|
|
from markupsafe import Markup
|
|
|
|
|
|
|
|
from app import db
|
2022-03-14 00:01:08 +01:00
|
|
|
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-10-31 16:26:36 +01:00
|
|
|
etud_moy_ue_df: pd.DataFrame,
|
|
|
|
ects_df: pd.DataFrame,
|
|
|
|
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
|
2022-10-31 16:26:36 +01:00
|
|
|
ects: DataFrame, col. ue_id, lignes etudid, valeur float ou None
|
2022-02-27 20:32:38 +01:00
|
|
|
|
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-10-31 16:26:36 +01:00
|
|
|
ects = np.where(etud_moy_ue_df.isna(), 0.0, ects_df.to_numpy())
|
2022-03-14 00:01:08 +01:00
|
|
|
else:
|
2022-10-31 16:26:36 +01:00
|
|
|
ects = ects_df.to_numpy()
|
|
|
|
# ects est maintenant un array nb_etuds x nb_ues
|
2023-08-22 18:00:13 +02:00
|
|
|
|
2022-10-31 16:26:36 +01:00
|
|
|
moy_gen = (etud_moy_ue_df * ects).sum(axis=1) / ects.sum(axis=1)
|
2023-08-22 18:00:13 +02:00
|
|
|
except ZeroDivisionError:
|
|
|
|
# peut arriver si aucun module... on ignore
|
2024-07-31 15:12:32 +02:00
|
|
|
moy_gen = pd.Series(np.nan, index=etud_moy_ue_df.index)
|
2022-02-27 20:32:38 +01:00
|
|
|
except TypeError:
|
|
|
|
if None in ects:
|
2023-07-11 06:57:38 +02:00
|
|
|
formation = db.session.get(Formation, formation_id)
|
2022-03-14 00:01:08 +01:00
|
|
|
flash(
|
|
|
|
Markup(
|
|
|
|
f"""Calcul moyenne générale impossible: ECTS des UE manquants !<br>
|
2023-12-31 23:04:06 +01:00
|
|
|
(formation: <a href="{url_for("notes.ue_table",
|
2022-03-14 00:01:08 +01:00
|
|
|
scodoc_dept=g.scodoc_dept, formation_id=formation_id)}">{formation.get_titre_version()}</a>)"""
|
|
|
|
)
|
|
|
|
)
|
2024-07-31 15:12:32 +02: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
|
|
|
|
|
|
|
|
|
2023-07-11 06:57:38 +02:00
|
|
|
def comp_ranks_series(notes: pd.Series) -> tuple[pd.Series, pd.Series]:
|
2024-02-02 17:17:26 +01:00
|
|
|
"""Calcul rangs à partir d'une série ("vecteur") de notes (index etudid, valeur
|
2022-01-16 23:47:52 +01:00
|
|
|
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-04-14 14:12:50 +02:00
|
|
|
rangs_str = pd.Series("", index=notes.index, dtype=str) # le rang est une chaîne
|
|
|
|
# le rang numérique pour tris:
|
|
|
|
rangs_int = pd.Series(0, index=notes.index, dtype=int)
|
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
|
2022-04-14 14:12:50 +02:00
|
|
|
assert rangs_int.dtype == int
|
2022-02-13 13:58:09 +01:00
|
|
|
return rangs_str, rangs_int
|