2020-09-26 16:19:37 +02:00
|
|
|
# -*- mode: python -*-
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# Gestion scolarite IUT
|
|
|
|
#
|
2023-01-02 13:16:27 +01:00
|
|
|
# Copyright (c) 1999 - 2023 Emmanuel Viennet. All rights reserved.
|
2020-09-26 16:19:37 +02: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
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
"""Exportation des résultats des étudiants vers Apogée.
|
|
|
|
|
2021-02-01 23:54:46 +01:00
|
|
|
Ce code a été au départ inspiré par les travaux de Damien Mascré, scodoc2apogee (en Java).
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
A utiliser en fin de semestre, après les jury.
|
|
|
|
|
|
|
|
On communique avec Apogée via des fichiers CSV.
|
|
|
|
|
|
|
|
Le fichier CSV, champs séparés par des tabulations, a la structure suivante:
|
|
|
|
|
|
|
|
<pre>
|
|
|
|
XX-APO_TITRES-XX
|
|
|
|
apoC_annee 2007/2008
|
|
|
|
apoC_cod_dip VDTCJ
|
|
|
|
apoC_Cod_Exp 1
|
|
|
|
apoC_cod_vdi 111
|
|
|
|
apoC_Fichier_Exp VDTCJ_V1CJ.txt
|
|
|
|
apoC_lib_dip DUT CJ
|
|
|
|
apoC_Titre1 Export Apogée du 13/06/2008 à 14:29
|
|
|
|
apoC_Titre2
|
|
|
|
|
|
|
|
XX-APO_COLONNES-XX
|
|
|
|
apoL_a01_code Type Objet Code Version Année Session Admission/Admissibilité Type Rés. Etudiant Numéro
|
|
|
|
apoL_a02_nom 1 Nom
|
|
|
|
apoL_a03_prenom 1 Prénom
|
|
|
|
apoL_a04_naissance Session Admissibilité Naissance
|
|
|
|
APO_COL_VAL_DEB
|
|
|
|
apoL_c0001 VET V1CJ 111 2007 0 1 N V1CJ - DUT CJ an1 0 1 Note
|
|
|
|
apoL_c0002 VET V1CJ 111 2007 0 1 B 0 1 Barème
|
|
|
|
apoL_c0003 VET V1CJ 111 2007 0 1 R 0 1 Résultat
|
|
|
|
APO_COL_VAL_FIN
|
|
|
|
apoL_c0030 APO_COL_VAL_FIN
|
|
|
|
|
|
|
|
XX-APO_VALEURS-XX
|
|
|
|
apoL_a01_code apoL_a02_nom apoL_a03_prenom apoL_a04_naissance apoL_c0001 apoL_c0002 apoL_c0003 apoL_c0004 apoL_c0005 apoL_c0006 apoL_c0007 apoL_c0008 apoL_c0009 apoL_c0010 apoL_c0011 apoL_c0012 apoL_c0013 apoL_c0014 apoL_c0015 apoL_c0016 apoL_c0017 apoL_c0018 apoL_c0019 apoL_c0020 apoL_c0021 apoL_c0022 apoL_c0023 apoL_c0024 apoL_c0025 apoL_c0026 apoL_c0027 apoL_c0028 apoL_c0029
|
|
|
|
10601232 AARIF MALIKA 22/09/1986 18 20 ADM 18 20 ADM 18 20 ADM 18 20 ADM 18 20 ADM 18 20 18 20 ADM 18 20 ADM 18 20 ADM 18 20 ADM
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
|
|
|
|
On récupère nos éléments pédagogiques dans la section XX-APO-COLONNES-XX et
|
|
|
|
notre liste d'étudiants dans la section XX-APO_VALEURS-XX. Les champs de la
|
|
|
|
section XX-APO_VALEURS-XX sont décrits par les lignes successives de la
|
|
|
|
section XX-APO_COLONNES-XX.
|
|
|
|
|
|
|
|
Le fichier CSV correspond à une étape, qui est récupérée sur la ligne
|
|
|
|
<pre>
|
|
|
|
apoL_c0001 VET V1CJ ...
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
|
|
|
|
XXX A vérifier:
|
|
|
|
AJAC car 1 sem. validé et pas de NAR
|
|
|
|
|
|
|
|
"""
|
2021-02-01 23:54:46 +01:00
|
|
|
|
|
|
|
import collections
|
|
|
|
import datetime
|
2021-08-31 19:32:12 +02:00
|
|
|
from functools import reduce
|
2022-04-05 11:44:08 +02:00
|
|
|
import functools
|
2021-08-15 15:01:13 +02:00
|
|
|
import io
|
2021-02-01 23:54:46 +01:00
|
|
|
import os
|
2021-08-31 19:32:12 +02:00
|
|
|
import pprint
|
2021-08-15 15:01:13 +02:00
|
|
|
import re
|
|
|
|
import time
|
2020-09-26 16:19:37 +02:00
|
|
|
from zipfile import ZipFile
|
2021-08-31 19:32:12 +02:00
|
|
|
|
|
|
|
from flask import send_file
|
2022-08-25 18:43:24 +02:00
|
|
|
import numpy as np
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2021-06-24 18:54:59 +02:00
|
|
|
# Pour la détection auto de l'encodage des fichiers Apogée:
|
2021-07-19 19:53:01 +02:00
|
|
|
from chardet import detect as chardet_detect
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2022-02-13 23:53:11 +01:00
|
|
|
from app import log
|
|
|
|
from app.comp import res_sem
|
2022-03-27 22:25:00 +02:00
|
|
|
from app.comp.res_compat import NotesTableCompat
|
2023-04-16 05:32:21 +02:00
|
|
|
from app.comp.res_but import ResultatsSemestreBUT
|
|
|
|
from app.models import FormSemestre, Identite, ApcValidationAnnee
|
2022-01-21 00:46:45 +01:00
|
|
|
from app.models.config import ScoDocSiteConfig
|
2021-06-19 23:21:37 +02:00
|
|
|
import app.scodoc.sco_utils as scu
|
2021-12-03 14:13:49 +01:00
|
|
|
from app.scodoc.sco_exceptions import ScoValueError, ScoFormatError
|
2021-06-19 23:21:37 +02:00
|
|
|
from app.scodoc.gen_tables import GenTable
|
2021-07-10 13:55:35 +02:00
|
|
|
from app.scodoc.sco_vdi import ApoEtapeVDI
|
2023-02-12 13:36:47 +01:00
|
|
|
from app.scodoc.codes_cursus import code_semestre_validant
|
|
|
|
from app.scodoc.codes_cursus import (
|
2021-06-19 23:21:37 +02:00
|
|
|
DEF,
|
2022-01-21 00:46:45 +01:00
|
|
|
DEM,
|
2021-06-19 23:21:37 +02:00
|
|
|
NAR,
|
|
|
|
RAT,
|
|
|
|
)
|
2022-07-07 16:24:52 +02:00
|
|
|
from app.scodoc import sco_cursus
|
2021-06-19 23:21:37 +02:00
|
|
|
from app.scodoc import sco_formsemestre
|
|
|
|
from app.scodoc import sco_etud
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
APO_PORTAL_ENCODING = (
|
|
|
|
"utf8" # encodage du fichier CSV Apogée (était 'ISO-8859-1' avant jul. 2016)
|
|
|
|
)
|
|
|
|
APO_INPUT_ENCODING = "ISO-8859-1" #
|
|
|
|
APO_OUTPUT_ENCODING = APO_INPUT_ENCODING # encodage des fichiers Apogee générés
|
|
|
|
APO_DECIMAL_SEP = "," # separateur décimal: virgule
|
|
|
|
APO_SEP = "\t"
|
|
|
|
APO_NEWLINE = "\r\n"
|
|
|
|
|
|
|
|
|
2022-04-05 11:44:08 +02:00
|
|
|
def _apo_fmt_note(note, fmt="%3.2f"):
|
2020-09-26 16:19:37 +02:00
|
|
|
"Formatte une note pour Apogée (séparateur décimal: ',')"
|
2022-01-31 23:15:42 +01:00
|
|
|
# if not note and isinstance(note, float): changé le 31/1/2022, étrange ?
|
|
|
|
# return ""
|
2020-09-26 16:19:37 +02:00
|
|
|
try:
|
|
|
|
val = float(note)
|
|
|
|
except ValueError:
|
|
|
|
return ""
|
2022-08-25 18:43:24 +02:00
|
|
|
if np.isnan(val):
|
|
|
|
return ""
|
2022-04-05 11:44:08 +02:00
|
|
|
return (fmt % val).replace(".", APO_DECIMAL_SEP)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
def guess_data_encoding(text, threshold=0.6):
|
|
|
|
"""Guess string encoding, using chardet heuristics.
|
2021-07-19 19:53:01 +02:00
|
|
|
Returns encoding, or None if detection failed (confidence below threshold)
|
2020-09-26 16:19:37 +02:00
|
|
|
"""
|
|
|
|
r = chardet_detect(text)
|
|
|
|
if r["confidence"] < threshold:
|
|
|
|
return None
|
|
|
|
else:
|
|
|
|
return r["encoding"]
|
|
|
|
|
|
|
|
|
|
|
|
def fix_data_encoding(
|
2022-01-07 17:58:34 +01:00
|
|
|
text: bytes,
|
|
|
|
default_source_encoding=APO_INPUT_ENCODING,
|
|
|
|
dest_encoding=APO_INPUT_ENCODING,
|
2023-01-31 18:00:11 +01:00
|
|
|
) -> tuple[bytes, str]:
|
2020-09-26 16:19:37 +02:00
|
|
|
"""Try to ensure that text is using dest_encoding
|
2021-01-01 18:40:47 +01:00
|
|
|
returns converted text, and a message describing the conversion.
|
2023-01-31 18:00:11 +01:00
|
|
|
|
|
|
|
Raises UnicodeEncodeError en cas de problème, en général liée à
|
|
|
|
une auto-détection errornée.
|
2020-09-26 16:19:37 +02:00
|
|
|
"""
|
|
|
|
message = ""
|
|
|
|
detected_encoding = guess_data_encoding(text)
|
|
|
|
if not detected_encoding:
|
|
|
|
if default_source_encoding != dest_encoding:
|
2023-01-31 18:00:11 +01:00
|
|
|
message = f"converting from {default_source_encoding} to {dest_encoding}"
|
|
|
|
text = text.decode(default_source_encoding).encode(dest_encoding)
|
2020-09-26 16:19:37 +02:00
|
|
|
else:
|
|
|
|
if detected_encoding != dest_encoding:
|
2023-01-31 18:00:11 +01:00
|
|
|
message = (
|
|
|
|
f"converting from detected {default_source_encoding} to {dest_encoding}"
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
2023-01-31 18:00:11 +01:00
|
|
|
text = text.decode(detected_encoding).encode(dest_encoding)
|
2020-09-26 16:19:37 +02:00
|
|
|
return text, message
|
|
|
|
|
|
|
|
|
2023-03-16 12:46:27 +01:00
|
|
|
class StringIOFileLineWrapper:
|
2022-01-07 17:58:34 +01:00
|
|
|
def __init__(self, data: str):
|
2021-08-15 15:01:13 +02:00
|
|
|
self.f = io.StringIO(data)
|
2020-09-26 16:19:37 +02:00
|
|
|
self.lineno = 0
|
|
|
|
|
|
|
|
def close(self):
|
|
|
|
return self.f.close()
|
|
|
|
|
|
|
|
def readline(self):
|
|
|
|
self.lineno += 1
|
|
|
|
return self.f.readline()
|
|
|
|
|
|
|
|
|
|
|
|
class DictCol(dict):
|
|
|
|
"A dict, where we can add attributes"
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2021-07-09 23:31:16 +02:00
|
|
|
class ApoElt(object):
|
2020-09-26 16:19:37 +02:00
|
|
|
"""Definition d'un Element Apogee
|
|
|
|
sur plusieurs colonnes du fichier CSV
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, cols):
|
|
|
|
assert len(cols) > 0
|
|
|
|
assert len(set([c["Code"] for c in cols])) == 1 # colonnes de meme code
|
|
|
|
assert len(set([c["Type Objet"] for c in cols])) == 1 # colonnes de meme type
|
|
|
|
self.cols = cols
|
|
|
|
self.code = cols[0]["Code"]
|
|
|
|
self.version = cols[0]["Version"]
|
|
|
|
self.type_objet = cols[0]["Type Objet"]
|
|
|
|
|
|
|
|
def append(self, col):
|
|
|
|
assert col["Code"] == self.code
|
|
|
|
if col["Type Objet"] != self.type_objet:
|
|
|
|
log(
|
|
|
|
"Warning: ApoElt: duplicate id %s (%s and %s)"
|
|
|
|
% (self.code, self.type_objet, col["Type Objet"])
|
|
|
|
)
|
|
|
|
self.type_objet = col["Type Objet"]
|
|
|
|
self.cols.append(col)
|
|
|
|
|
|
|
|
def __repr__(self):
|
2023-04-16 05:32:21 +02:00
|
|
|
return f"ApoElt(code='{self.code}', cols={pprint.pformat(self.cols)})"
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
2023-04-16 05:32:21 +02:00
|
|
|
class EtuCol:
|
2020-09-26 16:19:37 +02:00
|
|
|
"""Valeurs colonnes d'un element pour un etudiant"""
|
|
|
|
|
|
|
|
def __init__(self, nip, apo_elt, init_vals):
|
|
|
|
pass # XXX
|
|
|
|
|
|
|
|
|
|
|
|
ETUD_OK = "ok"
|
|
|
|
ETUD_ORPHELIN = "orphelin"
|
|
|
|
ETUD_NON_INSCRIT = "non_inscrit"
|
|
|
|
|
|
|
|
VOID_APO_RES = dict(N="", B="", J="", R="", M="")
|
|
|
|
|
|
|
|
|
|
|
|
class ApoEtud(dict):
|
2022-09-03 11:41:56 +02:00
|
|
|
"""Étudiant Apogee:"""
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
nip="",
|
|
|
|
nom="",
|
|
|
|
prenom="",
|
|
|
|
naissance="",
|
|
|
|
cols={},
|
|
|
|
export_res_etape=True,
|
|
|
|
export_res_sem=True,
|
|
|
|
export_res_ues=True,
|
|
|
|
export_res_modules=True,
|
|
|
|
export_res_sdj=True,
|
|
|
|
export_res_rat=True,
|
|
|
|
):
|
|
|
|
self["nip"] = nip
|
|
|
|
self["nom"] = nom
|
|
|
|
self["prenom"] = prenom
|
|
|
|
self["naissance"] = naissance
|
2022-07-02 11:17:04 +02:00
|
|
|
self.cols = cols
|
|
|
|
"{ col_id : value } colid = 'apoL_c0001'"
|
2022-07-13 11:30:01 +02:00
|
|
|
self.is_apc = None
|
|
|
|
"Vrai si BUT"
|
2022-07-02 11:17:04 +02:00
|
|
|
self.col_elts = {}
|
|
|
|
"{'V1RT': {'R': 'ADM', 'J': '', 'B': 20, 'N': '12.14'}}"
|
|
|
|
self.etud: Identite = None
|
|
|
|
"etudiant ScoDoc associé"
|
2020-09-26 16:19:37 +02:00
|
|
|
self.etat = None # ETUD_OK, ...
|
2022-07-02 11:17:04 +02:00
|
|
|
self.is_NAR = False
|
|
|
|
"True si NARé dans un semestre"
|
2020-09-26 16:19:37 +02:00
|
|
|
self.log = []
|
|
|
|
self.has_logged_no_decision = False
|
|
|
|
self.export_res_etape = export_res_etape # VET, ...
|
|
|
|
self.export_res_sem = export_res_sem # elt_sem_apo
|
|
|
|
self.export_res_ues = export_res_ues
|
|
|
|
self.export_res_modules = export_res_modules
|
2023-04-16 05:32:21 +02:00
|
|
|
self.export_res_sdj = export_res_sdj
|
|
|
|
"export meme si pas de decision de jury"
|
2020-09-26 16:19:37 +02:00
|
|
|
self.export_res_rat = export_res_rat
|
2022-04-05 11:44:08 +02:00
|
|
|
self.fmt_note = functools.partial(
|
|
|
|
_apo_fmt_note, fmt=ScoDocSiteConfig.get_code_apo("NOTES_FMT") or "3.2f"
|
|
|
|
)
|
2023-04-19 11:51:58 +02:00
|
|
|
# Initialisés par associate_sco:
|
|
|
|
self.autre_sem: dict = None
|
|
|
|
self.autre_res: NotesTableCompat = None
|
|
|
|
self.cur_sem: dict = None
|
|
|
|
self.cur_res: NotesTableCompat = None
|
|
|
|
self.new_cols = {}
|
|
|
|
"{ col_id : value to record in csv }"
|
|
|
|
|
|
|
|
# Pour le BUT:
|
|
|
|
self.validation_annee_but: ApcValidationAnnee = None
|
|
|
|
"validation de jury annuelle BUT, ou None"
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
def __repr__(self):
|
2022-07-02 11:17:04 +02:00
|
|
|
return f"""ApoEtud( nom='{self["nom"]}', nip='{self["nip"]}' )"""
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2021-08-21 00:24:51 +02:00
|
|
|
def lookup_scodoc(self, etape_formsemestre_ids):
|
2021-06-25 16:27:55 +02:00
|
|
|
"""Cherche l'étudiant ScoDoc associé à cet étudiant Apogée.
|
|
|
|
S'il n'est pas trouvé (état "orphelin", dans Apo mais pas chez nous),
|
|
|
|
met .etud à None.
|
|
|
|
Sinon, cherche le semestre, et met l'état à ETUD_OK ou ETUD_NON_INSCRIT.
|
|
|
|
"""
|
2022-07-02 11:17:04 +02:00
|
|
|
|
|
|
|
# futur: #WIP
|
2023-03-20 11:17:38 +01:00
|
|
|
# etud: Identite = Identite.query.filter_by(code_nip=self["nip"], dept_id=g.scodoc_dept_id).first()
|
2022-07-02 11:17:04 +02:00
|
|
|
# self.etud = etud
|
2021-06-19 23:21:37 +02:00
|
|
|
etuds = sco_etud.get_etud_info(code_nip=self["nip"], filled=True)
|
2020-09-26 16:19:37 +02:00
|
|
|
if not etuds:
|
|
|
|
# pas dans ScoDoc
|
|
|
|
self.etud = None
|
|
|
|
self.log.append("non inscrit dans ScoDoc")
|
|
|
|
self.etat = ETUD_ORPHELIN
|
|
|
|
else:
|
2022-07-02 11:17:04 +02:00
|
|
|
# futur: #WIP
|
|
|
|
# formsemestre_ids = {
|
|
|
|
# ins.formsemestre_id for ins in etud.formsemestre_inscriptions
|
|
|
|
# }
|
|
|
|
# in_formsemestre_ids = formsemestre_ids.intersection(etape_formsemestre_ids)
|
2020-09-26 16:19:37 +02:00
|
|
|
self.etud = etuds[0]
|
|
|
|
# cherche le semestre ScoDoc correspondant à l'un de ceux de l'etape:
|
|
|
|
formsemestre_ids = {s["formsemestre_id"] for s in self.etud["sems"]}
|
2022-07-02 11:17:04 +02:00
|
|
|
in_formsemestre_ids = formsemestre_ids.intersection(etape_formsemestre_ids)
|
|
|
|
if not in_formsemestre_ids:
|
2020-09-26 16:19:37 +02:00
|
|
|
self.log.append(
|
|
|
|
"connu dans ScoDoc, mais pas inscrit dans un semestre de cette étape"
|
|
|
|
)
|
|
|
|
self.etat = ETUD_NON_INSCRIT
|
|
|
|
else:
|
|
|
|
self.etat = ETUD_OK
|
|
|
|
|
2022-07-02 11:17:04 +02:00
|
|
|
def associate_sco(self, apo_data: "ApoData"):
|
2020-09-26 16:19:37 +02:00
|
|
|
"""Recherche les valeurs des éléments Apogée pour cet étudiant
|
|
|
|
Set .new_cols
|
|
|
|
"""
|
|
|
|
self.col_elts = {} # {'V1RT': {'R': 'ADM', 'J': '', 'B': 20, 'N': '12.14'}}
|
|
|
|
if self.etat is None:
|
2021-08-21 00:24:51 +02:00
|
|
|
self.lookup_scodoc(apo_data.etape_formsemestre_ids)
|
2020-09-26 16:19:37 +02:00
|
|
|
if self.etat != ETUD_OK:
|
|
|
|
self.new_cols = (
|
|
|
|
self.cols
|
|
|
|
) # etudiant inconnu, recopie les valeurs existantes dans Apo
|
|
|
|
else:
|
|
|
|
sco_elts = {} # valeurs trouvées dans ScoDoc code : { N, B, J, R }
|
|
|
|
for col_id in apo_data.col_ids[4:]:
|
|
|
|
code = apo_data.cols[col_id]["Code"] # 'V1RT'
|
2023-04-19 11:51:58 +02:00
|
|
|
elt = sco_elts.get(code, None)
|
|
|
|
# elt est {'R': ADM, 'J': '', 'B': 20, 'N': '12.14'}
|
|
|
|
if elt is None: # pas déjà trouvé
|
|
|
|
self.etud_set_semestres_de_etape(apo_data)
|
2020-09-26 16:19:37 +02:00
|
|
|
for sem in apo_data.sems_etape:
|
2023-04-19 11:51:58 +02:00
|
|
|
elt = self.search_elt_in_sem(code, sem)
|
|
|
|
if elt is not None:
|
|
|
|
sco_elts[code] = elt
|
2020-09-26 16:19:37 +02:00
|
|
|
break
|
2023-04-19 11:51:58 +02:00
|
|
|
self.col_elts[code] = elt
|
|
|
|
if elt is None:
|
2020-09-26 16:19:37 +02:00
|
|
|
self.new_cols[col_id] = self.cols[col_id]
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
self.new_cols[col_id] = sco_elts[code][
|
|
|
|
apo_data.cols[col_id]["Type Rés."]
|
|
|
|
]
|
2022-07-02 11:17:04 +02:00
|
|
|
except KeyError as exc:
|
2020-09-26 16:19:37 +02:00
|
|
|
log(
|
2023-04-16 05:32:21 +02:00
|
|
|
f"""associate_sco: missing key, etud={self}\ncode='{
|
|
|
|
code}'\netape='{apo_data.etape_apogee}'"""
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
|
|
|
raise ScoValueError(
|
2022-07-02 11:17:04 +02:00
|
|
|
f"""L'élément {code} n'a pas de résultat: peut-être une erreur
|
|
|
|
dans les codes sur le programme pédagogique
|
|
|
|
(vérifier qu'il est bien associé à une UE ou semestre)?"""
|
|
|
|
) from exc
|
2020-09-26 16:19:37 +02:00
|
|
|
# recopie les 4 premieres colonnes (nom, ..., naissance):
|
|
|
|
for col_id in apo_data.col_ids[:4]:
|
|
|
|
self.new_cols[col_id] = self.cols[col_id]
|
|
|
|
|
2021-02-01 23:54:46 +01:00
|
|
|
# def unassociated_codes(self, apo_data):
|
|
|
|
# "list of apo elements for this student without a value in ScoDoc"
|
|
|
|
# codes = set([apo_data.cols[col_id].code for col_id in apo_data.col_ids])
|
|
|
|
# return codes - set(sco_elts)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2023-04-19 11:51:58 +02:00
|
|
|
def search_elt_in_sem(self, code, sem) -> dict:
|
2020-09-26 16:19:37 +02:00
|
|
|
"""
|
2023-04-16 05:32:21 +02:00
|
|
|
VET code jury etape (en BUT, le code annuel)
|
2020-09-26 16:19:37 +02:00
|
|
|
ELP élément pédagogique: UE, module
|
|
|
|
Autres éléments: résultats du semestre ou de l'année scolaire:
|
|
|
|
=> VRTW1: code additionnel au semestre ("code élement semestre", elt_sem_apo)
|
|
|
|
=> VRT1A: le même que le VET: ("code élement annuel", elt_annee_apo)
|
2021-01-01 18:40:47 +01:00
|
|
|
Attention, si le semestre couvre plusieurs étapes, indiquer les codes des éléments,
|
2020-09-26 16:19:37 +02:00
|
|
|
séparés par des virgules.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
code (str): code apo de l'element cherché
|
|
|
|
sem (dict): semestre dans lequel on cherche l'élément
|
|
|
|
cur_sem (dict): semestre "courant" pour résultats annuels (VET)
|
2023-04-19 11:51:58 +02:00
|
|
|
autre_sem (dict): autre semestre utilisé pour calculer les résultats annuels (VET)
|
2021-01-01 18:40:47 +01:00
|
|
|
|
2020-09-26 16:19:37 +02:00
|
|
|
Returns:
|
|
|
|
dict: with N, B, J, R keys, ou None si elt non trouvé
|
|
|
|
"""
|
|
|
|
etudid = self.etud["etudid"]
|
2023-04-19 11:51:58 +02:00
|
|
|
if not self.cur_res:
|
|
|
|
log("search_elt_in_sem: no cur_res !")
|
|
|
|
return None
|
|
|
|
if sem["formsemestre_id"] == self.cur_res.formsemestre.id:
|
|
|
|
res = self.cur_res
|
|
|
|
elif (
|
|
|
|
self.autre_res and sem["formsemestre_id"] == self.autre_res.formsemestre.id
|
|
|
|
):
|
|
|
|
res = self.autre_res
|
|
|
|
else:
|
|
|
|
formsemestre = FormSemestre.query.get_or_404(sem["formsemestre_id"])
|
|
|
|
res: NotesTableCompat = res_sem.load_formsemestre_results(formsemestre)
|
2022-02-13 23:53:11 +01:00
|
|
|
|
2023-04-19 11:51:58 +02:00
|
|
|
if etudid not in res.identdict:
|
2020-09-26 16:19:37 +02:00
|
|
|
return None # etudiant non inscrit dans ce semestre
|
|
|
|
|
2023-04-19 11:51:58 +02:00
|
|
|
if not self.export_res_sdj and not res.etud_has_decision(etudid):
|
2020-09-26 16:19:37 +02:00
|
|
|
# pas de decision de jury, on n'enregistre rien
|
|
|
|
# (meme si démissionnaire)
|
|
|
|
if not self.has_logged_no_decision:
|
2023-04-16 05:32:21 +02:00
|
|
|
self.log.append("Pas de décision (export désactivé)")
|
2020-09-26 16:19:37 +02:00
|
|
|
self.has_logged_no_decision = True
|
|
|
|
return VOID_APO_RES
|
|
|
|
|
2023-04-19 11:51:58 +02:00
|
|
|
if res.is_apc: # export BUT
|
|
|
|
self._but_load_validation_annuelle()
|
|
|
|
else:
|
|
|
|
decision = res.get_etud_decision_sem(etudid)
|
|
|
|
if decision and decision["code"] == NAR:
|
|
|
|
self.is_NAR = True
|
|
|
|
# Element semestre: (non BUT donc)
|
|
|
|
if code in {x.strip() for x in sem["elt_sem_apo"].split(",")}:
|
|
|
|
if self.export_res_sem:
|
|
|
|
return self.comp_elt_semestre(res, decision, etudid)
|
|
|
|
else:
|
|
|
|
return VOID_APO_RES
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
# Element etape (annuel ou non):
|
|
|
|
if sco_formsemestre.sem_has_etape(sem, code) or (
|
2022-04-22 14:35:44 +02:00
|
|
|
code in {x.strip() for x in sem["elt_annee_apo"].split(",")}
|
2020-09-26 16:19:37 +02:00
|
|
|
):
|
|
|
|
export_res_etape = self.export_res_etape
|
2023-04-19 11:51:58 +02:00
|
|
|
if (not export_res_etape) and self.cur_sem:
|
2020-09-26 16:19:37 +02:00
|
|
|
# exporte toujours le résultat de l'étape si l'étudiant est diplômé
|
2022-07-07 16:24:52 +02:00
|
|
|
Se = sco_cursus.get_situation_etud_cursus(
|
2023-04-19 11:51:58 +02:00
|
|
|
self.etud, self.cur_sem["formsemestre_id"]
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
|
|
|
export_res_etape = Se.all_other_validated()
|
|
|
|
|
|
|
|
if export_res_etape:
|
2023-04-19 11:51:58 +02:00
|
|
|
return self.comp_elt_annuel(etudid)
|
2020-09-26 16:19:37 +02:00
|
|
|
else:
|
2023-04-16 05:32:21 +02:00
|
|
|
self.log.append("export étape désactivé")
|
2020-09-26 16:19:37 +02:00
|
|
|
return VOID_APO_RES
|
|
|
|
|
|
|
|
# Elements UE
|
2023-04-19 11:51:58 +02:00
|
|
|
decisions_ue = res.get_etud_decisions_ue(etudid)
|
|
|
|
for ue in res.get_ues_stat_dict():
|
2022-04-22 14:35:44 +02:00
|
|
|
if ue["code_apogee"] and code in {
|
|
|
|
x.strip() for x in ue["code_apogee"].split(",")
|
|
|
|
}:
|
2020-09-26 16:19:37 +02:00
|
|
|
if self.export_res_ues:
|
|
|
|
if decisions_ue and ue["ue_id"] in decisions_ue:
|
2023-04-19 11:51:58 +02:00
|
|
|
ue_status = res.get_etud_ue_status(etudid, ue["ue_id"])
|
2020-09-26 16:19:37 +02:00
|
|
|
code_decision_ue = decisions_ue[ue["ue_id"]]["code"]
|
|
|
|
return dict(
|
2022-04-05 11:44:08 +02:00
|
|
|
N=self.fmt_note(ue_status["moy"] if ue_status else ""),
|
2020-09-26 16:19:37 +02:00
|
|
|
B=20,
|
|
|
|
J="",
|
2022-01-21 00:46:45 +01:00
|
|
|
R=ScoDocSiteConfig.get_code_apo(code_decision_ue),
|
2020-09-26 16:19:37 +02:00
|
|
|
M="",
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
return VOID_APO_RES
|
|
|
|
else:
|
|
|
|
return VOID_APO_RES
|
|
|
|
|
|
|
|
# Elements Modules
|
2023-04-19 11:51:58 +02:00
|
|
|
modimpls = res.get_modimpls_dict()
|
2020-09-26 16:19:37 +02:00
|
|
|
module_code_found = False
|
|
|
|
for modimpl in modimpls:
|
2022-04-22 14:35:44 +02:00
|
|
|
module = modimpl["module"]
|
|
|
|
if module["code_apogee"] and code in {
|
|
|
|
x.strip() for x in module["code_apogee"].split(",")
|
|
|
|
}:
|
2023-04-19 11:51:58 +02:00
|
|
|
n = res.get_etud_mod_moy(modimpl["moduleimpl_id"], etudid)
|
2020-09-26 16:19:37 +02:00
|
|
|
if n != "NI" and self.export_res_modules:
|
2022-04-05 11:44:08 +02:00
|
|
|
return dict(N=self.fmt_note(n), B=20, J="", R="")
|
2020-09-26 16:19:37 +02:00
|
|
|
else:
|
|
|
|
module_code_found = True
|
|
|
|
if module_code_found:
|
|
|
|
return VOID_APO_RES
|
|
|
|
#
|
|
|
|
return None # element Apogee non trouvé dans ce semestre
|
|
|
|
|
2023-04-17 12:10:17 +02:00
|
|
|
def comp_elt_semestre(self, nt: NotesTableCompat, decision: dict, etudid: int):
|
|
|
|
"""Calcul résultat apo semestre.
|
|
|
|
Toujours vide pour en BUT/APC.
|
|
|
|
"""
|
2023-04-19 11:51:58 +02:00
|
|
|
if self.is_apc: # garde fou: pas de code semestre en APC !
|
2022-07-13 11:30:01 +02:00
|
|
|
return dict(N="", B=20, J="", R="", M="")
|
2022-02-26 20:22:18 +01:00
|
|
|
if decision is None:
|
2023-03-20 11:17:38 +01:00
|
|
|
etud = Identite.get_etud(etudid)
|
2022-02-26 20:22:18 +01:00
|
|
|
nomprenom = etud.nomprenom if etud else "(inconnu)"
|
|
|
|
raise ScoValueError(
|
|
|
|
f"decision absente pour l'étudiant {nomprenom} ({etudid})"
|
|
|
|
)
|
2020-09-26 16:19:37 +02:00
|
|
|
# resultat du semestre
|
2022-01-21 00:46:45 +01:00
|
|
|
decision_apo = ScoDocSiteConfig.get_code_apo(decision["code"])
|
2020-09-26 16:19:37 +02:00
|
|
|
note = nt.get_etud_moy_gen(etudid)
|
2022-01-21 00:46:45 +01:00
|
|
|
if decision_apo == "DEF" or decision["code"] == DEM or decision["code"] == DEF:
|
2020-09-26 16:19:37 +02:00
|
|
|
note_str = "0,01" # note non nulle pour les démissionnaires
|
|
|
|
else:
|
2022-04-05 11:44:08 +02:00
|
|
|
note_str = self.fmt_note(note)
|
2020-09-26 16:19:37 +02:00
|
|
|
return dict(N=note_str, B=20, J="", R=decision_apo, M="")
|
|
|
|
|
2023-04-19 11:51:58 +02:00
|
|
|
def comp_elt_annuel(self, etudid):
|
2020-09-26 16:19:37 +02:00
|
|
|
"""Calcul resultat annuel (VET) à partir du semestre courant
|
|
|
|
et de l'autre (le suivant ou le précédent complétant l'année scolaire)
|
2023-04-16 05:32:21 +02:00
|
|
|
En BUT, c'est la décision de jury annuelle (ApcValidationAnnee).
|
2020-09-26 16:19:37 +02:00
|
|
|
"""
|
|
|
|
# Code annuel:
|
2023-04-16 05:32:21 +02:00
|
|
|
# - Note: moyenne des moyennes générales des deux semestres
|
|
|
|
# (pas vraiment de sens, mais faute de mieux)
|
|
|
|
# on pourrait aussi bien prendre seulement la note du dernier semestre (S2 ou S4).
|
|
|
|
# XXX APOBUT: à modifier pour prendre moyenne indicative annuelle
|
|
|
|
#
|
2020-09-26 16:19:37 +02:00
|
|
|
# - Résultat jury:
|
|
|
|
# si l'autre est validé, code du semestre courant (ex: S1 (ADM), S2 (AJ) => année AJ)
|
|
|
|
# si l'autre n'est pas validé ou est DEF ou DEM, code de l'autre
|
|
|
|
#
|
|
|
|
# XXX cette règle est discutable, à valider
|
|
|
|
|
2023-04-16 05:32:21 +02:00
|
|
|
# log('comp_elt_annuel cur_sem=%s autre_sem=%s' % (cur_sem['formsemestre_id'], autre_sem['formsemestre_id']))
|
2023-04-19 11:51:58 +02:00
|
|
|
if not self.cur_sem:
|
2020-09-26 16:19:37 +02:00
|
|
|
# l'étudiant n'a pas de semestre courant ?!
|
2023-04-16 05:32:21 +02:00
|
|
|
self.log.append("pas de semestre courant")
|
2022-11-13 14:55:18 +01:00
|
|
|
log(f"comp_elt_annuel: etudid {etudid} has no cur_sem")
|
2020-09-26 16:19:37 +02:00
|
|
|
return VOID_APO_RES
|
|
|
|
|
2023-04-17 12:10:17 +02:00
|
|
|
if self.is_apc:
|
|
|
|
cur_decision = {} # comp_elt_semestre sera vide.
|
|
|
|
else:
|
2023-04-19 11:51:58 +02:00
|
|
|
cur_decision = self.cur_res.get_etud_decision_sem(etudid)
|
2023-04-16 05:32:21 +02:00
|
|
|
if not cur_decision:
|
|
|
|
# pas de decision => pas de résultat annuel
|
|
|
|
return VOID_APO_RES
|
|
|
|
|
|
|
|
if (cur_decision["code"] == RAT) and not self.export_res_rat:
|
|
|
|
# ne touche pas aux RATs
|
|
|
|
return VOID_APO_RES
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2023-04-19 11:51:58 +02:00
|
|
|
if not self.autre_sem:
|
2020-09-26 16:19:37 +02:00
|
|
|
# formations monosemestre, ou code VET semestriel,
|
|
|
|
# ou jury intermediaire et etudiant non redoublant...
|
2023-04-19 11:51:58 +02:00
|
|
|
return self.comp_elt_semestre(self.cur_res, cur_decision, etudid)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2023-04-16 05:32:21 +02:00
|
|
|
# --- Traite le BUT à part:
|
|
|
|
if self.is_apc:
|
2023-04-19 11:51:58 +02:00
|
|
|
return self.comp_elt_annuel_apc()
|
2023-04-16 05:32:21 +02:00
|
|
|
# --- Formations classiques
|
|
|
|
decision_apo = ScoDocSiteConfig.get_code_apo(cur_decision["code"])
|
2023-04-19 11:51:58 +02:00
|
|
|
autre_decision = self.autre_res.get_etud_decision_sem(etudid)
|
2020-09-26 16:19:37 +02:00
|
|
|
if not autre_decision:
|
|
|
|
# pas de decision dans l'autre => pas de résultat annuel
|
|
|
|
return VOID_APO_RES
|
2022-01-21 00:46:45 +01:00
|
|
|
autre_decision_apo = ScoDocSiteConfig.get_code_apo(autre_decision["code"])
|
2020-09-26 16:19:37 +02:00
|
|
|
if (
|
|
|
|
autre_decision_apo == "DEF"
|
2022-01-21 00:46:45 +01:00
|
|
|
or autre_decision["code"] == DEM
|
2020-09-26 16:19:37 +02:00
|
|
|
or autre_decision["code"] == DEF
|
|
|
|
) or (
|
|
|
|
decision_apo == "DEF"
|
2022-01-21 00:46:45 +01:00
|
|
|
or cur_decision["code"] == DEM
|
2020-09-26 16:19:37 +02:00
|
|
|
or cur_decision["code"] == DEF
|
|
|
|
):
|
|
|
|
note_str = "0,01" # note non nulle pour les démissionnaires
|
|
|
|
else:
|
2023-04-19 11:51:58 +02:00
|
|
|
note = self.cur_res.get_etud_moy_gen(etudid)
|
|
|
|
autre_note = self.autre_res.get_etud_moy_gen(etudid)
|
2020-09-26 16:19:37 +02:00
|
|
|
# print 'note=%s autre_note=%s' % (note, autre_note)
|
|
|
|
try:
|
|
|
|
moy_annuelle = (note + autre_note) / 2
|
2021-07-09 19:50:40 +02:00
|
|
|
except TypeError:
|
2020-09-26 16:19:37 +02:00
|
|
|
moy_annuelle = ""
|
2022-04-05 11:44:08 +02:00
|
|
|
note_str = self.fmt_note(moy_annuelle)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
if code_semestre_validant(autre_decision["code"]):
|
|
|
|
decision_apo_annuelle = decision_apo
|
|
|
|
else:
|
|
|
|
decision_apo_annuelle = autre_decision_apo
|
|
|
|
|
|
|
|
return dict(N=note_str, B=20, J="", R=decision_apo_annuelle, M="")
|
|
|
|
|
2023-04-19 11:51:58 +02:00
|
|
|
def comp_elt_annuel_apc(self):
|
2023-04-16 05:32:21 +02:00
|
|
|
"""L'élément Apo pour un résultat annuel BUT.
|
2023-04-19 11:51:58 +02:00
|
|
|
self.cur_res == résultats du semestre sur lequel a été appelé l'export.
|
2023-04-16 05:32:21 +02:00
|
|
|
"""
|
2023-04-19 11:51:58 +02:00
|
|
|
if not self.validation_annee_but:
|
|
|
|
# pas de décision ou pas de sem. impair
|
|
|
|
return VOID_APO_RES
|
|
|
|
|
|
|
|
return dict(
|
|
|
|
N="",
|
|
|
|
B=20,
|
|
|
|
J="",
|
|
|
|
R=ScoDocSiteConfig.get_code_apo(self.validation_annee_but.code),
|
|
|
|
M="",
|
|
|
|
)
|
|
|
|
|
|
|
|
def _but_load_validation_annuelle(self):
|
|
|
|
"charge la validation de jury BUT annuelle"
|
2023-04-16 05:32:21 +02:00
|
|
|
# le semestre impair de l'année scolaire
|
2023-04-19 11:51:58 +02:00
|
|
|
if self.cur_res.formsemestre.semestre_id % 2:
|
|
|
|
formsemestre = self.cur_res.formsemestre
|
2023-04-16 05:32:21 +02:00
|
|
|
elif (
|
2023-04-19 11:51:58 +02:00
|
|
|
self.autre_res
|
|
|
|
and self.autre_res.formsemestre.annee_scolaire()
|
|
|
|
== self.cur_res.formsemestre.annee_scolaire()
|
2023-04-16 05:32:21 +02:00
|
|
|
):
|
2023-04-19 11:51:58 +02:00
|
|
|
formsemestre = self.autre_res.formsemestre
|
2023-04-16 05:32:21 +02:00
|
|
|
assert formsemestre.semestre_id % 2
|
|
|
|
else:
|
|
|
|
# ne trouve pas de semestre impair
|
2023-04-19 11:51:58 +02:00
|
|
|
self.validation_annee_but = None
|
|
|
|
return
|
|
|
|
self.validation_annee_but: ApcValidationAnnee = (
|
|
|
|
ApcValidationAnnee.query.filter_by(
|
|
|
|
formsemestre_id=formsemestre.id, etudid=self.etud["etudid"]
|
|
|
|
).first()
|
2023-04-16 05:32:21 +02:00
|
|
|
)
|
|
|
|
|
2023-04-19 11:51:58 +02:00
|
|
|
def etud_set_semestres_de_etape(self, apo_data):
|
|
|
|
"""Set .cur_sem and .autre_sem et charge les résultats.
|
2020-09-26 16:19:37 +02:00
|
|
|
Lorsqu'on a une formation semestrialisée mais avec un code étape annuel,
|
|
|
|
il faut considérer les deux semestres ((S1,S2) ou (S3,S4)) pour calculer
|
|
|
|
le code annuel (VET ou VRT1A (voir elt_annee_apo)).
|
|
|
|
|
2022-07-13 11:30:01 +02:00
|
|
|
Pour les jurys intermediaires (janvier, S1 ou S3): (S2 ou S4) de la même
|
|
|
|
étape lors d'une année précédente ?
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2023-04-19 11:51:58 +02:00
|
|
|
Set cur_sem: le semestre "courant" et autre_sem, ou None s'il n'y en a pas.
|
2020-09-26 16:19:37 +02:00
|
|
|
"""
|
|
|
|
# Cherche le semestre "courant":
|
|
|
|
cur_sems = [
|
|
|
|
sem
|
|
|
|
for sem in self.etud["sems"]
|
|
|
|
if (
|
|
|
|
(sem["semestre_id"] == apo_data.cur_semestre_id)
|
|
|
|
and (apo_data.etape in sem["etapes"])
|
|
|
|
and (
|
2022-11-09 19:25:27 +01:00
|
|
|
sco_formsemestre.sem_in_semestre_scolaire(
|
|
|
|
sem,
|
|
|
|
apo_data.annee_scolaire,
|
2022-11-13 14:55:18 +01:00
|
|
|
0, # annee complete
|
2022-11-09 19:25:27 +01:00
|
|
|
)
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
|
|
|
)
|
|
|
|
]
|
|
|
|
if not cur_sems:
|
|
|
|
cur_sem = None
|
|
|
|
else:
|
|
|
|
# prend le plus recent avec decision
|
|
|
|
cur_sem = None
|
|
|
|
for sem in cur_sems:
|
2022-02-13 23:53:11 +01:00
|
|
|
formsemestre = FormSemestre.query.get_or_404(sem["formsemestre_id"])
|
2023-04-19 11:51:58 +02:00
|
|
|
res: NotesTableCompat = res_sem.load_formsemestre_results(formsemestre)
|
|
|
|
has_decision = res.etud_has_decision(self.etud["etudid"])
|
2023-04-16 05:32:21 +02:00
|
|
|
if has_decision:
|
2020-09-26 16:19:37 +02:00
|
|
|
cur_sem = sem
|
2023-04-19 11:51:58 +02:00
|
|
|
self.cur_res = res
|
2020-09-26 16:19:37 +02:00
|
|
|
break
|
|
|
|
if cur_sem is None:
|
2023-04-16 05:32:21 +02:00
|
|
|
cur_sem = cur_sems[0] # aucun avec décision, prend le plus recent
|
2023-04-19 11:51:58 +02:00
|
|
|
if res.formsemestre.id == cur_sem["formsemestre_id"]:
|
|
|
|
self.cur_res = res
|
|
|
|
else:
|
|
|
|
formsemestre = FormSemestre.query.get_or_404(
|
|
|
|
cur_sem["formsemestre_id"]
|
|
|
|
)
|
|
|
|
self.cur_res = res_sem.load_formsemestre_results(formsemestre)
|
|
|
|
|
|
|
|
self.cur_sem = cur_sem
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
if apo_data.cur_semestre_id <= 0:
|
2023-04-19 11:51:58 +02:00
|
|
|
# "autre_sem" non pertinent pour sessions sans semestres:
|
|
|
|
self.autre_sem = None
|
|
|
|
self.autre_res = None
|
|
|
|
return
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
if apo_data.jury_intermediaire: # jury de janvier
|
|
|
|
# Le semestre suivant: exemple 2 si on est en jury de S1
|
|
|
|
autre_semestre_id = apo_data.cur_semestre_id + 1
|
|
|
|
else:
|
|
|
|
# Le précédent (S1 si on est en S2)
|
|
|
|
autre_semestre_id = apo_data.cur_semestre_id - 1
|
|
|
|
|
|
|
|
# L'autre semestre DOIT être antérieur au courant indiqué par apo_data
|
|
|
|
if apo_data.periode is not None:
|
|
|
|
if apo_data.periode == 1:
|
|
|
|
courant_annee_debut = apo_data.annee_scolaire
|
|
|
|
courant_mois_debut = 9 # periode = 1 (sept-jan)
|
|
|
|
elif apo_data.periode == 2:
|
|
|
|
courant_annee_debut = apo_data.annee_scolaire + 1
|
|
|
|
courant_mois_debut = 1 # ou 2 (fev-jul)
|
|
|
|
else:
|
2023-04-19 11:51:58 +02:00
|
|
|
raise ValueError("invalid periode value !") # bug ?
|
2020-09-26 16:19:37 +02:00
|
|
|
courant_date_debut = "%d-%02d-01" % (
|
|
|
|
courant_annee_debut,
|
|
|
|
courant_mois_debut,
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
courant_date_debut = "9999-99-99"
|
|
|
|
|
|
|
|
# etud['sems'] est la liste des semestres de l'étudiant, triés par date,
|
|
|
|
# le plus récemment effectué en tête.
|
|
|
|
# Cherche les semestres (antérieurs) de l'indice autre de la même étape apogée
|
|
|
|
# s'il y en a plusieurs, choisit le plus récent ayant une décision
|
|
|
|
|
|
|
|
autres_sems = []
|
|
|
|
for sem in self.etud["sems"]:
|
|
|
|
if (
|
|
|
|
sem["semestre_id"] == autre_semestre_id
|
|
|
|
and apo_data.etape_apogee in sem["etapes"]
|
|
|
|
):
|
|
|
|
if (
|
|
|
|
sem["date_debut_iso"] < courant_date_debut
|
|
|
|
): # on demande juste qu'il ait démarré avant
|
|
|
|
autres_sems.append(sem)
|
|
|
|
if not autres_sems:
|
|
|
|
autre_sem = None
|
|
|
|
elif len(autres_sems) == 1:
|
|
|
|
autre_sem = autres_sems[0]
|
|
|
|
else:
|
|
|
|
autre_sem = None
|
|
|
|
for sem in autres_sems:
|
2022-02-13 23:53:11 +01:00
|
|
|
formsemestre = FormSemestre.query.get_or_404(sem["formsemestre_id"])
|
2023-04-19 11:51:58 +02:00
|
|
|
res: NotesTableCompat = res_sem.load_formsemestre_results(formsemestre)
|
|
|
|
if res.is_apc:
|
|
|
|
has_decision = res.etud_has_decision(self.etud["etudid"])
|
|
|
|
else:
|
|
|
|
has_decision = res.get_etud_decision_sem(self.etud["etudid"])
|
|
|
|
if has_decision:
|
2020-09-26 16:19:37 +02:00
|
|
|
autre_sem = sem
|
|
|
|
break
|
|
|
|
if autre_sem is None:
|
|
|
|
autre_sem = autres_sems[0] # aucun avec decision, prend le plus recent
|
|
|
|
|
2023-04-19 11:51:58 +02:00
|
|
|
self.autre_sem = autre_sem
|
|
|
|
# Charge les résultats:
|
|
|
|
if autre_sem:
|
|
|
|
formsemestre = FormSemestre.query.get_or_404(autre_sem["formsemestre_id"])
|
|
|
|
self.autre_res = res_sem.load_formsemestre_results(formsemestre)
|
|
|
|
else:
|
|
|
|
self.autre_res = None
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
2023-04-16 05:32:21 +02:00
|
|
|
class ApoData:
|
2020-09-26 16:19:37 +02:00
|
|
|
def __init__(
|
|
|
|
self,
|
2022-01-07 17:58:34 +01:00
|
|
|
data: str,
|
2020-09-26 16:19:37 +02:00
|
|
|
periode=None,
|
|
|
|
export_res_etape=True,
|
|
|
|
export_res_sem=True,
|
|
|
|
export_res_ues=True,
|
|
|
|
export_res_modules=True,
|
|
|
|
export_res_sdj=True,
|
|
|
|
export_res_rat=True,
|
|
|
|
orig_filename=None,
|
|
|
|
):
|
|
|
|
"""Lecture du fichier CSV Apogée
|
|
|
|
Regroupe les élements importants d'un fichier CSV Apogée
|
|
|
|
periode = 1 (sept-jan) ou 2 (fev-jul), mais cette info n'est pas
|
|
|
|
(toujours) présente dans les CSV Apogée et doit être indiquée par l'utilisateur
|
|
|
|
Laisser periode à None si etape en 1 semestre (LP, décalés, ...)
|
|
|
|
"""
|
|
|
|
self.export_res_etape = export_res_etape # VET, ...
|
|
|
|
self.export_res_sem = export_res_sem # elt_sem_apo
|
|
|
|
self.export_res_ues = export_res_ues
|
|
|
|
self.export_res_modules = export_res_modules
|
|
|
|
self.export_res_sdj = export_res_sdj
|
|
|
|
self.export_res_rat = export_res_rat
|
|
|
|
self.orig_filename = orig_filename
|
|
|
|
self.periode = periode #
|
2023-04-16 05:32:21 +02:00
|
|
|
"1 sem. sept-jan, 2 sem. fev-jul. 0 si étape en 1 seul semestre."
|
2022-07-13 11:30:01 +02:00
|
|
|
self.is_apc = None
|
|
|
|
"Vrai si BUT"
|
2023-04-16 05:32:21 +02:00
|
|
|
self.header: str = ""
|
|
|
|
"début du fichier Apogée (sera ré-écrit non modifié)"
|
|
|
|
self.titles: dict[str, str] = {}
|
|
|
|
"titres Apogée (section XX-APO_TITRES-XX)"
|
2020-09-26 16:19:37 +02:00
|
|
|
try:
|
|
|
|
self.read_csv(data)
|
2021-12-03 14:13:49 +01:00
|
|
|
except ScoFormatError as e:
|
2020-09-26 16:19:37 +02:00
|
|
|
# essaie de retrouver le nom du fichier pour enrichir le message d'erreur
|
|
|
|
filename = ""
|
|
|
|
if self.orig_filename is None:
|
|
|
|
if hasattr(self, "titles"):
|
|
|
|
filename = self.titles.get("apoC_Fichier_Exp", filename)
|
|
|
|
else:
|
|
|
|
filename = self.orig_filename
|
2021-12-03 14:13:49 +01:00
|
|
|
raise ScoFormatError(
|
2020-09-26 16:19:37 +02:00
|
|
|
"<h3>Erreur lecture du fichier Apogée <tt>%s</tt></h3><p>" % filename
|
|
|
|
+ e.args[0]
|
|
|
|
+ "</p>"
|
2022-01-07 17:58:34 +01:00
|
|
|
) from e
|
2020-09-26 16:19:37 +02:00
|
|
|
self.etape_apogee = self.get_etape_apogee() # 'V1RT'
|
|
|
|
self.vdi_apogee = self.get_vdi_apogee() # '111'
|
|
|
|
self.etape = ApoEtapeVDI(etape=self.etape_apogee, vdi=self.vdi_apogee)
|
|
|
|
self.cod_dip_apogee = self.get_cod_dip_apogee()
|
|
|
|
self.annee_scolaire = self.get_annee_scolaire()
|
|
|
|
self.jury_intermediaire = (
|
|
|
|
False # True si jury à mi-étape, eg jury de S1 dans l'étape (S1, S2)
|
|
|
|
)
|
|
|
|
|
2023-04-16 05:32:21 +02:00
|
|
|
log(f"ApoData( periode={self.periode}, annee_scolaire={self.annee_scolaire} )")
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2021-08-21 00:24:51 +02:00
|
|
|
def setup(self):
|
2021-01-01 18:40:47 +01:00
|
|
|
"""Recherche semestres ScoDoc concernés"""
|
2021-08-21 00:24:51 +02:00
|
|
|
self.sems_etape = comp_apo_sems(self.etape_apogee, self.annee_scolaire)
|
2022-07-13 11:30:01 +02:00
|
|
|
self.formsemestres_etape = [
|
|
|
|
FormSemestre.query.get_or_404(s["formsemestre_id"]) for s in self.sems_etape
|
|
|
|
]
|
|
|
|
apcs = {
|
|
|
|
formsemestre.formation.is_apc() for formsemestre in self.formsemestres_etape
|
|
|
|
}
|
|
|
|
if len(apcs) != 1:
|
|
|
|
raise ScoValueError(
|
|
|
|
"l'ensemble mixe des semestres BUT (APC) et des semestres classiques !"
|
|
|
|
)
|
|
|
|
self.is_apc = apcs.pop()
|
2020-09-26 16:19:37 +02:00
|
|
|
self.etape_formsemestre_ids = {s["formsemestre_id"] for s in self.sems_etape}
|
2022-07-13 11:30:01 +02:00
|
|
|
if self.periode is not None:
|
2020-09-26 16:19:37 +02:00
|
|
|
self.sems_periode = [
|
|
|
|
s
|
|
|
|
for s in self.sems_etape
|
|
|
|
if (s["periode"] == self.periode) or s["semestre_id"] < 0
|
|
|
|
]
|
|
|
|
if not self.sems_periode:
|
|
|
|
log("** Warning: ApoData.setup: sems_periode is empty")
|
|
|
|
log(
|
|
|
|
"** (periode=%s, sems_etape [periode]=%s)"
|
|
|
|
% (self.periode, [s["periode"] for s in self.sems_etape])
|
|
|
|
)
|
|
|
|
self.sems_periode = None
|
|
|
|
self.cur_semestre_id = -1 # ?
|
|
|
|
else:
|
|
|
|
self.cur_semestre_id = self.sems_periode[0]["semestre_id"]
|
|
|
|
# Les semestres de la période ont le même indice, n'est-ce pas ?
|
|
|
|
if not all(
|
|
|
|
self.cur_semestre_id == s["semestre_id"] for s in self.sems_periode
|
|
|
|
):
|
|
|
|
# debugging information
|
|
|
|
log(
|
2022-09-15 14:13:25 +02:00
|
|
|
f"""*** ApoData.set() error !
|
|
|
|
ApoData( periode={self.periode}, annee_scolaire={self.annee_scolaire
|
|
|
|
}, cur_semestre_id={self.cur_semestre_id} )
|
|
|
|
{len(self.sems_periode)} semestres dans la periode:
|
|
|
|
"""
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
|
|
|
for s in self.sems_periode:
|
|
|
|
log(pprint.pformat(s))
|
|
|
|
|
2022-09-15 14:13:25 +02:00
|
|
|
raise ScoValueError(
|
|
|
|
f"""Incohérence détectée !
|
|
|
|
|
|
|
|
Les semestres de la période n'ont pas tous le même indice.
|
|
|
|
|
|
|
|
Période: {self.periode}. Indice courant: {self.cur_semestre_id}
|
|
|
|
|
|
|
|
(au besoin, contacter l'assistance sur {scu.SCO_DISCORD_ASSISTANCE})
|
|
|
|
"""
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
|
|
|
# Cette condition sera inadaptée si semestres décalés
|
|
|
|
# (mais ils n'ont pas d'étape annuelle, espérons!)
|
|
|
|
if self.cur_semestre_id >= 0: # non pertinent pour sessions sans semestres
|
|
|
|
self.jury_intermediaire = (self.cur_semestre_id % 2) != 0
|
|
|
|
else:
|
|
|
|
self.sems_periode = None
|
|
|
|
|
2021-08-31 19:32:12 +02:00
|
|
|
def read_csv(self, data: str):
|
2020-09-26 16:19:37 +02:00
|
|
|
if not data:
|
2021-12-03 14:13:49 +01:00
|
|
|
raise ScoFormatError("Fichier Apogée vide !")
|
2021-08-31 19:32:12 +02:00
|
|
|
f = StringIOFileLineWrapper(data) # pour traiter comme un fichier
|
2020-09-26 16:19:37 +02:00
|
|
|
# check that we are at the begining of Apogee CSV
|
|
|
|
line = f.readline().strip()
|
|
|
|
if line != "XX-APO_TITRES-XX":
|
2021-12-03 14:13:49 +01:00
|
|
|
raise ScoFormatError("format incorrect: pas de XX-APO_TITRES-XX")
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
# 1-- En-tête: du début jusqu'à la balise XX-APO_VALEURS-XX
|
2022-01-07 17:58:34 +01:00
|
|
|
try:
|
|
|
|
idx = data.index("XX-APO_VALEURS-XX")
|
|
|
|
except ValueError as exc:
|
|
|
|
raise ScoFormatError("format incorrect: pas de XX-APO_VALEURS-XX") from exc
|
2021-08-31 19:32:12 +02:00
|
|
|
self.header = data[:idx]
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
# 2-- Titres:
|
|
|
|
# on va y chercher apoC_Fichier_Exp qui donnera le nom du fichier
|
|
|
|
# ainsi que l'année scolaire et le code diplôme.
|
|
|
|
self.titles = _apo_read_TITRES(f)
|
|
|
|
|
|
|
|
# 3-- La section XX-APO_TYP_RES-XX est ignorée:
|
|
|
|
line = f.readline().strip()
|
|
|
|
if line != "XX-APO_TYP_RES-XX":
|
2021-12-03 14:13:49 +01:00
|
|
|
raise ScoFormatError("format incorrect: pas de XX-APO_TYP_RES-XX")
|
2020-09-26 16:19:37 +02:00
|
|
|
_apo_skip_section(f)
|
|
|
|
|
|
|
|
# 4-- Définition de colonnes: (on y trouve aussi l'étape)
|
|
|
|
line = f.readline().strip()
|
|
|
|
if line != "XX-APO_COLONNES-XX":
|
2021-12-03 14:13:49 +01:00
|
|
|
raise ScoFormatError("format incorrect: pas de XX-APO_COLONNES-XX")
|
2020-09-26 16:19:37 +02:00
|
|
|
self.cols = _apo_read_cols(f)
|
|
|
|
self.apo_elts = self._group_elt_cols(self.cols)
|
|
|
|
|
|
|
|
# 5-- Section XX-APO_VALEURS-XX
|
|
|
|
# Lecture des étudiants et de leurs résultats
|
|
|
|
while True: # skip
|
|
|
|
line = f.readline()
|
|
|
|
if not line:
|
2021-12-03 14:13:49 +01:00
|
|
|
raise ScoFormatError("format incorrect: pas de XX-APO_VALEURS-XX")
|
2020-09-26 16:19:37 +02:00
|
|
|
if line.strip() == "XX-APO_VALEURS-XX":
|
|
|
|
break
|
|
|
|
self.column_titles = f.readline()
|
|
|
|
self.col_ids = self.column_titles.strip().split()
|
|
|
|
self.etuds = self.apo_read_etuds(f)
|
|
|
|
self.etud_by_nip = {e["nip"]: e for e in self.etuds}
|
|
|
|
|
|
|
|
def get_etud_by_nip(self, nip):
|
|
|
|
"returns ApoEtud with a given NIP code"
|
|
|
|
return self.etud_by_nip[nip]
|
|
|
|
|
|
|
|
def _group_elt_cols(self, cols):
|
|
|
|
"""Return ordered dict of ApoElt from list of ApoCols.
|
|
|
|
Clé: id apogée, eg 'V1RT', 'V1GE2201', ...
|
|
|
|
Valeur: ApoElt, avec les attributs code, type_objet
|
|
|
|
|
2021-01-01 18:40:47 +01:00
|
|
|
Si les id Apogée ne sont pas uniques (ce n'est pas garanti), garde le premier
|
2020-09-26 16:19:37 +02:00
|
|
|
"""
|
|
|
|
elts = collections.OrderedDict()
|
2021-07-09 17:47:06 +02:00
|
|
|
for col_id in sorted(list(cols.keys()), reverse=True):
|
2020-09-26 16:19:37 +02:00
|
|
|
col = cols[col_id]
|
|
|
|
if col["Code"] in elts:
|
|
|
|
elts[col["Code"]].append(col)
|
|
|
|
else:
|
|
|
|
elts[col["Code"]] = ApoElt([col])
|
|
|
|
return elts # { code apo : ApoElt }
|
|
|
|
|
2022-07-02 11:17:04 +02:00
|
|
|
def apo_read_etuds(self, f) -> list[ApoEtud]:
|
2023-04-19 11:51:58 +02:00
|
|
|
"""Lecture des étudiants (et résultats) du fichier CSV Apogée.
|
|
|
|
Les lignes "étudiant" commencent toujours par
|
|
|
|
`12345678 NOM PRENOM 15/05/2003`
|
|
|
|
le premier code étant le NIP.
|
|
|
|
"""
|
|
|
|
apo_etuds = []
|
2020-09-26 16:19:37 +02:00
|
|
|
while True:
|
|
|
|
line = f.readline()
|
|
|
|
if not line:
|
|
|
|
break
|
|
|
|
if not line.strip():
|
|
|
|
continue # silently ignore blank lines
|
|
|
|
line = line.strip(APO_NEWLINE)
|
2023-04-16 05:32:21 +02:00
|
|
|
fields = line.split(APO_SEP)
|
2023-04-19 11:51:58 +02:00
|
|
|
if len(fields) < 4:
|
|
|
|
raise ScoValueError(
|
|
|
|
"""Ligne étudiant invalide
|
|
|
|
(doit commencer par 'NIP NOM PRENOM dd/mm/yyyy')"""
|
|
|
|
)
|
2020-09-26 16:19:37 +02:00
|
|
|
cols = {} # { col_id : value }
|
2023-04-16 05:32:21 +02:00
|
|
|
for i, field in enumerate(fields):
|
|
|
|
cols[self.col_ids[i]] = field
|
2023-04-19 11:51:58 +02:00
|
|
|
apo_etuds.append(
|
2020-09-26 16:19:37 +02:00
|
|
|
ApoEtud(
|
2023-04-16 05:32:21 +02:00
|
|
|
nip=fields[0], # id etudiant
|
|
|
|
nom=fields[1],
|
|
|
|
prenom=fields[2],
|
|
|
|
naissance=fields[3],
|
2020-09-26 16:19:37 +02:00
|
|
|
cols=cols,
|
|
|
|
export_res_etape=self.export_res_etape,
|
|
|
|
export_res_sem=self.export_res_sem,
|
|
|
|
export_res_ues=self.export_res_ues,
|
|
|
|
export_res_modules=self.export_res_modules,
|
|
|
|
export_res_sdj=self.export_res_sdj,
|
|
|
|
export_res_rat=self.export_res_rat,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2023-04-19 11:51:58 +02:00
|
|
|
return apo_etuds
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
def get_etape_apogee(self):
|
2021-01-01 18:40:47 +01:00
|
|
|
"""Le code etape: 'V1RT', donné par le code de l'élément VET"""
|
2020-09-26 16:19:37 +02:00
|
|
|
for elt in self.apo_elts.values():
|
|
|
|
if elt.type_objet == "VET":
|
|
|
|
return elt.code
|
|
|
|
raise ScoValueError("Pas de code etape Apogee (manque élément VET)")
|
|
|
|
|
|
|
|
def get_vdi_apogee(self):
|
|
|
|
"""le VDI (version de diplôme), stocké dans l'élément VET
|
2023-04-16 05:32:21 +02:00
|
|
|
(note: on pourrait peut-être aussi bien le récupérer dans
|
|
|
|
l'en-tête XX-APO_TITRES-XX apoC_cod_vdi)
|
2020-09-26 16:19:37 +02:00
|
|
|
"""
|
|
|
|
for elt in self.apo_elts.values():
|
|
|
|
if elt.type_objet == "VET":
|
|
|
|
return elt.version
|
|
|
|
raise ScoValueError("Pas de VDI Apogee (manque élément VET)")
|
|
|
|
|
|
|
|
def get_cod_dip_apogee(self):
|
|
|
|
"""Le code diplôme, indiqué dans l'en-tête de la maquette
|
|
|
|
exemple: VDTRT
|
|
|
|
Retourne '' si absent.
|
|
|
|
"""
|
|
|
|
return self.titles.get("apoC_cod_dip", "")
|
|
|
|
|
|
|
|
def get_annee_scolaire(self):
|
|
|
|
"""Annee scolaire du fichier Apogee: un integer
|
|
|
|
= annee du mois de septembre de début
|
|
|
|
"""
|
|
|
|
m = re.match("[12][0-9]{3}", self.titles["apoC_annee"])
|
|
|
|
if not m:
|
2021-12-03 14:13:49 +01:00
|
|
|
raise ScoFormatError(
|
2023-04-16 05:32:21 +02:00
|
|
|
f"""Annee scolaire (apoC_annee) invalide: "{self.titles["apoC_annee"]}" """
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
|
|
|
return int(m.group(0))
|
|
|
|
|
|
|
|
def write_header(self, f):
|
|
|
|
"""write apo CSV header on f
|
|
|
|
(beginning of CSV until columns titles just after XX-APO_VALEURS-XX line)
|
|
|
|
"""
|
|
|
|
f.write(self.header)
|
|
|
|
f.write(APO_NEWLINE)
|
|
|
|
f.write("XX-APO_VALEURS-XX" + APO_NEWLINE)
|
|
|
|
f.write(self.column_titles)
|
|
|
|
|
|
|
|
def write_etuds(self, f):
|
2021-01-01 18:40:47 +01:00
|
|
|
"""write apo CSV etuds on f"""
|
2020-09-26 16:19:37 +02:00
|
|
|
for e in self.etuds:
|
2023-04-16 05:32:21 +02:00
|
|
|
fields = [] # e['nip'], e['nom'], e['prenom'], e['naissance'] ]
|
2020-09-26 16:19:37 +02:00
|
|
|
for col_id in self.col_ids:
|
|
|
|
try:
|
2023-04-16 05:32:21 +02:00
|
|
|
fields.append(str(e.new_cols[col_id]))
|
2020-09-26 16:19:37 +02:00
|
|
|
except KeyError:
|
|
|
|
log(
|
|
|
|
"Error: %s %s missing column key %s"
|
|
|
|
% (e["nip"], e["nom"], col_id)
|
|
|
|
)
|
|
|
|
log("Details:\ne = %s" % pprint.pformat(e))
|
|
|
|
log("col_ids=%s" % pprint.pformat(self.col_ids))
|
|
|
|
log("etudiant ignore.\n")
|
|
|
|
|
2023-04-16 05:32:21 +02:00
|
|
|
f.write(APO_SEP.join(fields) + APO_NEWLINE)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2023-04-16 05:32:21 +02:00
|
|
|
def list_unknown_elements(self) -> list[str]:
|
2020-09-26 16:19:37 +02:00
|
|
|
"""Liste des codes des elements Apogee non trouvés dans ScoDoc
|
|
|
|
(après traitement de tous les étudiants)
|
|
|
|
"""
|
2023-04-16 05:32:21 +02:00
|
|
|
codes = set()
|
2020-09-26 16:19:37 +02:00
|
|
|
for e in self.etuds:
|
2023-04-16 05:32:21 +02:00
|
|
|
codes.update({code for code in e.col_elts if e.col_elts[code] is None})
|
|
|
|
codes_list = list(codes)
|
|
|
|
codes_list.sort()
|
|
|
|
return codes_list
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
def list_elements(self):
|
|
|
|
"""Liste les codes des elements Apogée de la maquette
|
|
|
|
et ceux des semestres ScoDoc associés
|
|
|
|
Retourne deux ensembles
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
maq_elems = {self.cols[col_id]["Code"] for col_id in self.col_ids[4:]}
|
|
|
|
except KeyError:
|
|
|
|
# une colonne déclarée dans l'en-tête n'est pas présente
|
|
|
|
declared = self.col_ids[4:] # id des colones dans l'en-tête
|
|
|
|
present = sorted(self.cols.keys()) # colones presentes
|
|
|
|
log("Fichier Apogee invalide:")
|
2023-04-16 05:32:21 +02:00
|
|
|
log(f"Colonnes declarees: {declared}")
|
|
|
|
log(f"Colonnes presentes: {present}")
|
2021-12-03 14:13:49 +01:00
|
|
|
raise ScoFormatError(
|
2023-04-16 05:32:21 +02:00
|
|
|
f"""Fichier Apogee invalide<br>Colonnes declarees: <tt>{declared}</tt>
|
|
|
|
<br>Colonnes presentes: <tt>{present}</tt>"""
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
|
|
|
# l'ensemble de tous les codes des elements apo des semestres:
|
2021-07-09 17:47:06 +02:00
|
|
|
sem_elems = reduce(set.union, list(self.get_codes_by_sem().values()), set())
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
return maq_elems, sem_elems
|
|
|
|
|
2023-04-16 05:32:21 +02:00
|
|
|
def get_codes_by_sem(self) -> dict[int, set[str]]:
|
2022-04-22 14:35:44 +02:00
|
|
|
"""Pour chaque semestre associé, donne l'ensemble des codes de cette maquette Apogée
|
|
|
|
qui s'y trouvent (dans le semestre, les UE ou les modules).
|
|
|
|
Return: { formsemestre_id : { 'code1', 'code2', ... }}
|
2020-09-26 16:19:37 +02:00
|
|
|
"""
|
|
|
|
codes_by_sem = {}
|
|
|
|
for sem in self.sems_etape:
|
2022-07-02 11:17:04 +02:00
|
|
|
formsemestre: FormSemestre = FormSemestre.query.get_or_404(
|
|
|
|
sem["formsemestre_id"]
|
|
|
|
)
|
|
|
|
# L'ensemble des codes apo associés aux éléments:
|
|
|
|
codes_semestre = formsemestre.get_codes_apogee()
|
2022-07-02 00:00:29 +02:00
|
|
|
codes_modules = set().union(
|
|
|
|
*[
|
|
|
|
modimpl.module.get_codes_apogee()
|
|
|
|
for modimpl in formsemestre.modimpls
|
|
|
|
]
|
|
|
|
)
|
|
|
|
codes_ues = set().union(
|
|
|
|
*[
|
|
|
|
ue.get_codes_apogee()
|
|
|
|
for ue in formsemestre.query_ues(with_sport=True)
|
|
|
|
]
|
|
|
|
)
|
2020-09-26 16:19:37 +02:00
|
|
|
s = set()
|
|
|
|
codes_by_sem[sem["formsemestre_id"]] = s
|
|
|
|
for col_id in self.col_ids[4:]:
|
|
|
|
code = self.cols[col_id]["Code"] # 'V1RT'
|
2022-07-02 11:17:04 +02:00
|
|
|
# associé à l'étape, l'année ou le semestre:
|
|
|
|
if code in codes_semestre:
|
2020-09-26 16:19:37 +02:00
|
|
|
s.add(code)
|
|
|
|
continue
|
|
|
|
# associé à une UE:
|
2022-07-02 00:00:29 +02:00
|
|
|
if code in codes_ues:
|
|
|
|
s.add(code)
|
|
|
|
continue
|
2020-09-26 16:19:37 +02:00
|
|
|
# associé à un module:
|
2022-07-02 00:00:29 +02:00
|
|
|
if code in codes_modules:
|
|
|
|
s.add(code)
|
2020-09-26 16:19:37 +02:00
|
|
|
# log('codes_by_sem=%s' % pprint.pformat(codes_by_sem))
|
|
|
|
return codes_by_sem
|
|
|
|
|
|
|
|
def build_cr_table(self):
|
2021-01-01 18:40:47 +01:00
|
|
|
"""Table compte rendu des décisions"""
|
2020-09-26 16:19:37 +02:00
|
|
|
CR = [] # tableau compte rendu des decisions
|
|
|
|
for e in self.etuds:
|
|
|
|
cr = {
|
|
|
|
"NIP": e["nip"],
|
|
|
|
"nom": e["nom"],
|
|
|
|
"prenom": e["prenom"],
|
|
|
|
"est_NAR": e.is_NAR,
|
|
|
|
"commentaire": "; ".join(e.log),
|
|
|
|
}
|
2023-04-16 05:32:21 +02:00
|
|
|
if e.col_elts and e.col_elts[self.etape_apogee] is not None:
|
2020-09-26 16:19:37 +02:00
|
|
|
cr["etape"] = e.col_elts[self.etape_apogee].get("R", "")
|
|
|
|
cr["etape_note"] = e.col_elts[self.etape_apogee].get("N", "")
|
|
|
|
else:
|
|
|
|
cr["etape"] = ""
|
|
|
|
cr["etape_note"] = ""
|
|
|
|
CR.append(cr)
|
|
|
|
|
|
|
|
columns_ids = ["NIP", "nom", "prenom"]
|
|
|
|
columns_ids.extend(("etape", "etape_note", "est_NAR", "commentaire"))
|
|
|
|
|
|
|
|
T = GenTable(
|
|
|
|
columns_ids=columns_ids,
|
|
|
|
titles=dict(zip(columns_ids, columns_ids)),
|
|
|
|
rows=CR,
|
|
|
|
xls_sheet_name="Decisions ScoDoc",
|
|
|
|
)
|
|
|
|
return T
|
|
|
|
|
|
|
|
|
|
|
|
def _apo_read_cols(f):
|
2021-01-01 18:40:47 +01:00
|
|
|
"""Lecture colonnes apo :
|
2020-09-26 16:19:37 +02:00
|
|
|
Démarre après la balise XX-APO_COLONNES-XX
|
|
|
|
et s'arrête après la balise APO_COL_VAL_FIN
|
|
|
|
|
|
|
|
Colonne Apogee: les champs sont données par la ligne
|
2021-01-01 18:40:47 +01:00
|
|
|
apoL_a01_code de la section XX-APO_COLONNES-XX
|
2020-09-26 16:19:37 +02:00
|
|
|
col_id est apoL_c0001, apoL_c0002, ...
|
2021-01-01 18:40:47 +01:00
|
|
|
|
2020-09-26 16:19:37 +02:00
|
|
|
:return: { col_id : { title : value } }
|
|
|
|
Example: { 'apoL_c0001' : { 'Type Objet' : 'VET', 'Code' : 'V1IN', ... }, ... }
|
|
|
|
"""
|
|
|
|
line = f.readline().strip(" " + APO_NEWLINE)
|
2023-04-16 05:32:21 +02:00
|
|
|
fields = line.split(APO_SEP)
|
|
|
|
if fields[0] != "apoL_a01_code":
|
|
|
|
raise ScoFormatError(f"invalid line: {line} (expecting apoL_a01_code)")
|
|
|
|
col_keys = fields
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
while True: # skip premiere partie (apoL_a02_nom, ...)
|
|
|
|
line = f.readline().strip(" " + APO_NEWLINE)
|
|
|
|
if line == "APO_COL_VAL_DEB":
|
|
|
|
break
|
|
|
|
# après APO_COL_VAL_DEB
|
|
|
|
cols = {}
|
|
|
|
i = 0
|
|
|
|
while True:
|
|
|
|
line = f.readline().strip(" " + APO_NEWLINE)
|
|
|
|
if line == "APO_COL_VAL_FIN":
|
|
|
|
break
|
|
|
|
i += 1
|
2023-04-16 05:32:21 +02:00
|
|
|
fields = line.split(APO_SEP)
|
2020-09-26 16:19:37 +02:00
|
|
|
# sanity check
|
2023-04-16 05:32:21 +02:00
|
|
|
col_id = fields[0] # apoL_c0001, ...
|
2020-09-26 16:19:37 +02:00
|
|
|
if col_id in cols:
|
2023-03-16 12:46:27 +01:00
|
|
|
raise ScoFormatError(f"duplicate column definition: {col_id}")
|
2020-09-26 16:19:37 +02:00
|
|
|
m = re.match(r"^apoL_c([0-9]{4})$", col_id)
|
|
|
|
if not m:
|
2021-12-03 14:13:49 +01:00
|
|
|
raise ScoFormatError(
|
2023-03-16 12:46:27 +01:00
|
|
|
f"invalid column id: {line} (expecting apoL_c{col_id})"
|
2021-02-01 23:54:46 +01:00
|
|
|
)
|
2020-09-26 16:19:37 +02:00
|
|
|
if int(m.group(1)) != i:
|
2023-03-16 12:46:27 +01:00
|
|
|
raise ScoFormatError(f"invalid column id: {col_id} for index {i}")
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2023-04-16 05:32:21 +02:00
|
|
|
cols[col_id] = DictCol(list(zip(col_keys, fields)))
|
2020-09-26 16:19:37 +02:00
|
|
|
cols[col_id].lineno = f.lineno # for debuging purpose
|
|
|
|
|
|
|
|
return cols
|
|
|
|
|
|
|
|
|
2023-04-16 05:32:21 +02:00
|
|
|
def _apo_read_TITRES(f) -> dict:
|
2020-09-26 16:19:37 +02:00
|
|
|
"Lecture section TITRES du fichier Apogée, renvoie dict"
|
|
|
|
d = {}
|
|
|
|
while True:
|
|
|
|
line = f.readline().strip(
|
|
|
|
" " + APO_NEWLINE
|
|
|
|
) # ne retire pas le \t (pour les clés vides)
|
|
|
|
if not line.strip(): # stoppe sur ligne pleines de \t
|
|
|
|
break
|
|
|
|
|
|
|
|
fields = line.split(APO_SEP)
|
|
|
|
if len(fields) == 2:
|
|
|
|
k, v = fields
|
|
|
|
else:
|
2023-03-16 12:46:27 +01:00
|
|
|
log(f"Error read CSV: \nline={line}\nfields={fields}")
|
2020-09-26 16:19:37 +02:00
|
|
|
log(dir(f))
|
2021-12-03 14:13:49 +01:00
|
|
|
raise ScoFormatError(
|
2023-03-16 12:46:27 +01:00
|
|
|
f"Fichier Apogee incorrect (section titres, {len(fields)} champs au lieu de 2)"
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
|
|
|
d[k] = v
|
|
|
|
#
|
|
|
|
if not d.get("apoC_Fichier_Exp", None):
|
2021-12-03 14:13:49 +01:00
|
|
|
raise ScoFormatError("Fichier Apogee incorrect: pas de titre apoC_Fichier_Exp")
|
2020-09-26 16:19:37 +02:00
|
|
|
# keep only basename: may be a windows or unix pathname
|
|
|
|
s = d["apoC_Fichier_Exp"].split("/")[-1]
|
|
|
|
s = s.split("\\")[-1] # for DOS paths, eg C:\TEMP\VL4RT_V3ASR.TXT
|
|
|
|
d["apoC_Fichier_Exp"] = s
|
|
|
|
return d
|
|
|
|
|
|
|
|
|
|
|
|
def _apo_skip_section(f):
|
|
|
|
"Saute section Apo: s'arrete apres ligne vide"
|
|
|
|
while True:
|
|
|
|
line = f.readline().strip()
|
|
|
|
if not line:
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|
|
# -------------------------------------
|
|
|
|
|
|
|
|
|
2022-07-13 11:30:01 +02:00
|
|
|
def comp_apo_sems(etape_apogee, annee_scolaire: int) -> list[dict]:
|
2020-09-26 16:19:37 +02:00
|
|
|
"""
|
|
|
|
:param etape_apogee: etape (string or ApoEtapeVDI)
|
|
|
|
:param annee_scolaire: annee (int)
|
|
|
|
:return: list of sems for etape_apogee in annee_scolaire
|
|
|
|
"""
|
|
|
|
return sco_formsemestre.list_formsemestre_by_etape(
|
2021-08-19 10:28:35 +02:00
|
|
|
etape_apo=str(etape_apogee), annee_scolaire=annee_scolaire
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-08-21 00:24:51 +02:00
|
|
|
def nar_etuds_table(apo_data, NAR_Etuds):
|
2021-01-01 18:40:47 +01:00
|
|
|
"""Liste les NAR -> excel table"""
|
2020-09-26 16:19:37 +02:00
|
|
|
code_etape = apo_data.etape_apogee
|
|
|
|
today = datetime.datetime.today().strftime("%d/%m/%y")
|
2023-04-16 05:32:21 +02:00
|
|
|
rows = []
|
2020-09-26 16:19:37 +02:00
|
|
|
NAR_Etuds.sort(key=lambda k: k["nom"])
|
|
|
|
for e in NAR_Etuds:
|
2023-04-16 05:32:21 +02:00
|
|
|
rows.append(
|
2020-09-26 16:19:37 +02:00
|
|
|
{
|
|
|
|
"nom": e["nom"],
|
|
|
|
"prenom": e["prenom"],
|
|
|
|
"c0": "",
|
|
|
|
"c1": "AD",
|
|
|
|
"etape": code_etape,
|
|
|
|
"c3": "",
|
|
|
|
"c4": "",
|
|
|
|
"c5": "",
|
|
|
|
"c6": "N",
|
|
|
|
"c7": "",
|
|
|
|
"c8": "",
|
|
|
|
"NIP": e["nip"],
|
|
|
|
"c10": "",
|
|
|
|
"c11": "",
|
|
|
|
"c12": "",
|
|
|
|
"c13": "NAR - Jury",
|
|
|
|
"date": today,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
columns_ids = (
|
|
|
|
"NIP",
|
|
|
|
"nom",
|
|
|
|
"prenom",
|
|
|
|
"etape",
|
|
|
|
"c0",
|
|
|
|
"c1",
|
|
|
|
"c3",
|
|
|
|
"c4",
|
|
|
|
"c5",
|
|
|
|
"c6",
|
|
|
|
"c7",
|
|
|
|
"c8",
|
|
|
|
"c10",
|
|
|
|
"c11",
|
|
|
|
"c12",
|
|
|
|
"c13",
|
|
|
|
"date",
|
|
|
|
)
|
2023-04-16 05:32:21 +02:00
|
|
|
table = GenTable(
|
2020-09-26 16:19:37 +02:00
|
|
|
columns_ids=columns_ids,
|
|
|
|
titles=dict(zip(columns_ids, columns_ids)),
|
2023-04-16 05:32:21 +02:00
|
|
|
rows=rows,
|
2020-09-26 16:19:37 +02:00
|
|
|
xls_sheet_name="NAR ScoDoc",
|
|
|
|
)
|
2023-04-16 05:32:21 +02:00
|
|
|
return table.excel()
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
def export_csv_to_apogee(
|
2022-01-07 17:58:34 +01:00
|
|
|
apo_csv_data: str,
|
2020-09-26 16:19:37 +02:00
|
|
|
periode=None,
|
|
|
|
dest_zip=None,
|
|
|
|
export_res_etape=True,
|
|
|
|
export_res_sem=True,
|
|
|
|
export_res_ues=True,
|
|
|
|
export_res_modules=True,
|
|
|
|
export_res_sdj=True,
|
|
|
|
export_res_rat=True,
|
|
|
|
):
|
2021-01-01 18:40:47 +01:00
|
|
|
"""Genere un fichier CSV Apogée
|
2020-09-26 16:19:37 +02:00
|
|
|
à partir d'un fichier CSV Apogée vide (ou partiellement rempli)
|
|
|
|
et des résultats ScoDoc.
|
|
|
|
Si dest_zip, ajoute les fichiers générés à ce zip
|
|
|
|
sinon crée un zip et le publie
|
|
|
|
"""
|
|
|
|
apo_data = ApoData(
|
|
|
|
apo_csv_data,
|
|
|
|
periode=periode,
|
|
|
|
export_res_etape=export_res_etape,
|
|
|
|
export_res_sem=export_res_sem,
|
|
|
|
export_res_ues=export_res_ues,
|
|
|
|
export_res_modules=export_res_modules,
|
|
|
|
export_res_sdj=export_res_sdj,
|
|
|
|
export_res_rat=export_res_rat,
|
|
|
|
)
|
2021-08-21 00:24:51 +02:00
|
|
|
apo_data.setup() # -> .sems_etape
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
for e in apo_data.etuds:
|
2022-07-13 11:30:01 +02:00
|
|
|
e.is_apc = apo_data.is_apc
|
2021-08-21 00:24:51 +02:00
|
|
|
e.lookup_scodoc(apo_data.etape_formsemestre_ids)
|
|
|
|
e.associate_sco(apo_data)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
# Ré-écrit le fichier Apogée
|
2021-08-15 15:01:13 +02:00
|
|
|
f = io.StringIO()
|
2020-09-26 16:19:37 +02:00
|
|
|
apo_data.write_header(f)
|
|
|
|
apo_data.write_etuds(f)
|
|
|
|
|
|
|
|
# Table des NAR:
|
|
|
|
NAR_Etuds = [e for e in apo_data.etuds if e.is_NAR]
|
|
|
|
if NAR_Etuds:
|
2021-08-21 00:24:51 +02:00
|
|
|
nar_xls = nar_etuds_table(apo_data, NAR_Etuds)
|
2020-09-26 16:19:37 +02:00
|
|
|
else:
|
|
|
|
nar_xls = None
|
|
|
|
|
|
|
|
# Journaux & Comptes-rendus
|
|
|
|
# Orphelins: etudiants dans fichier Apogée mais pas dans ScoDoc
|
|
|
|
Apo_Non_ScoDoc = [e for e in apo_data.etuds if e.etat == ETUD_ORPHELIN]
|
|
|
|
# Non inscrits: connus de ScoDoc mais pas inscrit dans l'étape cette année
|
|
|
|
Apo_Non_ScoDoc_Inscrits = [e for e in apo_data.etuds if e.etat == ETUD_NON_INSCRIT]
|
|
|
|
# CR table
|
|
|
|
cr_table = apo_data.build_cr_table()
|
|
|
|
cr_xls = cr_table.excel()
|
|
|
|
|
|
|
|
# Create ZIP
|
|
|
|
if not dest_zip:
|
2021-08-31 19:32:12 +02:00
|
|
|
data = io.BytesIO()
|
2020-09-26 16:19:37 +02:00
|
|
|
dest_zip = ZipFile(data, "w")
|
|
|
|
my_zip = True
|
|
|
|
else:
|
|
|
|
my_zip = False
|
|
|
|
# Ensure unique filenames
|
|
|
|
filename = apo_data.titles["apoC_Fichier_Exp"]
|
|
|
|
basename, ext = os.path.splitext(filename)
|
|
|
|
csv_filename = filename
|
|
|
|
|
|
|
|
if csv_filename in dest_zip.namelist():
|
|
|
|
basename = filename + "-" + apo_data.vdi_apogee
|
|
|
|
csv_filename = basename + ext
|
|
|
|
nf = 1
|
|
|
|
tmplname = basename
|
|
|
|
while csv_filename in dest_zip.namelist():
|
|
|
|
basename = tmplname + "-%d" % nf
|
|
|
|
csv_filename = basename + ext
|
|
|
|
nf += 1
|
|
|
|
|
|
|
|
log_filename = "scodoc-" + basename + ".log.txt"
|
2021-08-12 14:49:53 +02:00
|
|
|
nar_filename = basename + "-nar" + scu.XLSX_SUFFIX
|
|
|
|
cr_filename = basename + "-decisions" + scu.XLSX_SUFFIX
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2021-08-15 15:01:13 +02:00
|
|
|
logf = io.StringIO()
|
2023-04-16 05:32:21 +02:00
|
|
|
logf.write(f"export_to_apogee du {time.ctime()}\n\n")
|
2020-09-26 16:19:37 +02:00
|
|
|
logf.write("Semestres ScoDoc sources:\n")
|
|
|
|
for sem in apo_data.sems_etape:
|
|
|
|
logf.write("\t%(titremois)s\n" % sem)
|
2023-04-16 05:32:21 +02:00
|
|
|
|
|
|
|
def vrai(val):
|
|
|
|
return "vrai" if int(val) else "faux"
|
|
|
|
|
|
|
|
logf.write(f"Période: {periode}\n")
|
|
|
|
logf.write(f"exporte résultat à l'étape: {vrai(export_res_etape)}\n")
|
|
|
|
logf.write(f"exporte résultat à l'année: {vrai(export_res_sem)}\n")
|
|
|
|
logf.write(f"exporte résultats des UEs: {vrai(export_res_ues)}\n")
|
|
|
|
logf.write(f"exporte résultats des modules: {vrai(export_res_modules)}\n")
|
|
|
|
logf.write(f"exporte résultats sans décision de jury: {vrai(export_res_sdj)}\n")
|
2020-09-26 16:19:37 +02:00
|
|
|
logf.write(
|
2023-04-16 05:32:21 +02:00
|
|
|
"\nÉtudiants Apogée non trouvés dans ScoDoc:\n"
|
2020-09-26 16:19:37 +02:00
|
|
|
+ "\n".join(
|
|
|
|
["%s\t%s\t%s" % (e["nip"], e["nom"], e["prenom"]) for e in Apo_Non_ScoDoc]
|
|
|
|
)
|
|
|
|
)
|
|
|
|
logf.write(
|
2023-04-16 05:32:21 +02:00
|
|
|
"\nÉtudiants Apogée non inscrits sur ScoDoc dans cette étape:\n"
|
2020-09-26 16:19:37 +02:00
|
|
|
+ "\n".join(
|
|
|
|
[
|
|
|
|
"%s\t%s\t%s" % (e["nip"], e["nom"], e["prenom"])
|
|
|
|
for e in Apo_Non_ScoDoc_Inscrits
|
|
|
|
]
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
logf.write(
|
|
|
|
"\n\nElements Apogee inconnus dans ces semestres ScoDoc:\n"
|
|
|
|
+ "\n".join(apo_data.list_unknown_elements())
|
|
|
|
)
|
|
|
|
log(logf.getvalue()) # sortie aussi sur le log ScoDoc
|
|
|
|
|
2021-08-31 19:32:12 +02:00
|
|
|
csv_data = f.getvalue().encode(APO_OUTPUT_ENCODING)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
# Write data to ZIP
|
|
|
|
dest_zip.writestr(csv_filename, csv_data)
|
|
|
|
dest_zip.writestr(log_filename, logf.getvalue())
|
|
|
|
if nar_xls:
|
|
|
|
dest_zip.writestr(nar_filename, nar_xls)
|
|
|
|
dest_zip.writestr(cr_filename, cr_xls)
|
|
|
|
|
|
|
|
if my_zip:
|
|
|
|
dest_zip.close()
|
2021-08-31 19:32:12 +02:00
|
|
|
data.seek(0)
|
|
|
|
return send_file(
|
|
|
|
data,
|
|
|
|
mimetype="application/zip",
|
2021-08-31 20:18:50 +02:00
|
|
|
download_name=scu.sanitize_filename(basename + "-scodoc.zip"),
|
2021-08-31 19:32:12 +02:00
|
|
|
as_attachment=True,
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
|
|
|
else:
|
|
|
|
return None # zip modified in place
|