basic and brutal way to import pictures

This commit is contained in:
Benjamin Bertrand 2016-11-25 23:57:49 +03:00
parent 4930a746b4
commit acc338367e
5 changed files with 25 additions and 12 deletions

View File

@ -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)

View File

@ -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)
# -----------------------------

View File

@ -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)

View File

@ -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

View File

@ -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__':