2024-01-25 17:17:01 +01:00
|
|
|
# -*- mode: python -*-
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# Gestion scolarite IUT
|
|
|
|
#
|
|
|
|
# Copyright (c) 1999 - 2024 Emmanuel Viennet. All rights reserved.
|
|
|
|
#
|
|
|
|
# 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
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
##############################################################################
|
|
|
|
# Module "Avis de poursuite d'étude"
|
|
|
|
# conçu et développé par Cléo Baras (IUT de Grenoble)
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
"""
|
|
|
|
Created on Fri Sep 9 09:15:05 2016
|
|
|
|
|
|
|
|
@author: barasc
|
|
|
|
"""
|
|
|
|
|
|
|
|
# ----------------------------------------------------------
|
|
|
|
# Ensemble des fonctions et des classes
|
|
|
|
# permettant les calculs preliminaires (hors affichage)
|
|
|
|
# a l'edition d'un jury de poursuites d'etudes
|
|
|
|
# ----------------------------------------------------------
|
|
|
|
|
|
|
|
import io
|
|
|
|
import os
|
2024-02-11 22:06:37 +01:00
|
|
|
import time
|
2024-01-25 17:17:01 +01:00
|
|
|
from zipfile import ZipFile
|
|
|
|
|
2024-02-02 06:11:21 +01:00
|
|
|
import numpy as np
|
2024-02-08 22:09:11 +01:00
|
|
|
import pandas as pd
|
2024-02-24 12:21:42 +01:00
|
|
|
import jinja2
|
2024-02-02 06:11:21 +01:00
|
|
|
|
2024-02-20 16:22:22 +01:00
|
|
|
from app.pe.rcss import pe_rcs
|
2024-02-21 20:02:38 +01:00
|
|
|
from app.pe.moys import pe_sxtag
|
2024-02-24 10:48:38 +01:00
|
|
|
|
2024-02-08 22:09:11 +01:00
|
|
|
import app.pe.pe_affichage as pe_affichage
|
2024-02-17 03:30:19 +01:00
|
|
|
import app.pe.pe_etudiant as pe_etudiant
|
2024-02-21 20:02:38 +01:00
|
|
|
from app.pe.moys import (
|
|
|
|
pe_tabletags,
|
|
|
|
pe_ressemtag,
|
|
|
|
pe_sxtag,
|
|
|
|
pe_rcstag,
|
|
|
|
pe_interclasstag,
|
|
|
|
pe_moytag,
|
|
|
|
)
|
2024-02-19 14:50:38 +01:00
|
|
|
import app.pe.pe_rcss_jury as pe_rcss_jury
|
2024-01-25 17:17:01 +01:00
|
|
|
|
|
|
|
|
|
|
|
class JuryPE(object):
|
2024-02-08 22:09:11 +01:00
|
|
|
"""
|
|
|
|
Classe mémorisant toutes les informations nécessaires pour établir un jury de PE, sur la base
|
|
|
|
d'une année de diplôme. De ce semestre est déduit :
|
|
|
|
1. l'année d'obtention du DUT,
|
|
|
|
2. tous les étudiants susceptibles à ce stade (au regard de leur parcours) d'être diplomés.
|
2024-01-25 17:17:01 +01:00
|
|
|
|
2024-02-08 22:09:11 +01:00
|
|
|
Args:
|
|
|
|
diplome : l'année d'obtention du diplome BUT et du jury de PE (généralement février XXXX)
|
|
|
|
"""
|
|
|
|
|
2024-02-14 15:19:21 +01:00
|
|
|
def __init__(self, diplome: int):
|
2024-02-11 22:06:37 +01:00
|
|
|
pe_affichage.pe_start_log()
|
2024-01-25 17:17:01 +01:00
|
|
|
self.diplome = diplome
|
2024-01-26 10:18:46 +01:00
|
|
|
"L'année du diplome"
|
2024-01-25 17:17:01 +01:00
|
|
|
|
2024-01-25 21:54:22 +01:00
|
|
|
self.nom_export_zip = f"Jury_PE_{self.diplome}"
|
2024-01-26 10:18:46 +01:00
|
|
|
"Nom du zip où ranger les fichiers générés"
|
|
|
|
|
2024-02-11 22:06:37 +01:00
|
|
|
pe_affichage.pe_print(
|
|
|
|
f"Données de poursuite d'étude générées le {time.strftime('%d/%m/%Y à %H:%M')}\n"
|
|
|
|
)
|
|
|
|
# Chargement des étudiants à prendre en compte dans le jury
|
2024-01-27 12:21:21 +01:00
|
|
|
pe_affichage.pe_print(
|
2024-02-25 12:45:58 +01:00
|
|
|
f"""***********************************************************\n"""
|
|
|
|
f"""*** Recherche des étudiants diplômés 🎓 en {self.diplome}\n"""
|
|
|
|
f"""***********************************************************\n"""
|
2024-01-27 12:21:21 +01:00
|
|
|
)
|
2024-02-25 12:45:58 +01:00
|
|
|
|
|
|
|
# Les infos sur les étudiants
|
|
|
|
self.etudiants = pe_etudiant.EtudiantsJuryPE(self.diplome)
|
|
|
|
"""Les informations sur les étudiants du jury PE"""
|
2024-02-14 15:19:21 +01:00
|
|
|
self.etudiants.find_etudiants()
|
2024-01-27 12:21:21 +01:00
|
|
|
self.diplomes_ids = self.etudiants.diplomes_ids
|
2024-01-27 10:13:04 +01:00
|
|
|
|
2024-02-19 14:50:38 +01:00
|
|
|
self.rcss_jury = pe_rcss_jury.RCSsJuryPE(self.diplome)
|
2024-02-18 19:24:03 +01:00
|
|
|
"""Les informations sur les regroupements de semestres"""
|
|
|
|
|
2024-01-27 12:21:21 +01:00
|
|
|
self.zipdata = io.BytesIO()
|
2024-01-26 10:18:46 +01:00
|
|
|
with ZipFile(self.zipdata, "w") as zipfile:
|
2024-01-27 10:13:04 +01:00
|
|
|
if not self.diplomes_ids:
|
2024-01-27 12:21:21 +01:00
|
|
|
pe_affichage.pe_print("*** Aucun étudiant diplômé")
|
2024-01-27 10:13:04 +01:00
|
|
|
else:
|
2024-02-19 14:50:38 +01:00
|
|
|
try:
|
|
|
|
self._gen_xls_diplomes(zipfile)
|
|
|
|
self._gen_xls_ressembuttags(zipfile)
|
2024-02-20 16:22:22 +01:00
|
|
|
self._gen_trajectoires()
|
|
|
|
self._gen_semXs()
|
2024-02-19 14:50:38 +01:00
|
|
|
self._gen_xls_sxtags(zipfile)
|
2024-02-20 20:52:44 +01:00
|
|
|
self._gen_rcsemxs()
|
|
|
|
self._gen_xls_rcstags(zipfile)
|
2024-02-21 20:02:38 +01:00
|
|
|
self._gen_xls_interclasstags(zipfile)
|
|
|
|
self._gen_xls_synthese_jury_par_tag(zipfile)
|
2024-02-24 10:48:38 +01:00
|
|
|
self._gen_html_synthese_par_etudiant(zipfile)
|
2024-02-19 14:50:38 +01:00
|
|
|
except Exception as e:
|
|
|
|
raise e
|
2024-02-11 22:06:37 +01:00
|
|
|
# et le log
|
|
|
|
self._add_log_to_zip(zipfile)
|
2024-02-02 11:49:24 +01:00
|
|
|
|
2024-01-27 12:21:21 +01:00
|
|
|
# Fin !!!! Tada :)
|
2024-01-26 10:18:46 +01:00
|
|
|
|
2024-01-27 12:21:21 +01:00
|
|
|
def _gen_xls_diplomes(self, zipfile: ZipFile):
|
|
|
|
"Intègre le bilan des semestres taggués au zip"
|
|
|
|
output = io.BytesIO()
|
|
|
|
with pd.ExcelWriter( # pylint: disable=abstract-class-instantiated
|
|
|
|
output, engine="openpyxl"
|
|
|
|
) as writer:
|
|
|
|
if self.diplomes_ids:
|
|
|
|
onglet = "diplômés"
|
|
|
|
df_diplome = self.etudiants.df_administratif(self.diplomes_ids)
|
|
|
|
df_diplome.to_excel(writer, onglet, index=True, header=True)
|
|
|
|
if self.etudiants.abandons_ids:
|
|
|
|
onglet = "redoublants-réorientés"
|
|
|
|
df_abandon = self.etudiants.df_administratif(
|
|
|
|
self.etudiants.abandons_ids
|
2024-01-27 10:13:04 +01:00
|
|
|
)
|
2024-01-27 12:21:21 +01:00
|
|
|
df_abandon.to_excel(writer, onglet, index=True, header=True)
|
|
|
|
output.seek(0)
|
|
|
|
|
|
|
|
self.add_file_to_zip(
|
|
|
|
zipfile,
|
|
|
|
f"etudiants_{self.diplome}.xlsx",
|
|
|
|
output.read(),
|
|
|
|
path="details",
|
|
|
|
)
|
|
|
|
|
2024-02-17 02:35:43 +01:00
|
|
|
def _gen_xls_ressembuttags(self, zipfile: ZipFile):
|
|
|
|
"""Calcule les moyennes par tag des résultats des Semestres BUT"""
|
2024-02-17 03:30:19 +01:00
|
|
|
pe_affichage.pe_print(
|
2024-02-25 12:45:58 +01:00
|
|
|
f"""*************************************************************************\n"""
|
|
|
|
f"""*** Génère les ResSemBUTTag (ResSemestreBUT taggués)\n"""
|
|
|
|
f"""*************************************************************************"""
|
2024-02-17 03:30:19 +01:00
|
|
|
)
|
2024-02-17 02:35:43 +01:00
|
|
|
|
2024-02-25 12:45:58 +01:00
|
|
|
# Tous les formsestres des étudiants
|
2024-02-17 02:35:43 +01:00
|
|
|
formsemestres = get_formsemestres_etudiants(self.etudiants)
|
2024-02-25 12:45:58 +01:00
|
|
|
pe_affichage.pe_print(f"1) Génère les {len(formsemestres)} ResSemBUTTag")
|
2024-02-17 02:35:43 +01:00
|
|
|
|
2024-02-17 03:30:19 +01:00
|
|
|
self.ressembuttags = {}
|
2024-02-17 02:35:43 +01:00
|
|
|
for frmsem_id, formsemestre in formsemestres.items():
|
|
|
|
# Crée le semestre_tag et exécute les calculs de moyennes
|
2024-02-21 20:02:38 +01:00
|
|
|
self.ressembuttags[frmsem_id] = pe_ressemtag.ResSemBUTTag(formsemestre)
|
2024-01-27 12:21:21 +01:00
|
|
|
|
|
|
|
# Intègre le bilan des semestres taggués au zip final
|
2024-02-25 12:45:58 +01:00
|
|
|
pe_affichage.pe_print(f"2) Bilan")
|
2024-01-27 12:21:21 +01:00
|
|
|
output = io.BytesIO()
|
|
|
|
with pd.ExcelWriter( # pylint: disable=abstract-class-instantiated
|
|
|
|
output, engine="openpyxl"
|
|
|
|
) as writer:
|
2024-02-20 09:13:19 +01:00
|
|
|
onglets = []
|
2024-02-17 02:35:43 +01:00
|
|
|
for res_sem_tag in self.ressembuttags.values():
|
2024-02-20 09:13:19 +01:00
|
|
|
onglet = res_sem_tag.get_repr(verbose=True)
|
2024-02-25 12:45:58 +01:00
|
|
|
onglet = onglet.replace("Semestre ", "S")
|
|
|
|
onglets += ["📊" + onglet]
|
2024-02-21 20:02:38 +01:00
|
|
|
df = res_sem_tag.to_df()
|
2024-02-24 10:48:38 +01:00
|
|
|
# Conversion colonnes en multiindex
|
|
|
|
df = convert_colonnes_to_multiindex(df)
|
2024-01-27 12:21:21 +01:00
|
|
|
# écriture dans l'onglet
|
|
|
|
df.to_excel(writer, onglet, index=True, header=True)
|
2024-02-25 12:45:58 +01:00
|
|
|
pe_affichage.pe_print(f"--> Export excel de {', '.join(onglets)}")
|
2024-01-27 12:21:21 +01:00
|
|
|
output.seek(0)
|
|
|
|
|
2024-02-16 16:07:48 +01:00
|
|
|
self.add_file_to_zip(
|
|
|
|
zipfile,
|
2024-02-17 02:35:43 +01:00
|
|
|
f"ResSemBUTTags_{self.diplome}.xlsx",
|
2024-02-16 16:07:48 +01:00
|
|
|
output.read(),
|
|
|
|
path="details",
|
|
|
|
)
|
|
|
|
|
2024-02-20 16:22:22 +01:00
|
|
|
def _gen_trajectoires(self):
|
|
|
|
"""Génère l'ensemble des trajectoires (RCS), qui traduisent les différents
|
|
|
|
chemins au sein des (form)semestres pour atteindre la cible d'un
|
|
|
|
RCS (par ex: 'S2' ou '3S').
|
2024-02-16 16:07:48 +01:00
|
|
|
"""
|
|
|
|
pe_affichage.pe_print(
|
2024-02-25 12:45:58 +01:00
|
|
|
"***************************************************************************\n"
|
2024-02-25 16:25:28 +01:00
|
|
|
"*** Génère les trajectoires (≠tes combinaisons de semestres) des étudiants\n"
|
|
|
|
"***************************************************************************"
|
2024-02-16 16:07:48 +01:00
|
|
|
)
|
2024-02-18 19:24:03 +01:00
|
|
|
|
2024-02-20 16:22:22 +01:00
|
|
|
self.rcss_jury.cree_trajectoires(self.etudiants)
|
2024-02-25 12:45:58 +01:00
|
|
|
self.rcss_jury._aff_trajectoires(self.etudiants)
|
2024-02-16 16:07:48 +01:00
|
|
|
|
2024-02-20 16:22:22 +01:00
|
|
|
def _gen_semXs(self):
|
|
|
|
"""Génère les SemXs (trajectoires/combinaisons de semestre de même rang x)
|
|
|
|
qui traduisent les différents chemins des étudiants pour valider un semestre Sx.
|
|
|
|
"""
|
2024-02-18 19:24:03 +01:00
|
|
|
# Génère les regroupements de semestres de type Sx
|
2024-02-19 14:50:38 +01:00
|
|
|
pe_affichage.pe_print(
|
2024-02-20 16:22:22 +01:00
|
|
|
"*** Génère les SemXs (RCS de même Sx donnant lieu à validation du semestre)"
|
2024-02-19 14:50:38 +01:00
|
|
|
)
|
2024-02-20 16:22:22 +01:00
|
|
|
self.rcss_jury.cree_semxs(self.etudiants)
|
|
|
|
self.rcss_jury._aff_semxs_suivis(self.etudiants)
|
2024-02-18 19:24:03 +01:00
|
|
|
|
2024-02-20 09:13:19 +01:00
|
|
|
def _gen_xls_sxtags(self, zipfile: ZipFile):
|
|
|
|
"""Génère les semestres taggués en s'appuyant sur les RCF de type Sx (pour
|
|
|
|
identifier les redoublements impactant les semestres taggués).
|
|
|
|
"""
|
2024-02-16 16:07:48 +01:00
|
|
|
# Génère les moyennes des RCS de type Sx
|
2024-02-20 16:22:22 +01:00
|
|
|
pe_affichage.pe_print(
|
2024-02-25 12:45:58 +01:00
|
|
|
"***************************************************************************\n"
|
2024-02-25 16:25:28 +01:00
|
|
|
"*** Calcule les moyennes des SxTag (moyennes d'un RCS de type Sx)\n"
|
|
|
|
"***************************************************************************"
|
2024-02-20 16:22:22 +01:00
|
|
|
)
|
2024-02-17 02:35:43 +01:00
|
|
|
|
2024-02-18 19:24:03 +01:00
|
|
|
# Les SxTag (moyenne de Sx par UE)
|
2024-02-25 12:45:58 +01:00
|
|
|
pe_affichage.pe_print("1) Calcul des moyennes")
|
2024-02-17 02:35:43 +01:00
|
|
|
self.sxtags = {}
|
2024-02-20 16:22:22 +01:00
|
|
|
for rcf_id, rcf in self.rcss_jury.semXs.items():
|
2024-02-18 19:24:03 +01:00
|
|
|
# SxTag traduisant le RCF
|
|
|
|
sxtag_id = rcf_id
|
2024-02-19 14:50:38 +01:00
|
|
|
self.sxtags[sxtag_id] = pe_sxtag.SxTag(sxtag_id, rcf, self.ressembuttags)
|
2024-02-16 16:07:48 +01:00
|
|
|
|
|
|
|
# Intègre le bilan des semestres taggués au zip final
|
2024-02-25 12:45:58 +01:00
|
|
|
pe_affichage.pe_print("2) Bilan")
|
2024-02-16 16:07:48 +01:00
|
|
|
output = io.BytesIO()
|
|
|
|
with pd.ExcelWriter( # pylint: disable=abstract-class-instantiated
|
2024-02-17 03:30:19 +01:00
|
|
|
output, engine="openpyxl"
|
2024-02-16 16:07:48 +01:00
|
|
|
) as writer:
|
2024-02-20 09:13:19 +01:00
|
|
|
onglets = []
|
2024-02-18 19:24:03 +01:00
|
|
|
for sxtag in self.sxtags.values():
|
|
|
|
onglet = sxtag.get_repr(verbose=False)
|
2024-02-21 20:02:38 +01:00
|
|
|
if sxtag.is_significatif():
|
|
|
|
df = sxtag.to_df()
|
2024-02-24 10:48:38 +01:00
|
|
|
# Conversion colonnes en multiindex
|
|
|
|
df = convert_colonnes_to_multiindex(df)
|
2024-02-25 12:45:58 +01:00
|
|
|
onglets += ["📊" + onglet]
|
2024-02-21 20:02:38 +01:00
|
|
|
# écriture dans l'onglet
|
|
|
|
df.to_excel(writer, onglet, index=True, header=True)
|
2024-02-25 12:45:58 +01:00
|
|
|
pe_affichage.pe_print(f"--> Export excel de {', '.join(onglets)}")
|
2024-02-20 09:13:19 +01:00
|
|
|
|
2024-02-16 16:07:48 +01:00
|
|
|
output.seek(0)
|
2024-02-21 20:02:38 +01:00
|
|
|
if onglets:
|
|
|
|
self.add_file_to_zip(
|
|
|
|
zipfile,
|
|
|
|
f"semestres_taggues_{self.diplome}.xlsx",
|
|
|
|
output.read(),
|
|
|
|
path="details",
|
|
|
|
)
|
2024-01-27 12:21:21 +01:00
|
|
|
|
2024-02-20 16:22:22 +01:00
|
|
|
def _gen_rcsemxs(self):
|
2024-02-18 19:24:03 +01:00
|
|
|
"""Génère les regroupements cohérents de RCFs qu'ont suivi chaque étudiant"""
|
|
|
|
|
2024-02-19 14:50:38 +01:00
|
|
|
pe_affichage.pe_print(
|
2024-02-25 12:45:58 +01:00
|
|
|
"""******************************************************************************\n"""
|
|
|
|
"""*** Génère les RCSemX (regroupements cohérents de données extraites des SemX)\n"""
|
|
|
|
"""*** amenant du S1 à un semestre final\n"""
|
|
|
|
"""******************************************************************************"""
|
2024-02-19 14:50:38 +01:00
|
|
|
)
|
2024-02-20 16:22:22 +01:00
|
|
|
self.rcss_jury.cree_rcsemxs(self.etudiants)
|
|
|
|
self.rcss_jury._aff_rcsemxs_suivis(self.etudiants)
|
2024-02-18 19:24:03 +01:00
|
|
|
|
2024-02-20 20:52:44 +01:00
|
|
|
def _gen_xls_rcstags(self, zipfile: ZipFile):
|
2024-02-18 19:24:03 +01:00
|
|
|
"""Génère les RCS taggués traduisant les moyennes (orientées compétences)
|
|
|
|
de regroupements de semestre de type Sx, xA ou xS.
|
2024-02-15 17:05:03 +01:00
|
|
|
|
|
|
|
Stocke le résultat dans self.rccs_tag, un dictionnaire de
|
2024-02-17 02:35:43 +01:00
|
|
|
la forme ``{nom_aggregat: {fid_terminal: RCSTag(fid_terminal)} }``
|
2024-02-15 17:05:03 +01:00
|
|
|
|
|
|
|
Pour rappel : Chaque RCS est identifié par un nom d'aggrégat et par un formsemestre terminal.
|
|
|
|
|
|
|
|
Par exemple :
|
|
|
|
|
|
|
|
* combinaisons '3S' : S1+S2+S3 en prenant en compte tous les S3 qu'ont fréquenté les
|
|
|
|
étudiants du jury PE. Ces S3 marquent les formsemestre terminal de chaque combinaison.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
etudiants: Les données des étudiants
|
|
|
|
semestres_tag: Les semestres tag (pour lesquels des moyennes par tag ont été calculés)
|
2024-01-27 12:21:21 +01:00
|
|
|
"""
|
|
|
|
|
2024-02-16 16:07:48 +01:00
|
|
|
# Génère les moyennes des RCS de type Sx
|
2024-02-25 12:45:58 +01:00
|
|
|
pe_affichage.pe_print(
|
|
|
|
"""****************************************************\n"""
|
|
|
|
"""*** Génère les moyennes associées aux RCSemX \n"""
|
|
|
|
"""****************************************************"""
|
|
|
|
)
|
2024-02-15 17:05:03 +01:00
|
|
|
|
2024-02-25 16:25:28 +01:00
|
|
|
pe_affichage.pe_print("1) Calcul des moyennes des RCSTag")
|
2024-02-15 17:05:03 +01:00
|
|
|
self.rcss_tags = {}
|
2024-02-20 20:52:44 +01:00
|
|
|
for rcs_id, rcsemx in self.rcss_jury.rcsemxs.items():
|
2024-02-21 20:02:38 +01:00
|
|
|
self.rcss_tags[rcs_id] = pe_rcstag.RCSTag(rcsemx, self.sxtags)
|
2024-01-27 12:21:21 +01:00
|
|
|
|
|
|
|
# Intègre le bilan des trajectoires tagguées au zip final
|
2024-02-25 16:25:28 +01:00
|
|
|
pe_affichage.pe_print("2) Bilan")
|
2024-01-27 12:21:21 +01:00
|
|
|
output = io.BytesIO()
|
|
|
|
with pd.ExcelWriter( # pylint: disable=abstract-class-instantiated
|
|
|
|
output, engine="openpyxl"
|
|
|
|
) as writer:
|
2024-02-20 09:13:19 +01:00
|
|
|
onglets = []
|
2024-02-05 19:46:16 +01:00
|
|
|
for rcs_tag in self.rcss_tags.values():
|
2024-02-19 14:50:38 +01:00
|
|
|
onglet = rcs_tag.get_repr(verbose=False)
|
2024-02-21 20:02:38 +01:00
|
|
|
if rcs_tag.is_significatif():
|
|
|
|
df = rcs_tag.to_df()
|
2024-02-24 10:48:38 +01:00
|
|
|
# Conversion colonnes en multiindex
|
|
|
|
df = convert_colonnes_to_multiindex(df)
|
2024-02-25 16:25:28 +01:00
|
|
|
onglets += ["📊" + onglet]
|
2024-02-21 20:02:38 +01:00
|
|
|
# écriture dans l'onglet
|
|
|
|
df.to_excel(writer, onglet, index=True, header=True)
|
2024-02-25 16:25:28 +01:00
|
|
|
pe_affichage.pe_print(f"--> Export excel de {', '.join(onglets)}")
|
2024-01-27 12:21:21 +01:00
|
|
|
output.seek(0)
|
|
|
|
|
2024-02-21 20:02:38 +01:00
|
|
|
if onglets:
|
|
|
|
self.add_file_to_zip(
|
|
|
|
zipfile,
|
|
|
|
f"RCRCFs_{self.diplome}.xlsx",
|
|
|
|
output.read(),
|
|
|
|
path="details",
|
|
|
|
)
|
|
|
|
|
|
|
|
def _gen_xls_interclasstags(self, zipfile: ZipFile):
|
|
|
|
"""Génère les interclassements sur la promo de diplômés
|
|
|
|
par (nom d') aggrégat
|
|
|
|
en distinguant les interclassements par accronymes d'UEs (sur les SxTag)
|
|
|
|
et ceux par compétences (sur les RCSTag).
|
|
|
|
"""
|
|
|
|
pe_affichage.pe_print(
|
2024-02-25 16:25:28 +01:00
|
|
|
"""******************************************************************\n"""
|
|
|
|
"""*** Génère les interclassements sur chaque type de RCS/agrgégat\n"""
|
|
|
|
"""******************************************************************"""
|
2024-01-27 12:21:21 +01:00
|
|
|
)
|
2024-02-21 20:02:38 +01:00
|
|
|
self.interclasstags = {
|
|
|
|
pe_moytag.CODE_MOY_UE: {},
|
|
|
|
pe_moytag.CODE_MOY_COMPETENCES: {},
|
|
|
|
}
|
|
|
|
|
|
|
|
etudiants_diplomes = self.etudiants.etudiants_diplomes
|
|
|
|
|
|
|
|
# Les interclassements par UE
|
|
|
|
for Sx in pe_rcs.TOUS_LES_SEMESTRES:
|
|
|
|
interclass = pe_interclasstag.InterClassTag(
|
|
|
|
Sx,
|
|
|
|
pe_moytag.CODE_MOY_UE,
|
|
|
|
etudiants_diplomes,
|
|
|
|
self.rcss_jury.semXs,
|
|
|
|
self.sxtags,
|
|
|
|
self.rcss_jury.semXs_suivis,
|
|
|
|
)
|
|
|
|
self.interclasstags[pe_moytag.CODE_MOY_UE][Sx] = interclass
|
|
|
|
|
|
|
|
# Les interclassements par compétences
|
|
|
|
for nom_rcs in pe_rcs.TOUS_LES_RCS:
|
|
|
|
interclass = pe_interclasstag.InterClassTag(
|
|
|
|
nom_rcs,
|
|
|
|
pe_moytag.CODE_MOY_COMPETENCES,
|
|
|
|
etudiants_diplomes,
|
|
|
|
self.rcss_jury.rcsemxs,
|
|
|
|
self.rcss_tags,
|
|
|
|
self.rcss_jury.rcsemxs_suivis,
|
|
|
|
)
|
|
|
|
self.interclasstags[pe_moytag.CODE_MOY_COMPETENCES][nom_rcs] = interclass
|
2024-01-27 12:21:21 +01:00
|
|
|
|
|
|
|
# Intègre le bilan des aggrégats (interclassé par promo) au zip final
|
|
|
|
output = io.BytesIO()
|
|
|
|
with pd.ExcelWriter( # pylint: disable=abstract-class-instantiated
|
|
|
|
output, engine="openpyxl"
|
|
|
|
) as writer:
|
2024-02-20 09:13:19 +01:00
|
|
|
onglets = []
|
2024-02-21 20:02:38 +01:00
|
|
|
for type_interclass in [
|
|
|
|
pe_moytag.CODE_MOY_UE,
|
|
|
|
pe_moytag.CODE_MOY_COMPETENCES,
|
|
|
|
]:
|
|
|
|
interclasstag = self.interclasstags[type_interclass]
|
|
|
|
for nom_rcs, interclass in interclasstag.items():
|
|
|
|
onglet = interclass.get_repr()
|
|
|
|
if interclass.is_significatif():
|
|
|
|
df = interclass.to_df(cohorte="Promo")
|
2024-02-24 10:48:38 +01:00
|
|
|
# Conversion colonnes en multiindex
|
|
|
|
df = convert_colonnes_to_multiindex(df)
|
2024-02-21 20:02:38 +01:00
|
|
|
onglets += [onglet]
|
|
|
|
# écriture dans l'onglet
|
|
|
|
df.to_excel(writer, onglet, index=True, header=True)
|
2024-02-20 09:13:19 +01:00
|
|
|
pe_affichage.pe_print(f"=> Export excel de {', '.join(onglets)}")
|
|
|
|
|
2024-01-27 12:21:21 +01:00
|
|
|
output.seek(0)
|
|
|
|
|
2024-02-21 20:02:38 +01:00
|
|
|
if onglets:
|
|
|
|
self.add_file_to_zip(
|
|
|
|
zipfile,
|
|
|
|
f"InterClassTags_{self.diplome}.xlsx",
|
|
|
|
output.read(),
|
|
|
|
path="details",
|
|
|
|
)
|
2024-01-27 12:21:21 +01:00
|
|
|
|
2024-02-02 11:49:24 +01:00
|
|
|
def _gen_xls_synthese_jury_par_tag(self, zipfile: ZipFile):
|
|
|
|
"""Synthèse des éléments du jury PE tag par tag"""
|
2024-02-24 10:48:38 +01:00
|
|
|
pe_affichage.pe_print(
|
|
|
|
"*** Synthèse finale des moyennes par tag et par type de moyennes (UEs ou Compétences)***"
|
|
|
|
)
|
2024-01-27 12:21:21 +01:00
|
|
|
|
2024-02-24 10:48:38 +01:00
|
|
|
self.synthese = {}
|
|
|
|
pe_affichage.pe_print(" -> Synthèse des données administratives")
|
|
|
|
self.synthese["administratif"] = self.etudiants.df_administratif(
|
|
|
|
self.diplomes_ids
|
2024-02-02 11:49:24 +01:00
|
|
|
)
|
|
|
|
|
2024-02-24 10:48:38 +01:00
|
|
|
tags = self._do_tags_list(self.interclasstags)
|
|
|
|
for tag in tags:
|
|
|
|
for type_moy in [pe_moytag.CODE_MOY_UE, pe_moytag.CODE_MOY_COMPETENCES]:
|
|
|
|
self.synthese[(tag, type_moy)] = self.df_tag_type(tag, type_moy)
|
2024-02-02 11:49:24 +01:00
|
|
|
|
|
|
|
# Export des données => mode 1 seule feuille -> supprimé
|
2024-02-24 10:48:38 +01:00
|
|
|
pe_affichage.pe_print("*** Export du jury de synthese par tags")
|
2024-02-02 11:49:24 +01:00
|
|
|
output = io.BytesIO()
|
|
|
|
with pd.ExcelWriter( # pylint: disable=abstract-class-instantiated
|
|
|
|
output, engine="openpyxl"
|
|
|
|
) as writer:
|
2024-02-20 09:13:19 +01:00
|
|
|
onglets = []
|
2024-02-24 10:48:38 +01:00
|
|
|
for onglet, df in self.synthese.items():
|
|
|
|
# Conversion colonnes en multiindex
|
2024-02-24 12:21:42 +01:00
|
|
|
df_final = df.copy()
|
|
|
|
df_final = convert_colonnes_to_multiindex(df_final)
|
2024-02-24 10:48:38 +01:00
|
|
|
# Nom de l'onglet
|
2024-02-24 09:31:47 +01:00
|
|
|
if isinstance(onglet, tuple):
|
|
|
|
if onglet[1] == pe_moytag.CODE_MOY_COMPETENCES:
|
2024-02-24 10:48:38 +01:00
|
|
|
nom_onglet = onglet[0][: 31 - 7] + " (Comp)"
|
2024-02-24 09:31:47 +01:00
|
|
|
else:
|
2024-02-24 10:48:38 +01:00
|
|
|
nom_onglet = onglet[0][: 31 - 5] + " (UE)"
|
2024-02-24 09:31:47 +01:00
|
|
|
else:
|
|
|
|
nom_onglet = onglet
|
|
|
|
onglets += [nom_onglet]
|
2024-02-02 11:49:24 +01:00
|
|
|
# écriture dans l'onglet:
|
2024-02-24 12:21:42 +01:00
|
|
|
df_final.to_excel(writer, nom_onglet, index=True, header=True)
|
2024-02-20 09:13:19 +01:00
|
|
|
pe_affichage.pe_print(f"=> Export excel de {', '.join(onglets)}")
|
2024-02-02 11:49:24 +01:00
|
|
|
output.seek(0)
|
|
|
|
|
|
|
|
self.add_file_to_zip(
|
2024-02-24 10:48:38 +01:00
|
|
|
zipfile, f"synthese_jury_{self.diplome}_par_tag.xlsx", output.read()
|
2024-01-27 12:21:21 +01:00
|
|
|
)
|
2024-01-25 17:17:01 +01:00
|
|
|
|
2024-02-24 10:48:38 +01:00
|
|
|
def _gen_html_synthese_par_etudiant(self, zipfile: ZipFile):
|
|
|
|
"""Synthèse des éléments du jury PE, étudiant par étudiant"""
|
|
|
|
# Synthèse des éléments du jury PE
|
|
|
|
pe_affichage.pe_print("*** Synthèse finale étudiant par étudiant***")
|
|
|
|
|
|
|
|
etudids = list(self.diplomes_ids)
|
|
|
|
for etudid in etudids:
|
|
|
|
nom, prenom, html = self.synthetise_jury_etudiant(etudid)
|
|
|
|
self.add_file_to_zip(
|
|
|
|
zipfile, f"{nom}_{prenom}.html", html, path="etudiants"
|
|
|
|
)
|
|
|
|
|
2024-02-11 22:06:37 +01:00
|
|
|
def _add_log_to_zip(self, zipfile):
|
|
|
|
"""Add a text file with the log messages"""
|
|
|
|
log_data = pe_affichage.pe_get_log()
|
|
|
|
self.add_file_to_zip(zipfile, "pe_log.txt", log_data)
|
|
|
|
|
2024-01-26 10:18:46 +01:00
|
|
|
def add_file_to_zip(self, zipfile: ZipFile, filename: str, data, path=""):
|
|
|
|
"""Add a file to given zip
|
2024-01-25 17:17:01 +01:00
|
|
|
All files under NOM_EXPORT_ZIP/
|
|
|
|
path may specify a subdirectory
|
|
|
|
|
|
|
|
Args:
|
2024-01-26 10:18:46 +01:00
|
|
|
zipfile: ZipFile
|
2024-01-25 17:17:01 +01:00
|
|
|
filename: Le nom du fichier à intégrer au zip
|
|
|
|
data: Les données du fichier
|
|
|
|
path: Un dossier dans l'arborescence du zip
|
|
|
|
"""
|
2024-01-25 19:42:22 +01:00
|
|
|
path_in_zip = os.path.join(path, filename) # self.nom_export_zip,
|
2024-01-26 10:18:46 +01:00
|
|
|
zipfile.writestr(path_in_zip, data)
|
2024-01-25 17:17:01 +01:00
|
|
|
|
2024-01-26 10:18:46 +01:00
|
|
|
def get_zipped_data(self) -> io.BytesIO | None:
|
2024-01-25 17:17:01 +01:00
|
|
|
"""returns file-like data with a zip of all generated (CSV) files.
|
2024-01-26 10:18:46 +01:00
|
|
|
Warning: reset stream to the begining.
|
2024-01-25 17:17:01 +01:00
|
|
|
"""
|
|
|
|
self.zipdata.seek(0)
|
|
|
|
return self.zipdata
|
|
|
|
|
2024-02-21 20:02:38 +01:00
|
|
|
def _do_tags_list(self, interclassements: dict[str, dict]):
|
2024-01-25 17:17:01 +01:00
|
|
|
"""La liste des tags extraites des interclassements"""
|
|
|
|
tags = []
|
2024-02-21 20:02:38 +01:00
|
|
|
# Pour chaque type d'interclassements
|
|
|
|
for type in interclassements:
|
|
|
|
interclassement = interclassements[type]
|
|
|
|
for aggregat in interclassement:
|
|
|
|
interclass = interclassement[aggregat]
|
|
|
|
if interclass.tags_sorted:
|
|
|
|
tags.extend(interclass.tags_sorted)
|
|
|
|
tags = sorted(set(tags))
|
|
|
|
return tags
|
2024-01-25 17:17:01 +01:00
|
|
|
|
|
|
|
# **************************************************************************************************************** #
|
|
|
|
# Méthodes pour la synthèse du juryPE
|
|
|
|
# *****************************************************************************************************************
|
|
|
|
|
2024-02-24 10:48:38 +01:00
|
|
|
def df_tag_type(self, tag, type_moy):
|
2024-02-21 20:02:38 +01:00
|
|
|
"""Génère le DataFrame synthétisant les moyennes/classements (groupe +
|
|
|
|
interclassement promo) pour tous les aggrégats prévus, en fonction
|
|
|
|
du type (UEs ou Compétences) de données souhaitées,
|
2024-01-25 17:17:01 +01:00
|
|
|
tels que fourni dans l'excel final.
|
|
|
|
|
2024-02-21 20:02:38 +01:00
|
|
|
Si type=UEs => tous les sxtag du tag
|
|
|
|
Si type=Compétences => tous les rcstag du tag
|
|
|
|
|
2024-01-25 17:17:01 +01:00
|
|
|
Args:
|
|
|
|
tag: Un des tags (a minima `but`)
|
2024-02-21 20:02:38 +01:00
|
|
|
type_moy: Un type de moyenne
|
2024-01-25 17:17:01 +01:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
"""
|
|
|
|
|
2024-02-03 15:26:58 +01:00
|
|
|
# Les données des étudiants
|
2024-02-21 20:02:38 +01:00
|
|
|
etuds = [etud for etudid, etud in self.etudiants.etudiants_diplomes.items()]
|
|
|
|
df = pe_tabletags.df_administratif(etuds, aggregat="", cohorte="")
|
|
|
|
|
|
|
|
if type_moy == pe_moytag.CODE_MOY_UE:
|
|
|
|
aggregats = pe_rcs.TOUS_LES_SEMESTRES
|
|
|
|
else:
|
|
|
|
aggregats = pe_rcs.TOUS_LES_RCS
|
|
|
|
|
2024-02-24 09:31:47 +01:00
|
|
|
aff_aggregat = []
|
2024-02-21 20:02:38 +01:00
|
|
|
for aggregat in aggregats:
|
|
|
|
# Descr de l'aggrégat
|
|
|
|
descr = pe_rcs.TYPES_RCS[aggregat]["descr"]
|
|
|
|
|
|
|
|
# L'interclassement associé
|
|
|
|
interclass = self.interclasstags[type_moy][aggregat]
|
|
|
|
|
|
|
|
if interclass.is_significatif():
|
|
|
|
# Le dataframe du classement sur le groupe
|
|
|
|
df_groupe = interclass.compute_df_synthese_moyennes_tag(
|
|
|
|
tag, aggregat=aggregat, type_colonnes=False
|
2024-02-03 15:26:58 +01:00
|
|
|
)
|
2024-02-24 09:31:47 +01:00
|
|
|
if not df_groupe.empty:
|
|
|
|
aff_aggregat += [aggregat]
|
|
|
|
df = df.join(df_groupe)
|
2024-02-21 20:02:38 +01:00
|
|
|
|
|
|
|
# Le dataframe du classement sur la promo
|
|
|
|
df_promo = interclass.to_df(
|
|
|
|
administratif=False,
|
|
|
|
aggregat=aggregat,
|
|
|
|
tags_cibles=[tag],
|
|
|
|
cohorte="Promo",
|
|
|
|
)
|
2024-02-24 09:31:47 +01:00
|
|
|
if not df_promo.empty:
|
|
|
|
aff_aggregat += [aggregat]
|
|
|
|
df = df.join(df_promo)
|
2024-02-03 15:26:58 +01:00
|
|
|
|
2024-02-24 09:31:47 +01:00
|
|
|
if aff_aggregat:
|
|
|
|
aff_aggregat = sorted(set(aff_aggregat))
|
|
|
|
pe_affichage.pe_print(
|
|
|
|
f" -> Synthèse de 👜{tag} par {type_moy} avec {', '.join(aff_aggregat)}"
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
pe_affichage.pe_print(f" -> Synthèse du tag {tag} par {type_moy} : <vide>")
|
2024-02-24 10:48:38 +01:00
|
|
|
|
2024-02-21 20:02:38 +01:00
|
|
|
return df
|
|
|
|
# Fin de l'aggrégat
|
2024-01-25 17:17:01 +01:00
|
|
|
|
2024-02-24 10:48:38 +01:00
|
|
|
def synthetise_jury_etudiant(self, etudid) -> (str, str, str):
|
|
|
|
"""Synthétise les résultats d'un étudiant dans un
|
|
|
|
fichier html à son nom en s'appuyant sur la synthese final
|
2024-02-02 11:49:24 +01:00
|
|
|
|
2024-02-24 10:48:38 +01:00
|
|
|
Returns:
|
|
|
|
Un tuple nom, prenom, html
|
|
|
|
"""
|
|
|
|
etudiant = self.etudiants.identites[etudid]
|
|
|
|
nom = etudiant.nom
|
|
|
|
prenom = etudiant.prenom # initial du prénom
|
2024-02-24 12:21:42 +01:00
|
|
|
|
|
|
|
# Accès au template
|
|
|
|
environnement = jinja2.Environment(
|
|
|
|
loader=jinja2.FileSystemLoader("app/templates/")
|
|
|
|
)
|
|
|
|
template = environnement.get_template("pe/pe_view_resultats_etudiant.j2")
|
|
|
|
|
|
|
|
# Colonnes des tableaux htmls => competences
|
|
|
|
competences = []
|
|
|
|
for aggregat in pe_rcs.TOUS_LES_RCS_AVEC_PLUSIEURS_SEM:
|
|
|
|
# L'interclassement associé
|
|
|
|
interclass = self.interclasstags[pe_moytag.CODE_MOY_COMPETENCES][aggregat]
|
|
|
|
competences.extend(interclass.champs_sorted)
|
|
|
|
competences = sorted(set(competences))
|
|
|
|
colonnes_html = competences
|
2024-02-02 11:49:24 +01:00
|
|
|
|
2024-02-21 20:02:38 +01:00
|
|
|
tags = self._do_tags_list(self.interclasstags)
|
2024-02-24 12:21:42 +01:00
|
|
|
|
2024-02-25 10:39:51 +01:00
|
|
|
# Descripti
|
|
|
|
|
2024-02-24 12:21:42 +01:00
|
|
|
# Les données par UE
|
|
|
|
moyennes = {}
|
|
|
|
for tag in tags:
|
|
|
|
moyennes[tag] = {}
|
|
|
|
# Les données de synthèse
|
|
|
|
df = self.synthese[(tag, pe_moytag.CODE_MOY_COMPETENCES)]
|
2024-02-25 10:39:51 +01:00
|
|
|
for aggregat in pe_rcs.TOUS_LES_RCS:
|
2024-02-24 12:21:42 +01:00
|
|
|
moyennes[tag][aggregat] = {}
|
|
|
|
for comp in competences + ["Général"]:
|
|
|
|
moyennes[tag][aggregat][comp] = {
|
|
|
|
"note": "",
|
|
|
|
"rang_groupe": "",
|
|
|
|
"rang_promo": "",
|
|
|
|
}
|
|
|
|
colonne = pe_moytag.get_colonne_df(
|
|
|
|
aggregat, tag, comp, "Groupe", "note"
|
|
|
|
)
|
|
|
|
if colonne in df.columns:
|
|
|
|
valeur = df.loc[etudid, colonne]
|
|
|
|
if not np.isnan(valeur):
|
|
|
|
moyennes[tag][aggregat][comp]["note"] = round(valeur, 2)
|
|
|
|
colonne = pe_moytag.get_colonne_df(
|
|
|
|
aggregat, tag, comp, "Groupe", "rang"
|
|
|
|
)
|
|
|
|
if colonne in df.columns:
|
|
|
|
valeur = df.loc[etudid, colonne]
|
|
|
|
if valeur != "nan":
|
|
|
|
moyennes[tag][aggregat][comp]["rang_groupe"] = valeur
|
|
|
|
colonne = pe_moytag.get_colonne_df(
|
|
|
|
aggregat, tag, comp, "Promo", "rang"
|
|
|
|
)
|
|
|
|
if colonne in df.columns:
|
|
|
|
valeur = df.loc[etudid, colonne]
|
|
|
|
if valeur != "nan":
|
|
|
|
moyennes[tag][aggregat][comp]["rang_promo"] = valeur
|
|
|
|
|
|
|
|
html = template.render(
|
|
|
|
nom=nom,
|
|
|
|
prenom=prenom,
|
|
|
|
colonnes_html=colonnes_html,
|
|
|
|
tags=tags,
|
|
|
|
moyennes=moyennes,
|
|
|
|
)
|
2024-02-24 10:48:38 +01:00
|
|
|
# for onglet, df_synthese in self.synthese.items():
|
|
|
|
# if isinstance(onglet, tuple): # Les onglets autres que "administratif"
|
|
|
|
# tag = onglet[0]
|
|
|
|
# type_moy = onglet[1]
|
2024-02-02 11:49:24 +01:00
|
|
|
|
2024-02-24 10:48:38 +01:00
|
|
|
# colonnes = list(df_synthese.columns)
|
2024-02-02 11:49:24 +01:00
|
|
|
|
2024-02-24 10:48:38 +01:00
|
|
|
return (nom, prenom, html)
|
2024-01-25 17:17:01 +01:00
|
|
|
|
2024-02-08 22:09:11 +01:00
|
|
|
|
2024-02-17 03:30:19 +01:00
|
|
|
def get_formsemestres_etudiants(etudiants: pe_etudiant.EtudiantsJuryPE) -> dict:
|
2024-02-05 12:58:09 +01:00
|
|
|
"""Ayant connaissance des étudiants dont il faut calculer les moyennes pour
|
2024-02-17 02:35:43 +01:00
|
|
|
le jury PE (attribut `self.etudiant_ids) et de leurs trajectoires (semestres
|
|
|
|
parcourus), renvoie un dictionnaire ``{fid: FormSemestre(fid)}``
|
2024-02-05 12:58:09 +01:00
|
|
|
contenant l'ensemble des formsemestres de leurs cursus, dont il faudra calculer
|
|
|
|
la moyenne.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
etudiants: Les étudiants du jury PE
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Un dictionnaire de la forme `{fid: FormSemestre(fid)}`
|
|
|
|
"""
|
|
|
|
semestres = {}
|
|
|
|
for etudid in etudiants.etudiants_ids:
|
2024-02-20 16:22:22 +01:00
|
|
|
for cle in etudiants.cursus[etudid]:
|
2024-02-05 12:58:09 +01:00
|
|
|
if cle.startswith("S"):
|
2024-02-20 16:22:22 +01:00
|
|
|
semestres = semestres | etudiants.cursus[etudid][cle]
|
2024-02-05 12:58:09 +01:00
|
|
|
return semestres
|
2024-02-03 10:46:14 +01:00
|
|
|
|
2024-02-08 22:09:11 +01:00
|
|
|
|
2024-02-24 10:48:38 +01:00
|
|
|
def convert_colonnes_to_multiindex(df):
|
|
|
|
"""Convertit les colonnes d'un df pour obtenir des colonnes
|
|
|
|
multiindex"""
|
|
|
|
colonnes = list(df.columns)
|
|
|
|
colonnes = [tuple(col.split("|")) for col in colonnes]
|
|
|
|
df.columns = pd.MultiIndex.from_tuples(colonnes)
|
|
|
|
return df
|