2021-04-02 11:54:35 +02:00
|
|
|
import logging
|
2021-04-07 11:51:19 +02:00
|
|
|
import string
|
2021-04-02 11:54:35 +02:00
|
|
|
import pypandoc
|
|
|
|
import ruamel.yaml
|
|
|
|
|
|
|
|
from modeles import get_modele, TemplateLatex
|
2021-04-07 11:51:19 +02:00
|
|
|
from officiel import *
|
2021-04-02 15:24:56 +02:00
|
|
|
from ressourcedocx import remove_ligne_vide
|
|
|
|
from tools import caracteres_recalcitrants
|
2021-04-02 11:54:35 +02:00
|
|
|
|
2021-04-07 11:51:19 +02:00
|
|
|
__LOGGER = logging.getLogger(__name__)
|
2021-04-02 11:54:35 +02:00
|
|
|
|
|
|
|
class Ressource():
|
|
|
|
"""Modélise une ressource lorsqu'elle est extraite d'un yaml"""
|
|
|
|
__LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
def __init__(self, fichieryaml):
|
|
|
|
with open(fichieryaml, "r", encoding="utf8") as fid:
|
|
|
|
yaml = ruamel.yaml.YAML()
|
|
|
|
try:
|
|
|
|
self.ressource = yaml.load(fid.read())
|
|
|
|
except:
|
|
|
|
Ressource.__LOGGER.warning(f"Pb de chargement de {fichieryaml}")
|
|
|
|
|
2021-04-02 16:08:14 +02:00
|
|
|
def to_latex(self, modele="pn/modele_ressource.tex"):
|
2021-04-02 11:54:35 +02:00
|
|
|
"""Génère le code latex décrivant la ressource"""
|
|
|
|
modlatex = get_modele(modele) #"pn/modele_ressource.tex")
|
|
|
|
|
2021-04-07 11:51:19 +02:00
|
|
|
# if self.ressource["code"] == "R107":
|
|
|
|
# print("ici")
|
2021-04-02 11:54:35 +02:00
|
|
|
|
2021-04-07 11:51:19 +02:00
|
|
|
# Préparation des coeffs
|
|
|
|
ajoutcoeff = "\\ajoutRcoeff{%s}"
|
|
|
|
coeffRT = []
|
|
|
|
for comp in ['RT1', 'RT2', 'RT3']:
|
|
|
|
if comp in self.ressource["coeffs"]:
|
|
|
|
coeffRT.append(ajoutcoeff % (str(self.ressource["coeffs"][comp])))
|
|
|
|
else:
|
|
|
|
coeffRT.append("")
|
2021-04-02 11:54:35 +02:00
|
|
|
|
|
|
|
# Préparation des ac
|
2021-04-02 16:08:14 +02:00
|
|
|
ajoutac = "\\ajoutRac{%s}{%s}"
|
2021-04-02 11:54:35 +02:00
|
|
|
compRT = []
|
2021-04-07 11:51:19 +02:00
|
|
|
for accomp in ['RT1', 'RT2', 'RT3']:
|
2021-04-02 11:54:35 +02:00
|
|
|
comps = []
|
2021-04-07 11:51:19 +02:00
|
|
|
if accomp in self.ressource["acs"]:
|
|
|
|
for no_ac in range(len(self.ressource["acs"][accomp])): # les ac de la comp
|
|
|
|
code_ac = self.ressource["acs"][accomp][no_ac]
|
|
|
|
comps.append( ajoutac % (code_ac, DATA_ACS[accomp][code_ac]) )
|
2021-04-02 11:54:35 +02:00
|
|
|
compRT.append("\n".join(comps))
|
|
|
|
|
|
|
|
# Préparation des sae
|
2021-04-07 11:51:19 +02:00
|
|
|
ajoutsaes = "\\ajoutRsae{%s}{%s}" # nom, intitule, code_latex
|
2021-04-02 11:54:35 +02:00
|
|
|
saesRT = []
|
|
|
|
for (i, sae) in enumerate(self.ressource["sae"]): # in range(len(self.apprentissages)):
|
2021-04-07 11:51:19 +02:00
|
|
|
code_latex = string.ascii_uppercase[int(sae[-2])-1] + string.ascii_uppercase[int(sae[-1])-1]
|
|
|
|
saesRT.append(ajoutsaes % (sae, get_officiel_sae_name_by_code(sae))) # , code_latex))
|
2021-04-02 11:54:35 +02:00
|
|
|
saes = "\n".join(saesRT)
|
|
|
|
|
2021-04-02 16:08:14 +02:00
|
|
|
ajoutprerequis = "\\ajoutRprerequis{%s}{%s}"
|
2021-04-02 11:54:35 +02:00
|
|
|
prerequis = ""
|
|
|
|
if self.ressource["prerequis"] == "Aucun":
|
|
|
|
prerequis = ""
|
|
|
|
else:
|
|
|
|
liste = []
|
|
|
|
for (no, mod) in enumerate(self.ressource["prerequis"]):
|
|
|
|
liste.append(ajoutprerequis % (mod, get_officiel_ressource_name_by_code(mod)))
|
|
|
|
prerequis = "\n".join(liste)
|
|
|
|
|
|
|
|
# préparation du contexte
|
|
|
|
contexte = self.ressource["contexte"]
|
2021-04-02 12:08:09 +02:00
|
|
|
if contexte == "Aucun":
|
|
|
|
contexte = ""
|
|
|
|
Ressource.__LOGGER.warning(f"{self.ressource['nom']} n'a pas de contexte")
|
2021-04-02 11:54:35 +02:00
|
|
|
|
2021-04-02 12:08:09 +02:00
|
|
|
else:
|
2021-04-07 11:51:19 +02:00
|
|
|
contexte = md_to_latex(contexte)
|
2021-04-02 12:08:09 +02:00
|
|
|
|
2021-04-02 11:54:35 +02:00
|
|
|
# contexte = remove_ligne_vide(contexte)
|
|
|
|
# préparation du contenu
|
|
|
|
|
|
|
|
contenu = self.ressource["contenu"] #supprime les passages à la ligne
|
|
|
|
|
2021-04-07 11:51:19 +02:00
|
|
|
if contenu:
|
|
|
|
if self.ressource["code"] == "R112":
|
|
|
|
print("ici")
|
|
|
|
contenu = md_to_latex(contenu)
|
|
|
|
|
2021-04-02 11:54:35 +02:00
|
|
|
|
|
|
|
chaine = ""
|
|
|
|
chaine = TemplateLatex(modlatex).substitute(code=self.ressource["code"],
|
|
|
|
nom=self.ressource["nom"],
|
|
|
|
heures_formation=self.ressource["heures_formation"],
|
|
|
|
heures_tp=self.ressource["heures_tp"],
|
2021-04-07 11:51:19 +02:00
|
|
|
coeffRT1=coeffRT[0],
|
|
|
|
coeffRT2=coeffRT[1],
|
|
|
|
coeffRT3=coeffRT[2],
|
2021-04-02 11:54:35 +02:00
|
|
|
compRT1=compRT[0],
|
|
|
|
compRT2=compRT[1],
|
|
|
|
compRT3=compRT[2],
|
|
|
|
saes=saes,
|
2021-04-05 12:05:04 +02:00
|
|
|
motscles=self.ressource["motscles"],
|
2021-04-02 11:54:35 +02:00
|
|
|
prerequis=prerequis,
|
2021-04-05 12:05:04 +02:00
|
|
|
contexte=contexte,
|
2021-04-02 11:54:35 +02:00
|
|
|
contenu=contenu,
|
|
|
|
)
|
|
|
|
# chaine = chaine.replace("&", "\&")
|
2021-04-10 09:13:52 +02:00
|
|
|
# Supprime les \\tighlist ajoutés par pypandoc
|
2021-04-02 11:54:35 +02:00
|
|
|
chaine = chaine.replace("\\tightlist\n", "")
|
2021-04-10 09:13:52 +02:00
|
|
|
chaine = ajoute_abbr_latex(chaine)
|
|
|
|
|
|
|
|
# Insère les abbréviations
|
2021-04-02 17:38:56 +02:00
|
|
|
return chaine
|
|
|
|
|
|
|
|
|
2021-04-10 09:13:52 +02:00
|
|
|
def contient_abbr(chaine):
|
|
|
|
mots = []
|
|
|
|
for lettre in DATA_ABBREVIATIONS:
|
|
|
|
for mot in DATA_ABBREVIATIONS[lettre]:
|
|
|
|
if mot in chaine:
|
|
|
|
mots.append(mot)
|
|
|
|
mots = sorted(mots, key=lambda m: len(m), reverse=True) # les mots triés par nbre de carac décroissant
|
|
|
|
return mots
|
|
|
|
|
|
|
|
def ajoute_abbr_latex(chaine):
|
|
|
|
"""Parse la chaine latex pour ajouter les abbréviations"""
|
|
|
|
mots = chaine.split(" ")
|
|
|
|
for (i, mot) in enumerate(mots):
|
|
|
|
abbrs = contient_abbr(mot)
|
|
|
|
if abbrs:
|
|
|
|
mots[i] = mots[i].replace(abbrs[0], "\\texttt{" + abbrs[0] + "}")
|
|
|
|
chaine = " ".join(mots)
|
|
|
|
if "/IP" in chaine:
|
|
|
|
chaine = chaine.replace("/IP", "/\\texttt{IP}")
|
|
|
|
return chaine
|
|
|
|
|
|
|
|
|
2021-04-02 17:38:56 +02:00
|
|
|
class SAE():
|
2021-04-03 09:53:25 +02:00
|
|
|
"""Modélise une saé (chapeau) lorsqu'elle est extraite d'un yaml"""
|
2021-04-02 17:38:56 +02:00
|
|
|
__LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
def __init__(self, fichieryaml):
|
|
|
|
with open(fichieryaml, "r", encoding="utf8") as fid:
|
|
|
|
yaml = ruamel.yaml.YAML()
|
|
|
|
try:
|
|
|
|
self.sae = yaml.load(fid.read())
|
|
|
|
except:
|
|
|
|
Ressource.__LOGGER.warning(f"Pb de chargement de {fichieryaml}")
|
|
|
|
|
2021-04-07 11:51:19 +02:00
|
|
|
|
|
|
|
|
2021-04-02 17:38:56 +02:00
|
|
|
def to_latex(self, modele="pn/modele_sae.tex"):
|
|
|
|
"""Génère le code latex décrivant la ressource"""
|
|
|
|
modlatex = get_modele(modele) #"pn/modele_ressource.tex")
|
|
|
|
|
2021-04-07 11:51:19 +02:00
|
|
|
# Préparation des coeffs
|
|
|
|
ajoutcoeff = "\\ajoutScoeff{%s}"
|
|
|
|
coeffRT = []
|
|
|
|
for comp in ['RT1', 'RT2', 'RT3']:
|
|
|
|
if comp in self.sae["coeffs"]:
|
|
|
|
coeffRT.append(ajoutcoeff % (str(self.sae["coeffs"][comp])))
|
|
|
|
else:
|
|
|
|
coeffRT.append("")
|
|
|
|
|
2021-04-02 17:38:56 +02:00
|
|
|
# Préparation des ac
|
2021-04-07 11:51:19 +02:00
|
|
|
ajoutac = "\\ajoutSac{%s}{%s}" # nom, intitule, code latex
|
2021-04-02 17:38:56 +02:00
|
|
|
compRT = []
|
2021-04-07 11:51:19 +02:00
|
|
|
for accomp in ['RT1', 'RT2', 'RT3']:
|
2021-04-03 09:53:25 +02:00
|
|
|
comps = []
|
2021-04-07 11:51:19 +02:00
|
|
|
if accomp in self.sae["acs"]:
|
|
|
|
for no_ac in range(len(self.sae["acs"][accomp])): # les ac de la comp
|
|
|
|
code_ac = self.sae["acs"][accomp][no_ac]
|
|
|
|
comps.append( ajoutac % (code_ac, DATA_ACS[accomp][code_ac]) )
|
|
|
|
|
2021-04-03 09:53:25 +02:00
|
|
|
compRT.append("\n".join(comps))
|
|
|
|
|
|
|
|
# Préparation des ressources
|
|
|
|
ajoutressources = "\\ajoutSressources{%s}{%s}"
|
|
|
|
resRT = []
|
|
|
|
for (i, res) in enumerate(self.sae["ressources"]): # in range(len(self.apprentissages)):
|
|
|
|
resRT.append(ajoutressources % (res, get_officiel_ressource_name_by_code(res)))
|
|
|
|
ressources = "\n".join(resRT)
|
|
|
|
|
|
|
|
|
|
|
|
# préparation du descriptif
|
|
|
|
descriptif = self.sae["description"]
|
|
|
|
if descriptif == "Aucun":
|
|
|
|
descriptif = ""
|
|
|
|
SAE.__LOGGER.warning(f"{self.sae['titre']} n'a pas de description")
|
|
|
|
else:
|
|
|
|
descriptif = md_to_latex(descriptif)
|
|
|
|
|
|
|
|
# préparation des livrables
|
|
|
|
livrables = self.sae["livrables"]
|
|
|
|
if livrables == "Aucun":
|
|
|
|
livrables = ""
|
|
|
|
SAE.__LOGGER.warning(f"{self.sae['titre']} n'a pas de livrables")
|
|
|
|
else:
|
|
|
|
livrables = md_to_latex(livrables)
|
|
|
|
|
|
|
|
chaine = ""
|
|
|
|
chaine = TemplateLatex(modlatex).substitute(code=self.sae["code"],
|
|
|
|
titre=self.sae["titre"],
|
|
|
|
heures_encadrees=self.sae["heures_encadrees"],
|
|
|
|
heures_tp=self.sae["tp"],
|
|
|
|
heures_projet=self.sae["projet"],
|
2021-04-07 11:51:19 +02:00
|
|
|
coeffRT1=coeffRT[0],
|
|
|
|
coeffRT2=coeffRT[1],
|
|
|
|
coeffRT3=coeffRT[2],
|
2021-04-03 09:53:25 +02:00
|
|
|
compRT1=compRT[0],
|
|
|
|
compRT2=compRT[1],
|
|
|
|
compRT3=compRT[2],
|
2021-04-05 12:05:04 +02:00
|
|
|
description=descriptif,
|
2021-04-03 09:53:25 +02:00
|
|
|
ressources=ressources,
|
|
|
|
livrables= livrables,
|
2021-04-05 12:05:04 +02:00
|
|
|
motscles = self.sae["motscles"],
|
2021-04-03 09:53:25 +02:00
|
|
|
)
|
|
|
|
# chaine = chaine.replace("&", "\&")
|
|
|
|
|
|
|
|
chaine = chaine.replace("\\tightlist\n", "")
|
2021-04-10 09:13:52 +02:00
|
|
|
chaine = ajoute_abbr_latex(chaine)
|
2021-04-03 09:53:25 +02:00
|
|
|
return chaine
|
|
|
|
|
|
|
|
class ExempleSAE():
|
|
|
|
"""Modélise un exemple de SAE lorsqu'elle est extraite d'un yaml"""
|
|
|
|
__LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
def __init__(self, fichieryaml):
|
|
|
|
with open(fichieryaml, "r", encoding="utf8") as fid:
|
|
|
|
yaml = ruamel.yaml.YAML()
|
|
|
|
try:
|
|
|
|
self.exemple = yaml.load(fid.read())
|
|
|
|
except:
|
|
|
|
Ressource.__LOGGER.warning(f"Pb de chargement de {fichieryaml}")
|
|
|
|
|
2021-04-03 14:55:05 +02:00
|
|
|
def to_latex(self, modele="pn/modele_exemple_sae.tex"):
|
2021-04-03 09:53:25 +02:00
|
|
|
"""Génère le code latex décrivant la ressource"""
|
|
|
|
modlatex = get_modele(modele) #"pn/modele_ressource.tex")
|
|
|
|
|
2021-04-02 17:38:56 +02:00
|
|
|
# préparation du descriptif
|
2021-04-03 14:55:05 +02:00
|
|
|
description = self.exemple["description"]
|
|
|
|
if not description:
|
|
|
|
description = ""
|
|
|
|
ExempleSAE.__LOGGER.warning(f"{self.exemple['titre']} n'a pas de description")
|
2021-04-02 17:38:56 +02:00
|
|
|
else:
|
2021-04-03 14:55:05 +02:00
|
|
|
description = md_to_latex(description)
|
|
|
|
|
|
|
|
# préparation de la forme
|
|
|
|
formes = self.exemple["formes"]
|
|
|
|
if not formes:
|
|
|
|
formes = ""
|
|
|
|
ExempleSAE.__LOGGER.warning(f"{self.exemple['titre']} n'a pas de formes")
|
2021-04-02 17:38:56 +02:00
|
|
|
else:
|
2021-04-03 14:55:05 +02:00
|
|
|
formes = md_to_latex(formes)
|
|
|
|
|
|
|
|
# préparation de la problématique
|
|
|
|
problematique = self.exemple["problematique"]
|
2021-04-10 09:13:52 +02:00
|
|
|
if not problematique:
|
2021-04-03 14:55:05 +02:00
|
|
|
problematique = ""
|
|
|
|
ExempleSAE.__LOGGER.warning(f"{self.exemple['titre']} n'a pas de problematique")
|
|
|
|
else:
|
|
|
|
problematique = md_to_latex(problematique)
|
|
|
|
|
|
|
|
# préparation des modalites
|
|
|
|
modalite = self.exemple["modalite"]
|
2021-04-10 09:13:52 +02:00
|
|
|
if not modalite:
|
2021-04-03 14:55:05 +02:00
|
|
|
modalite = ""
|
|
|
|
ExempleSAE.__LOGGER.warning(f"{self.exemple['titre']} n'a pas de modalite")
|
|
|
|
else:
|
|
|
|
modalite = md_to_latex(modalite)
|
2021-04-02 17:38:56 +02:00
|
|
|
|
|
|
|
chaine = ""
|
2021-04-03 14:55:05 +02:00
|
|
|
chaine = TemplateLatex(modlatex).substitute(titre=self.exemple["titre"],
|
|
|
|
description=description,
|
|
|
|
formes=formes,
|
|
|
|
problematique = problematique,
|
|
|
|
modalite=modalite
|
|
|
|
)
|
2021-04-02 17:38:56 +02:00
|
|
|
# chaine = chaine.replace("&", "\&")
|
|
|
|
|
|
|
|
chaine = chaine.replace("\\tightlist\n", "")
|
2021-04-10 09:13:52 +02:00
|
|
|
chaine = ajoute_abbr_latex(chaine)
|
2021-04-02 17:38:56 +02:00
|
|
|
return chaine
|
|
|
|
|
|
|
|
def md_to_latex(contenu):
|
|
|
|
"""Réalise la conversion markdown to latex avec pypandoc"""
|
2021-04-04 09:34:03 +02:00
|
|
|
contenu = contenu.replace("\n", "\n\n") # corrige les suppressions de ligne à la relecture du yaml
|
|
|
|
|
2021-04-02 17:38:56 +02:00
|
|
|
contenu = pypandoc.convert_text(contenu, 'tex', format='md',
|
|
|
|
extra_args=['--atx-headers'])
|
|
|
|
contenu = contenu.replace("\r\n", "\n")
|
2021-04-07 11:51:19 +02:00
|
|
|
lignes = contenu.split("\n\n") # Détecte les sauts de ligne
|
|
|
|
for (i, ligne) in enumerate(lignes):
|
|
|
|
if i < len(lignes)-1:
|
|
|
|
if lignes[i].strip().startswith("\\") == False and \
|
|
|
|
lignes[i].startswith(" ") == False and \
|
|
|
|
lignes[i+1].strip().startswith("\\") == False and \
|
|
|
|
lignes[i+1].startswith(" ") == False and \
|
|
|
|
lignes[i].strip().endswith("\\\\") == False:
|
|
|
|
lignes[i] = lignes[i] + "\\\\" # ajoute un passage à la ligne latex
|
|
|
|
contenu = "\n\n".join(lignes)
|
|
|
|
|
2021-04-05 12:05:04 +02:00
|
|
|
# contenu = caracteres_recalcitrants(contenu)
|
2021-04-02 17:38:56 +02:00
|
|
|
contenu = remove_ligne_vide(contenu)
|
2021-04-04 09:34:03 +02:00
|
|
|
lignes = contenu.split("\n") # pour debug
|
|
|
|
|
|
|
|
if contenu.startswith("\\begin{itemize}"):
|
|
|
|
contenu = "\\vspace{-5pt}\n" + contenu # ajout d'un offset en cas de liste à puces
|
2021-04-07 11:51:19 +02:00
|
|
|
contenu = contenu.replace("\\\\"*2, "\\\\")
|
|
|
|
return contenu
|
|
|
|
|
|
|
|
|
|
|
|
def get_matrices_ac_ressource(saes, ressources, sem):
|
|
|
|
"""Calcule la matrice AC vs sae + ressource pour un sem donné et la renvoie"""
|
|
|
|
les_codes_acs = [code for comp in DATA_ACS for code in DATA_ACS[comp]]
|
|
|
|
nbre_acs = len(les_codes_acs)
|
|
|
|
|
|
|
|
saesem = saes[sem] # les saé du semestre
|
|
|
|
ressem = ressources[sem] # les ressources du semestre
|
|
|
|
|
|
|
|
nbre_saes = len(DATA_SAES[sem])
|
|
|
|
nbre_ressources = len(DATA_RESSOURCES[sem])
|
|
|
|
if len(saesem)!= nbre_saes or len(ressem) != nbre_ressources:
|
|
|
|
__LOGGER.warning(f"Pb => il manque des saes/ressources au {sem}")
|
|
|
|
|
|
|
|
matrice = [[False] * (nbre_saes + nbre_ressources) for i in range(nbre_acs)]
|
|
|
|
|
|
|
|
for (i, s) in enumerate(saesem): # pour chaque SAE
|
|
|
|
for comp in s.sae["acs"]: # pour chaque comp
|
2021-04-09 08:13:12 +02:00
|
|
|
for (j, ac) in enumerate(DATA_ACS[comp]): # pour chaque ac
|
2021-04-07 11:51:19 +02:00
|
|
|
if ac in s.sae["acs"][comp]: # si l'ac est prévue dans la ressource
|
2021-04-09 08:13:12 +02:00
|
|
|
k = les_codes_acs.index(ac)
|
|
|
|
matrice[k][i] = True
|
2021-04-07 11:51:19 +02:00
|
|
|
|
|
|
|
for (i, r) in enumerate(ressem): # pour chaque ressource
|
|
|
|
for comp in r.ressource["acs"]: # pour chaque comp
|
2021-04-09 08:13:12 +02:00
|
|
|
for (j, ac) in enumerate(DATA_ACS[comp]): # pour chaque ac
|
2021-04-07 11:51:19 +02:00
|
|
|
if ac in r.ressource["acs"][comp]: # si l'ac est prévue dans la ressource
|
2021-04-09 08:13:12 +02:00
|
|
|
k = les_codes_acs.index(ac)
|
|
|
|
matrice[k][i+nbre_saes] = True
|
2021-04-07 11:51:19 +02:00
|
|
|
return matrice
|
|
|
|
|
|
|
|
def get_matrices_coeffs(saes, ressources, sem):
|
|
|
|
"""Calcule la matrice AC vs sae + ressource pour un sem donné et la renvoie"""
|
|
|
|
comps = ['RT1', 'RT2', 'RT3']
|
|
|
|
|
|
|
|
saesem = saes[sem] # les saé du semestre
|
|
|
|
ressem = ressources[sem] # les ressources du semestre
|
|
|
|
|
|
|
|
nbre_saes = len(DATA_SAES[sem])
|
|
|
|
nbre_ressources = len(DATA_RESSOURCES[sem])
|
|
|
|
if len(saesem)!= nbre_saes or len(ressem) != nbre_ressources:
|
|
|
|
__LOGGER.warning(f"Pb => il manque des saes/ressources au {sem}")
|
|
|
|
|
|
|
|
matrice = [[None] * (len(comps)) for i in range(nbre_saes + nbre_ressources)]
|
|
|
|
|
|
|
|
for (i, s) in enumerate(saesem): # pour chaque SAE
|
|
|
|
for (j, comp) in enumerate(comps): # pour chaque comp
|
|
|
|
if comp in s.sae["coeffs"]:
|
|
|
|
matrice[i][j] = s.sae["coeffs"][comp]
|
|
|
|
|
|
|
|
for (i, r) in enumerate(ressem): # pour chaque ressource
|
|
|
|
for (j, comp) in enumerate(comps): # pour chaque comp
|
|
|
|
if comp in r.ressource["coeffs"]: # pour chaque ac
|
|
|
|
matrice[i+nbre_saes][j] = r.ressource["coeffs"][comp]
|
|
|
|
return matrice
|
|
|
|
|
|
|
|
def get_matrices_volumes(saes, ressources, sem):
|
|
|
|
"""Calcule la matrice AC vs sae + ressource pour un sem donné et la renvoie"""
|
|
|
|
format = ['CM/TD', 'TP', 'Projet']
|
|
|
|
|
|
|
|
saesem = saes[sem] # les saé du semestre
|
|
|
|
ressem = ressources[sem] # les ressources du semestre
|
|
|
|
|
|
|
|
nbre_saes = len(DATA_SAES[sem])
|
|
|
|
nbre_ressources = len(DATA_RESSOURCES[sem])
|
|
|
|
if len(saesem)!= nbre_saes or len(ressem) != nbre_ressources:
|
|
|
|
__LOGGER.warning(f"Pb => il manque des saes/ressources au {sem}")
|
|
|
|
|
|
|
|
matrice = [[0] * (len(format)) for i in range(nbre_saes + nbre_ressources)]
|
|
|
|
|
|
|
|
for (i, s) in enumerate(saesem): # pour chaque SAE
|
|
|
|
formation = s.sae["heures_encadrees"] if not isinstance(s.sae["heures_encadrees"], str) else 0
|
|
|
|
tp = s.sae["tp"] if not isinstance(s.sae["tp"], str) else 0
|
|
|
|
matrice[i][0] = formation - tp
|
|
|
|
matrice[i][1] = tp
|
|
|
|
matrice[i][2] = s.sae["projet"] if not isinstance(s.sae["projet"], str) else 0
|
|
|
|
|
|
|
|
for (i, r) in enumerate(ressem): # pour chaque ressource
|
|
|
|
formation = r.ressource["heures_formation"] if not isinstance(r.ressource["heures_formation"], str) else 0
|
|
|
|
tp = r.ressource["heures_tp"] if not isinstance(r.ressource["heures_tp"], str) else 0
|
|
|
|
matrice[i + nbre_saes][0] = formation - tp
|
|
|
|
matrice[i + nbre_saes][1] = tp
|
|
|
|
|
|
|
|
return matrice
|
|
|
|
|
|
|
|
def str_matrice(matrice, saes, ressources, sem):
|
|
|
|
"""Renvoie une chaine de caractère affichant la matrice"""
|
|
|
|
les_codes_acs = [code for comp in DATA_ACS for code in DATA_ACS[comp]]
|
|
|
|
nbre_acs = len(les_codes_acs)
|
|
|
|
|
|
|
|
saesem = saes[sem] # les saé du semestre
|
|
|
|
ressem = ressources[sem] # les ressources du semestre
|
|
|
|
|
|
|
|
nbre_saes = len(DATA_SAES[sem])
|
|
|
|
nbre_ressources = len(DATA_RESSOURCES[sem])
|
|
|
|
|
|
|
|
chaine = ""
|
|
|
|
ligne = "{:20s} | " + "{:5s} | " * (nbre_saes + nbre_ressources)
|
|
|
|
valeurs = ("" for i in range(nbre_saes + nbre_ressources + 1))
|
|
|
|
trait = "-" * len(ligne.format(*valeurs))
|
|
|
|
|
|
|
|
valeurs = [""] + [s.sae["code"] if s.sae["code"] else "????" for s in saesem] +\
|
|
|
|
[r.ressource["code"] if r.ressource["code"] else "????" for r in ressem] + [""] * (nbre_saes - len(saesem) + nbre_ressources - len(ressem))
|
|
|
|
valeurs = tuple(valeurs)
|
|
|
|
chaine += ligne.format(*valeurs) + "\n" + trait + "\n"
|
|
|
|
for (j, ac) in enumerate(les_codes_acs):
|
|
|
|
valeurs = [ac] + [("X" if matrice[j][i] == True else "") for i in range(nbre_saes + nbre_ressources )]
|
|
|
|
valeurs = tuple(valeurs)
|
|
|
|
chaine += ligne.format(*valeurs) + "\n"
|
|
|
|
chaine += trait + "\n"
|
|
|
|
return chaine
|
|
|
|
|
|
|
|
def cesure_contenu(contenu, long_max = 30):
|
|
|
|
chaine = "\\rotatebox[origin=c]{90}{\n"
|
|
|
|
chaine += "\\begin{tabular}{ll}\n"
|
|
|
|
contenu_cesure = []
|
|
|
|
while contenu:
|
|
|
|
indice_espace = contenu.find(" ", long_max)
|
|
|
|
if indice_espace<0:
|
|
|
|
contenu_cesure.append(contenu)
|
|
|
|
contenu = ""
|
|
|
|
else:
|
|
|
|
contenu_cesure.append(contenu[:indice_espace])
|
|
|
|
contenu = contenu[indice_espace+1:]
|
|
|
|
chaine += " \\\\ ".join(contenu_cesure)
|
|
|
|
chaine += "\\end{tabular} }"
|
|
|
|
return chaine
|
|
|
|
|
|
|
|
def rotation_entete_colonne(contenu, pos="l"):
|
|
|
|
chaine = "\\rotatebox[origin=" + pos + "]{90}{"
|
|
|
|
chaine += contenu + "}"
|
|
|
|
return chaine
|
|
|
|
|
|
|
|
def to_latex_matrice_acs(matrice, saes, ressources, sem):
|
|
|
|
"""Renvoie le tableau latex affichant la matrice"""
|
|
|
|
|
|
|
|
les_codes_acs = [code for comp in DATA_ACS for code in DATA_ACS[comp]]
|
|
|
|
nbre_acs = len(les_codes_acs)
|
|
|
|
|
|
|
|
lettresem = "A" if sem=="S1" else "B"
|
|
|
|
|
|
|
|
saesem = saes[sem] # les saé du semestre
|
|
|
|
ressem = ressources[sem] # les ressources du semestre
|
|
|
|
|
|
|
|
|
|
|
|
nbre_saes = len(DATA_SAES[sem])
|
|
|
|
nbre_ressources = len(DATA_RESSOURCES[sem])
|
|
|
|
nbre_colonnes = nbre_saes + nbre_ressources + 2
|
|
|
|
|
|
|
|
chaine = "\\begin{tabular}[c]{|lp{3.5cm}||" + "c|"*(nbre_saes) + "|" + "c|"*(nbre_ressources) + "}" + "\n"
|
|
|
|
chaine += "\\hline \n" # % (nbre_saes + nbre_ressources+1)+ "\n"
|
|
|
|
# l'entete
|
|
|
|
chaine += " & & "
|
2021-04-09 08:13:12 +02:00
|
|
|
chaine += "\multicolumn{%d}{c||}{\\textcolor{saeC}{\\bfseries SAÉs}}" % (nbre_saes) + "\n"
|
2021-04-07 11:51:19 +02:00
|
|
|
chaine += " & "
|
2021-04-09 08:13:12 +02:00
|
|
|
chaine += "\multicolumn{%d}{c|}{\\textcolor{ressourceC}{\\bfseries Ressources}}" % (nbre_ressources) + "\\\\ \n"
|
2021-04-07 11:51:19 +02:00
|
|
|
chaine += "\\cline{3-%d}" % (nbre_colonnes)
|
|
|
|
chaine += " & & "
|
|
|
|
# les noms des SAE et des ressources
|
|
|
|
noms_saes = []
|
|
|
|
for (i, s) in enumerate(saesem): # pour chaque SAE
|
|
|
|
# saecode = "Scode" + lettresem + string.ascii_uppercase[i]
|
|
|
|
# contenu = "\\xdef\saecode{\csname " + saecode + "\endcsname}"
|
|
|
|
# contenu += "\\tiny{\\hyperlink{sae:\\saecode}{" + s.sae["titre"] + "~}}"
|
|
|
|
contenu = "\\tiny{" + s.sae["titre"] + "~}"
|
|
|
|
noms_saes.append(rotation_entete_colonne(contenu) + "\n")
|
|
|
|
chaine += " & ".join(noms_saes) + "\n"
|
|
|
|
chaine += " & "
|
|
|
|
noms_ressources = []
|
|
|
|
for (i, r) in enumerate(ressem): # pour chaque SAE
|
|
|
|
# contenu = r.ressource["code"] + " | " + r.ressource["nom"]
|
|
|
|
# noms_ressources.append(rotation_entete_colonne(contenu) + "\n")
|
|
|
|
contenu = "\\tiny{" + r.ressource["nom"] + "~}"
|
|
|
|
noms_ressources.append(rotation_entete_colonne(contenu) + "\n")
|
|
|
|
chaine += " & ".join(noms_ressources) + "\n"
|
|
|
|
chaine += "\\\\ \n"
|
|
|
|
|
|
|
|
# les codes des SAE et des ressources
|
|
|
|
noms_saes = []
|
|
|
|
chaine += " & & \n"
|
|
|
|
for (i, s) in enumerate(saesem): # pour chaque SAE
|
2021-04-09 08:13:12 +02:00
|
|
|
contenu = "~\\textcolor{saeC}{" + s.sae["code"] + "}~|"
|
2021-04-07 11:51:19 +02:00
|
|
|
noms_saes.append(rotation_entete_colonne(contenu, pos="r") + "\n")
|
|
|
|
chaine += " & ".join(noms_saes) + "\n"
|
|
|
|
chaine += " & "
|
|
|
|
noms_ressources = []
|
|
|
|
for (i, r) in enumerate(ressem): # pour chaque SAE
|
2021-04-09 08:13:12 +02:00
|
|
|
contenu = "~\\textcolor{ressourceC}{" + r.ressource["code"] + "}~|"
|
2021-04-07 11:51:19 +02:00
|
|
|
noms_ressources.append(rotation_entete_colonne(contenu, pos="r") + "\n")
|
|
|
|
chaine += " & ".join(noms_ressources) + "\n"
|
|
|
|
chaine += "\\\\ \n"
|
|
|
|
chaine += "\\hline \n"
|
|
|
|
|
|
|
|
# Les ACS et les croix
|
2021-04-09 08:13:12 +02:00
|
|
|
for (noc, comp) in enumerate(DATA_ACS):
|
2021-04-07 11:51:19 +02:00
|
|
|
nom_comp = DATA_COMPETENCES[comp]["nom"]
|
|
|
|
niveau = list(DATA_COMPETENCES[comp]["niveaux"].keys())[0]
|
2021-04-09 08:13:12 +02:00
|
|
|
couleur = "\\textcolor{compC" + string.ascii_uppercase[noc] + "}"
|
|
|
|
chaine += "\\multicolumn{%d}{|l|}{\hyperlink{comp:%s}{%s{\\bfseries %s - %s }}} \\\\" % (nbre_colonnes, comp, couleur, comp, nom_comp.replace("&", "\&"))
|
2021-04-07 11:51:19 +02:00
|
|
|
chaine += "\\multicolumn{%d}{|l|}{\small Niveau 1 - %s} \\\\" % (nbre_colonnes, niveau.replace("&", "\&"))
|
|
|
|
chaine += "\\hline \n"
|
|
|
|
for (k, ac) in enumerate(DATA_ACS[comp]):
|
2021-04-09 08:13:12 +02:00
|
|
|
chaine += couleur + "{" + ac + "}" + " | & " + "\n"
|
|
|
|
chaine += "\\begin{tabular}{p{3.2cm}} "
|
|
|
|
chaine += "\\tiny{" + DATA_ACS[comp][ac] + "}"
|
|
|
|
chaine += "\\end{tabular} & \n"
|
2021-04-07 11:51:19 +02:00
|
|
|
|
|
|
|
croix = []
|
2021-04-09 08:13:12 +02:00
|
|
|
indice_ac = les_codes_acs.index(ac)
|
2021-04-07 11:51:19 +02:00
|
|
|
for (i, s) in enumerate(saesem): # pour chaque SAE
|
2021-04-09 08:13:12 +02:00
|
|
|
croix.append("$\\times$" if matrice[indice_ac][i] == True else "")
|
2021-04-07 11:51:19 +02:00
|
|
|
chaine += " & ".join(croix) + "\n"
|
|
|
|
chaine += " & "
|
|
|
|
croix = []
|
|
|
|
for (j, r) in enumerate(ressem): # pour chaque SAE
|
2021-04-09 08:13:12 +02:00
|
|
|
croix.append("$\\times$" if matrice[indice_ac][nbre_saes + j] == True else "")
|
2021-04-07 11:51:19 +02:00
|
|
|
chaine += " & ".join(croix) + "\\\\ \n"
|
|
|
|
# if k < len(DATA_ACS[comp]) -1:
|
|
|
|
# chaine += "\\cline{2-%d}" % (nbre_saes+ nbre_ressources+3)
|
|
|
|
chaine += "\\hline \n"
|
|
|
|
chaine += "\\hline \n"
|
|
|
|
|
|
|
|
chaine += "\\end{tabular}"
|
|
|
|
return chaine
|
|
|
|
|
|
|
|
|
|
|
|
def to_latex_matrice_coeffs(matrice_vols, matrice_coeffs, saes, ressources, sem):
|
|
|
|
"""Renvoie le tableau latex affichant la matrice"""
|
|
|
|
|
|
|
|
def str_coeff(val):
|
|
|
|
if val == None:
|
|
|
|
return ""
|
|
|
|
else:
|
|
|
|
return str(val)
|
|
|
|
|
|
|
|
def str_volume(val):
|
|
|
|
if val:
|
|
|
|
return str(val) + "h"
|
|
|
|
else:
|
|
|
|
return " "
|
|
|
|
|
|
|
|
comps = ['RT1', 'RT2', 'RT3']
|
|
|
|
lettresem = "A" if sem == "S1" else "B"
|
|
|
|
|
|
|
|
saesem = saes[sem] # les saé du semestre
|
|
|
|
ressem = ressources[sem] # les ressources du semestre
|
|
|
|
|
|
|
|
nbre_saes = len(saesem)
|
|
|
|
nbre_colonnes = len(comps) + 3
|
|
|
|
|
|
|
|
|
|
|
|
chaine = "\\begin{tabular}[c]{|rcp{6cm}||" + "c|" * 2 + "|c|" + "|" + "c|"*(len(comps)) + "}" + "\n"
|
|
|
|
chaine += "\\hline \n" # % (nbre_saes + nbre_ressources+1)+ "\n"
|
|
|
|
# le début
|
|
|
|
chaine += " & & & " + "\\multicolumn{3}{c||}{\\bfseries Volumes} \n"
|
|
|
|
chaine += " & " + "\\multicolumn{3}{c|}{\\bfseries Coefficients} \n"
|
|
|
|
chaine += " \\\\ \\hline \n"
|
|
|
|
# l'entete
|
|
|
|
chaine += " & & & "
|
|
|
|
# Volume
|
|
|
|
chaine += rotation_entete_colonne("\\bfseries Heures de formation encadrée") + " & "
|
|
|
|
chaine += rotation_entete_colonne("\\bfseries Heures de TPs") + " & "
|
|
|
|
chaine += rotation_entete_colonne("\\bfseries Heures de projets") + " & "
|
|
|
|
# les noms des comps
|
|
|
|
noms = []
|
|
|
|
for (i, comp) in enumerate(comps): # pour chaque SAE
|
|
|
|
contenu = "\\begin{tabular}{p{5cm}}\n"
|
2021-04-09 08:13:12 +02:00
|
|
|
couleur = "\\textcolor{compC" + string.ascii_uppercase[i] + "}"
|
|
|
|
contenu += couleur + "{\\bfseries " + comp + "} - " + DATA_COMPETENCES[comp]["nom"].replace("&", "\&") + "\\\\ \n"
|
2021-04-07 11:51:19 +02:00
|
|
|
niveau = list(DATA_COMPETENCES[comp]["niveaux"].keys())[0]
|
|
|
|
contenu += " \\small Niveau 1 - " + niveau.replace("&", "\&") + "\n"
|
|
|
|
contenu += "\\end{tabular}\n"
|
|
|
|
noms.append(rotation_entete_colonne(contenu) + "\n")
|
|
|
|
chaine += " & ".join(noms) + "\n"
|
|
|
|
chaine += "\\\\ \n"
|
|
|
|
|
|
|
|
chaine += "\\hline"
|
|
|
|
chaine += "\\hline"
|
|
|
|
|
2021-04-09 08:13:12 +02:00
|
|
|
chaine += "\multicolumn{%d}{|l}{\\textcolor{saeC}{\\bfseries SAÉs}}" % (nbre_colonnes) + "\n"
|
2021-04-07 11:51:19 +02:00
|
|
|
chaine += "\\\\ \n"
|
|
|
|
chaine += "\\hline "
|
|
|
|
# le nom des SAE
|
|
|
|
for (i, s) in enumerate(saesem): # pour chaque SAE
|
2021-04-09 08:13:12 +02:00
|
|
|
chaine += "\\textcolor{saeC}{" + s.sae["code"] + "} & | & " + "\n"
|
2021-04-07 11:51:19 +02:00
|
|
|
chaine += "\\begin{tabular}{p{5.7cm}} \\tiny{" + s.sae["titre"] + "} \\end{tabular} & \n"
|
|
|
|
chaine += str_volume(matrice_vols[i][0]) + " & "
|
|
|
|
chaine += str_volume(matrice_vols[i][1]) + " & "
|
|
|
|
chaine += str_volume(matrice_vols[i][2]) + " & "
|
|
|
|
chaine += " & ".join([str_coeff(matrice_coeffs[i][j]) for j in range(len(comp))])
|
|
|
|
chaine += "\\\\ \n"
|
|
|
|
chaine += "\\hline "
|
|
|
|
chaine += "\\hline "
|
|
|
|
|
|
|
|
# Les ressources et les coeff
|
2021-04-09 08:13:12 +02:00
|
|
|
chaine += "\multicolumn{%d}{|l}{\\textcolor{ressourceC}{\\bfseries Ressources}}" % (nbre_colonnes) + "\n"
|
2021-04-07 11:51:19 +02:00
|
|
|
chaine += "\\\\ \n"
|
|
|
|
chaine += "\\hline "
|
|
|
|
|
|
|
|
for (i, r) in enumerate(ressem): # pour chaque SAE
|
2021-04-09 08:13:12 +02:00
|
|
|
chaine += "\\textcolor{ressourceC}{" + r.ressource["code"] + "} & | & " + "\n"
|
|
|
|
chaine += "\\begin{tabular}{p{5.7cm}}"
|
|
|
|
chaine += "\\tiny{" + r.ressource["nom"] + "} \\end{tabular} & \n"
|
2021-04-07 11:51:19 +02:00
|
|
|
chaine += str_volume(matrice_vols[i + nbre_saes][0]) + " & "
|
|
|
|
chaine += str_volume(matrice_vols[i + nbre_saes][1]) + " & "
|
|
|
|
chaine += " & "
|
|
|
|
chaine += " & ".join([str_coeff(matrice_coeffs[i + nbre_saes][j]) for j in range(len(comp))])
|
|
|
|
chaine += "\\\\ \n"
|
|
|
|
chaine += "\\hline "
|
|
|
|
|
|
|
|
# Total
|
|
|
|
total_heures = get_total_nbre_heures(matrice_vols)
|
|
|
|
# total_heures_sae = get_total_nbre_heures(matrice_vols[0:nbre_saes][:])
|
|
|
|
# total_heures_ressources = get_total_nbre_heures(matrice_vols[nbre_saes+1:][:])
|
|
|
|
total_coeffs = get_total_coeffs(matrice_coeffs)
|
|
|
|
|
|
|
|
chaine += "\\hline "
|
|
|
|
chaine += "\multicolumn{%d}{|l}{\\bfseries Total}" % (nbre_colonnes) + "\n"
|
|
|
|
chaine += "\\\\ \n"
|
|
|
|
chaine += "\\hline "
|
|
|
|
|
|
|
|
|
|
|
|
chaine += " & & "
|
|
|
|
for i in range(3):
|
2021-04-09 08:13:12 +02:00
|
|
|
chaine += " & {\\bfseries " + str(total_heures[i]) + "h}"
|
2021-04-07 11:51:19 +02:00
|
|
|
for i in range(3):
|
2021-04-09 08:13:12 +02:00
|
|
|
chaine += " & {\\bfseries " + str(total_coeffs[i]) + "}"
|
2021-04-07 11:51:19 +02:00
|
|
|
chaine += "\\\\ \\hline"
|
|
|
|
chaine += "\\end{tabular}"
|
|
|
|
return chaine
|
|
|
|
|
|
|
|
|
|
|
|
def get_total_nbre_heures(matrice_heures):
|
|
|
|
"""Calcul le nombre d'heures total des SAé d'après la matrice"""
|
|
|
|
sommes = [sum([matrice_heures[i][j] for i in range(len(matrice_heures)) if matrice_heures[i][j]]) for j in range(3)]
|
|
|
|
return sommes
|
|
|
|
|
|
|
|
def get_total_coeffs(matrice_coeffs):
|
|
|
|
sommes = [sum([matrice_coeffs[i][j] for i in range(len(matrice_coeffs)) if matrice_coeffs[i][j]]) for j in range(3)]
|
|
|
|
return sommes
|