2021-03-30 07:59:21 +02:00
|
|
|
|
import logging, yaml
|
2021-03-30 08:11:38 +02:00
|
|
|
|
import unicodedata
|
2021-04-10 17:35:40 +02:00
|
|
|
|
from config import Config
|
2021-03-30 07:59:21 +02:00
|
|
|
|
|
|
|
|
|
__LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
2021-04-09 08:13:12 +02:00
|
|
|
|
# Récupère les informations officielles
|
|
|
|
|
## Les ressources
|
2021-04-10 17:35:40 +02:00
|
|
|
|
with open(Config.ROOT+"/python/pn/ressources.yml", 'r', encoding="utf8") as fid:
|
2021-03-30 07:59:21 +02:00
|
|
|
|
DATA_RESSOURCES = yaml.load(fid.read(), Loader=yaml.Loader)
|
2021-04-09 08:13:12 +02:00
|
|
|
|
## Les ACS
|
2021-04-10 17:35:40 +02:00
|
|
|
|
with open(Config.ROOT+"/python/pn/acs.yml", 'r', encoding="utf8") as fid:
|
2021-03-30 07:59:21 +02:00
|
|
|
|
DATA_ACS = yaml.load(fid.read(), Loader=yaml.Loader)
|
2021-04-09 08:13:12 +02:00
|
|
|
|
## Les SAEs
|
2021-04-10 17:35:40 +02:00
|
|
|
|
with open(Config.ROOT+"/python/pn/saes.yml", 'r', encoding="utf8") as fid:
|
2021-03-30 07:59:21 +02:00
|
|
|
|
DATA_SAES = yaml.load(fid.read(), Loader=yaml.Loader)
|
2021-04-09 08:13:12 +02:00
|
|
|
|
## Les compétences
|
2021-04-10 17:35:40 +02:00
|
|
|
|
with open(Config.ROOT+"/yaml/competences/RT123.yml", 'r', encoding="utf8") as fid:
|
2021-04-07 11:51:19 +02:00
|
|
|
|
DATA_COMPETENCES = yaml.load(fid.read(), Loader=yaml.Loader)
|
2021-04-15 19:16:48 +02:00
|
|
|
|
## Les abréviations
|
2021-04-10 17:35:40 +02:00
|
|
|
|
with open(Config.ROOT+"/yaml/abbreviations.yml", "r", encoding="utf8") as fid:
|
2021-04-09 08:13:12 +02:00
|
|
|
|
DATA_ABBREVIATIONS = yaml.load(fid.read(), Loader=yaml.Loader)
|
2021-04-15 19:16:48 +02:00
|
|
|
|
## Les mostcles (commandes, logiciels, etc...)
|
|
|
|
|
with open(Config.ROOT+"/yaml/motscles.yml", "r", encoding="utf8") as fid:
|
|
|
|
|
DATA_MOTSCLES = yaml.load(fid.read(), Loader=yaml.Loader)
|
2021-03-30 08:11:38 +02:00
|
|
|
|
|
2021-04-12 11:32:09 +02:00
|
|
|
|
AUCUN_PREREQUIS = "Aucun"
|
|
|
|
|
|
2021-03-30 08:11:38 +02:00
|
|
|
|
def supprime_accent_espace(chaine):
|
|
|
|
|
"""Met en minuscule, supprime les accents, les ponctuations et les espaces"""
|
|
|
|
|
purge = chaine.lower().replace("'", "").replace("’", "")
|
|
|
|
|
purge = unicodedata.normalize('NFD', purge).encode('ascii', 'ignore').decode('ascii')
|
|
|
|
|
purge = purge.replace(" ", "")
|
|
|
|
|
return purge
|
|
|
|
|
|
|
|
|
|
def devine_code_by_nom_from_dict(champ, dico):
|
|
|
|
|
"""Partant d'une chaine de caractères décrivant une ressource, une SAé ou un ACS,
|
|
|
|
|
détermine le code présent dans le dico officiel (dico à double entrée),
|
|
|
|
|
Le dico officiel vient d'un .yml"""
|
|
|
|
|
acs = []
|
|
|
|
|
champ_purge = supprime_accent_espace(champ)
|
|
|
|
|
|
|
|
|
|
for comp in DATA_ACS:
|
|
|
|
|
for code in DATA_ACS[comp]:
|
|
|
|
|
acs_purge = supprime_accent_espace(DATA_ACS[comp][code])
|
|
|
|
|
if acs_purge in champ_purge:
|
|
|
|
|
acs += [code]
|
|
|
|
|
return sorted(list(set(acs)))
|
|
|
|
|
|
|
|
|
|
|
2021-03-30 09:22:21 +02:00
|
|
|
|
def affiche_bilan_heures(ressources, sem):
|
|
|
|
|
"""Renvoie une chaine décrivant un bilan des heures pour un sem donné"""
|
|
|
|
|
ligne = "{:20s} | {:75s} | {:10s} | {:10s} |"
|
|
|
|
|
trait = "-"*len(ligne.format("", "", "", ""))
|
|
|
|
|
|
|
|
|
|
ressem = ressources[sem] # les ressources du semestre
|
|
|
|
|
chaine = ""
|
|
|
|
|
chaine += trait + "\n"
|
|
|
|
|
chaine += ligne.format("Code", "Ressource", "Form.", "dont TP") + "\n"
|
|
|
|
|
chaine += trait + "\n"
|
|
|
|
|
for r in ressem:
|
|
|
|
|
chaine += ligne.format(r.code if r.code else "MANQUANT",
|
|
|
|
|
# r.nom[:30] + ("..." if len(r.nom) > 30 else "") ,
|
|
|
|
|
r.nom,
|
|
|
|
|
str(r.heures_encadrees) if r.heures_encadrees else "MANQUANT",
|
|
|
|
|
str(r.tp) if r.tp else "MANQUANT") + "\n"
|
|
|
|
|
heures_formation_total = sum([r.heures_encadrees for r in ressem if r.heures_encadrees != None])
|
|
|
|
|
heures_tp_total = sum([r.tp for r in ressem if r.tp != None])
|
|
|
|
|
chaine += trait + "\n"
|
|
|
|
|
chaine += ligne.format("", "Total", str(heures_formation_total), str(heures_tp_total)) + "\n"
|
|
|
|
|
chaine += trait + "\n"
|
|
|
|
|
return chaine
|
2021-03-30 12:14:27 +02:00
|
|
|
|
|
2021-04-02 14:59:08 +02:00
|
|
|
|
def get_officiel_name_by_code_using_dict(code, dico):
|
|
|
|
|
"""Extrait un nom à partir d'un code (pour les RESSOURCES ou les SAES)"""
|
|
|
|
|
for sem in dico:
|
|
|
|
|
for rcode in dico[sem]:
|
|
|
|
|
if rcode==code:
|
|
|
|
|
return dico[sem][code]
|
2021-03-30 12:14:27 +02:00
|
|
|
|
|
|
|
|
|
def get_officiel_ressource_name_by_code(code):
|
2021-03-30 12:34:59 +02:00
|
|
|
|
"""Pour un code valide, fournit le nom officiel de la ressource (sans connaissance du semestre)"""
|
2021-04-02 14:59:08 +02:00
|
|
|
|
return get_officiel_name_by_code_using_dict(code, DATA_RESSOURCES)
|
2021-03-30 12:34:59 +02:00
|
|
|
|
|
|
|
|
|
def get_officiel_sae_name_by_code(code):
|
|
|
|
|
"""Pour un code valide, fournit le nom officiel de la sae (sans connaissance du semestre)"""
|
2021-04-02 14:59:08 +02:00
|
|
|
|
return get_officiel_name_by_code_using_dict(code, DATA_SAES)
|
2021-03-31 10:34:56 +02:00
|
|
|
|
|
|
|
|
|
|
2021-04-03 09:53:25 +02:00
|
|
|
|
|
2021-04-04 11:15:59 +02:00
|
|
|
|
def get_code_from_nom_using_dict(nom, dico):
|
2021-03-31 10:34:56 +02:00
|
|
|
|
"""Récupère le code d'une ressource d'après son nom en utilisant les noms officiels
|
2021-04-02 14:59:08 +02:00
|
|
|
|
des ressources du yaml si dico == DATA_RESSOURCES ; sinon fait de même avec les SAE"""
|
2021-04-04 11:15:59 +02:00
|
|
|
|
nom = supprime_accent_espace(nom)
|
2021-04-02 14:59:08 +02:00
|
|
|
|
for sem in dico:
|
|
|
|
|
for code in dico[sem]:
|
|
|
|
|
nom_data = supprime_accent_espace(dico[sem][code])
|
2021-03-31 10:34:56 +02:00
|
|
|
|
if nom.startswith(nom_data):
|
2021-04-03 09:53:25 +02:00
|
|
|
|
return code
|
|
|
|
|
|
|
|
|
|
def get_officiel_sem_sae_by_code(sae):
|
|
|
|
|
"""Récupère le semestre de la SAE d'après son code"""
|
|
|
|
|
for sem in DATA_SAES:
|
|
|
|
|
if sae in DATA_SAES[sem]:
|
2021-04-07 11:51:19 +02:00
|
|
|
|
return sem
|
|
|
|
|
|
|
|
|
|
if __name__=="__main__":
|
|
|
|
|
print(DATA_COMPETENCES)
|