diff --git a/notes_tools/generate_bilan/__main__.py b/notes_tools/generate_bilan/__main__.py index 1229675..61dc666 100644 --- a/notes_tools/generate_bilan/__main__.py +++ b/notes_tools/generate_bilan/__main__.py @@ -6,7 +6,7 @@ import logging # création de l'objet logger qui va nous servir à écrire dans les logs logger = logging.getLogger("generate_bilan") # on met le niveau du logger à DEBUG, comme ça il écrit tout -logger.setLevel(logging.WARNING) +logger.setLevel(logging.DEBUG) formatter = logging.Formatter('%(asctime)s :: %(name)s :: %(levelname)s :: %(message)s') steam_handler = logging.StreamHandler() steam_handler.setLevel(logging.DEBUG) diff --git a/notes_tools/generate_bilan/filters.py b/notes_tools/generate_bilan/filters.py index cbcb710..44fd7c1 100644 --- a/notes_tools/generate_bilan/filters.py +++ b/notes_tools/generate_bilan/filters.py @@ -3,8 +3,10 @@ from uuid import uuid4 from path import Path +import logging +logger = logging.getLogger("generate_bilan") -def includegraphic(fig_ax, path="./fig/", +def includegraphics(fig_ax, document_path="./", fig_path="fig/", prefix="", scale=1): """ Jinja2 filter which save the figure and return latex includegraphic to display it. @@ -25,10 +27,14 @@ def includegraphic(fig_ax, path="./fig/", filename = "{}_{}.pdf".format(prefix, str(uuid4())[:8]) else: filename = "{}.pdf".format(str(uuid4())[:8]) - path_to_file = Path(path) + + path_to_file = Path(document_path/fig_path) path_to_file.mkdir_p() + fig.savefig(path_to_file/filename) - return "\includegraphic[scale={sc}]{{{f}}}".format(sc = scale, f=path_to_file/filename) + logger.info("Graphique sauvé à {}".format(path_to_file)) + return "\includegraphics[scale={sc}]{{{f}}}".format(sc = scale, + f=Path(fig_path)/filename) # ----------------------------- diff --git a/notes_tools/generate_bilan/generate_bilan.py b/notes_tools/generate_bilan/generate_bilan.py index b4784e9..0eab10f 100755 --- a/notes_tools/generate_bilan/generate_bilan.py +++ b/notes_tools/generate_bilan/generate_bilan.py @@ -78,7 +78,7 @@ def build_target_name(classe, ds_name, path = Path("./")): >>> build_target_name("312", "DS1", Path("plop/")) Path('plop/312/bilan_DS1.tex') """ - return Path(path + classe + "/bilan_" + ds_name + ".tex") + return Path(path + "/" + classe + "/bilan_" + ds_name + ".tex") def feed_bilan(target, datas, template = "tpl_bilan.tex"): """ Get the template and feed it to create bilans @@ -94,7 +94,7 @@ def feed_bilan(target, datas, template = "tpl_bilan.tex"): path_to_target.mkdir() with open(target, "w") as f: - f.write(bilan.render(**datas)) + f.write(bilan.render(**datas, directory=path_to_target)) logger.info("{} est construit! Ya plus qu'à compiler!".format(target)) def generate_bilan(classe, ds_name, path = Path('./'), template = "tpl_bilan.tex"): @@ -120,7 +120,8 @@ def generate_bilan(classe, ds_name, path = Path('./'), template = "tpl_bilan.tex ds_info = build_ds_info(classe, eval_df) students_df = students_pov(quest_df, exo_df, eval_df) - datas = {"ds_info": ds_info, "students":students_df} + datas = {"ds_info": ds_info, "students":students_df, + "quest_df":quest_df, "exo_df":exo_df, "eval_df":eval_df} target = build_target_name(classe, ds_name, path) feed_bilan(target, datas, template) diff --git a/notes_tools/generate_bilan/templates/tpl_bilan.tex b/notes_tools/generate_bilan/templates/tpl_bilan.tex index ca21044..99f7986 100644 --- a/notes_tools/generate_bilan/templates/tpl_bilan.tex +++ b/notes_tools/generate_bilan/templates/tpl_bilan.tex @@ -1,7 +1,7 @@ \documentclass{/media/documents/Cours/Prof/Enseignements/2016-2017/tools/style/classBilan} \usepackage{/media/documents/Cours/Prof/Enseignements/2016-2017/theme} -\usepackage{multicol} +\usepackage{booktabs} % Title Page \titre{\Var{ds_info["Nom"]}} @@ -12,6 +12,14 @@ \begin{document} +Devoir sur \Var{eval_df["Bareme"].iloc[0]} + +\Var{eval_df.describe()[["Mark"]].T.to_latex()} + +\Var{eval_df["Mark"].hist() | includegraphics(document_path=directory, scale=0.5)} +\pagebreak + + %- for e in students \maketitle diff --git a/notes_tools/generate_bilan/texenv.py b/notes_tools/generate_bilan/texenv.py index e438963..dcb59b9 100644 --- a/notes_tools/generate_bilan/texenv.py +++ b/notes_tools/generate_bilan/texenv.py @@ -2,7 +2,7 @@ # encoding: utf-8 import jinja2, os -from .filters import includegraphic +from .filters import includegraphics __all__ = ["texenv"] @@ -25,9 +25,7 @@ texenv = jinja2.Environment( # Filters -texenv.filters['includegraphic'] = includegraphic - - +texenv.filters['includegraphics'] = includegraphics if __name__ == '__main__':