ScoDoc/app/pe/pe_affichage.py

107 lines
2.7 KiB
Python
Raw Normal View History

2024-02-08 22:09:11 +01:00
##############################################################################
# Module "Avis de poursuite d'étude"
# conçu et développé par Cléo Baras (IUT de Grenoble)
##############################################################################
"""Affichages, debug
"""
from flask import g
from app import log
2024-02-26 12:03:19 +01:00
PE_DEBUG = False
# On stocke les logs PE dans g.scodoc_pe_log
# pour ne pas modifier les nombreux appels à pe_print.
def pe_start_log() -> list[str]:
"Initialize log"
g.scodoc_pe_log = []
return g.scodoc_pe_log
def pe_print(*a):
"Log (or print in PE_DEBUG mode) and store in g"
if PE_DEBUG:
msg = " ".join(a)
print(msg)
else:
lines = getattr(g, "scodoc_pe_log")
if lines is None:
lines = pe_start_log()
msg = " ".join(a)
lines.append(msg)
log(msg)
def pe_get_log() -> str:
"Renvoie une chaîne avec tous les messages loggués"
return "\n".join(getattr(g, "scodoc_pe_log", []))
2024-01-25 17:17:01 +01:00
# Affichage dans le tableur pe en cas d'absence de notes
SANS_NOTE = "-"
def aff_profil_coeffs(matrice_coeffs_moy_gen, with_index=False):
"""Affiche les différents types de coefficients (appelés profil)
d'une matrice_coeffs_moy_gen (pour debug)
"""
# Les profils des coeffs d'UE (pour debug)
profils = []
index_a_profils = {}
for i in matrice_coeffs_moy_gen.index:
val = matrice_coeffs_moy_gen.loc[i].fillna("-")
val = " | ".join([str(v) for v in val])
if val not in profils:
profils += [val]
index_a_profils[val] = [str(i)]
else:
index_a_profils[val] += [str(i)]
# L'affichage
if len(profils) > 1:
if with_index:
elmts = [
" " * 10
+ prof
+ " (par ex. "
+ ", ".join(index_a_profils[prof][:10])
+ ")"
for prof in profils
]
else:
elmts = [" " * 10 + prof for prof in profils]
profils_aff = "\n" + "\n".join(elmts)
else:
profils_aff = "\n".join(profils)
2024-02-26 12:03:19 +01:00
return profils_aff
def aff_UEs(champs):
"""Affiche les UEs"""
champs_tries = sorted(champs)
aff_comp = []
for comp in champs_tries:
aff_comp += ["📍" + comp]
return ", ".join(aff_comp)
def aff_competences(champs):
"""Affiche les compétences"""
champs_tries = sorted(champs)
aff_comp = []
for comp in champs_tries:
aff_comp += ["💡" + comp]
return ", ".join(aff_comp)
def aff_tag(tags):
"""Affiche les tags"""
tags_tries = sorted(tags)
aff_tag = ["👜" + tag for tag in tags_tries]
return ", ".join(aff_tag)