Start splitting eval_bilan and term bilan

This commit is contained in:
Benjamin Bertrand 2016-11-26 17:34:32 +03:00
parent 34546914e5
commit 8340a58cc8
3 changed files with 230 additions and 15 deletions

View File

@ -14,17 +14,12 @@ steam_handler.setFormatter(formatter)
logger.addHandler(steam_handler) logger.addHandler(steam_handler)
from .generate_bilan import generate_bilan
import optparse import optparse
import os import os
from path import Path from path import Path
import sys import sys
# Defaults settings
default_template = "tpl_bilan.tex"
def main(): def main():
parser = optparse.OptionParser() parser = optparse.OptionParser()
parser.add_option("-c", parser.add_option("-c",
@ -37,8 +32,14 @@ def main():
"--evaluation", "--evaluation",
action="store", action="store",
type="string", type="string",
dest="ds_name", dest="eval",
help="The evaluation name.") help="The evaluation name.")
parser.add_option("-t",
"--term",
action="store",
type="int",
dest="term",
help="The term number.")
parser.add_option("-p", parser.add_option("-p",
"--path", "--path",
action="store", action="store",
@ -46,12 +47,11 @@ def main():
dest="path", dest="path",
default=Path("./"), default=Path("./"),
help="Path where xlsx are stored") help="Path where xlsx are stored")
parser.add_option("-t", parser.add_option("-T",
"--template", "--template",
action="store", action="store",
type="string", type="string",
dest="template", dest="template",
default=default_template,
help="The template file") help="The template file")
parser.add_option("-d", parser.add_option("-d",
"--debug", "--debug",
@ -64,17 +64,41 @@ def main():
if not options.classe: if not options.classe:
logger.error("Need to pass a class with -c. See -h for help") logger.error("Need to pass a class with -c. See -h for help")
sys.exit() sys.exit()
if not options.ds_name:
logger.error("Need to pass a evaluation name with -e. See -h for help")
sys.exit()
if options.debug_level: if options.debug_level:
logger.setLevel(logging.DEBUG) logger.setLevel(logging.DEBUG)
if options.term:
logger.info("Creating term {} bilan".format(options.term))
from .term_bilan import term_bilan
if options.template:
logger.info("Not default template: {}".format(options.template))
template = options.template
else:
template = "tpl_bilan_term.tex"
generate_bilan(options.classe, term_bilan(options.classe,
options.ds_name, options.term,
options.path, options.path,
options.template) template)
elif options.eval:
logger.info("Creating {} bilan".format(options.eval))
from .eval_bilan import eval_bilan
if options.template:
logger.info("Not default template: {}".format(options.template))
template = options.template
else:
template = "tpl_bilan_eval.tex"
eval_bilan(options.classe,
options.eval,
options.path,
template)
else:
logger.error("Need to pass a evaluation name with -e or the term number with -t. See -h for help")
sys.exit()
logger.info("À fini") logger.info("À fini")

View File

@ -0,0 +1,90 @@
#!/usr/bin/env python
# encoding: utf-8
from notes_tools.tools import extract_flat_marks, get_class_ws, digest_flat_df, students_pov, select_eval
from .texenv import texenv
import pandas as pd
import numpy as np
import xlrd
from path import Path
import logging
logger = logging.getLogger("generate_bilan")
def eval_info(classe, ds_df):
"""TODO: Docstring for build_ds_info.
:param ds_df: TODO
:returns: TODO
# TODO: vérifier que toutes ces informations soient identiques sur les lignes |dim. nov. 6 16:06:58 EAT 2016
"""
eval_info = {}
eval_info["Classe"] = classe
eval_info["Nom"] = ds_df["Nom"].unique()[0]
eval_info["Date"] = pd.to_datetime(ds_df["Date"].unique()[0]).strftime("%d-%m-%Y")
eval_info["Trimestre"] = ds_df["Trimestre"].unique()[0]
return eval_info
def build_target_name(classe, evalname, path = Path("./")):
""" Build the path where the .tex will be sored
>>> build_target_name("312", "DS1")
Path('./312/bilan_DS1.tex')
>>> build_target_name("312", "DS1", Path("plop/"))
Path('plop/312/bilan_DS1.tex')
"""
return Path(path + "/" + classe + "/bilan_" + evalname + ".tex")
def eval_bilan(classe, evalname, path = Path('./'), template = "tpl_bilan_eval.tex"):
""" Generate the bilan of a evaluation for a class
:param classe: the classe name
:param evalname: name of the evaluation
:param path: path where xlsx are stored
:param template: template for the bilan
"""
ws = get_class_ws(classe, path)
logger.info("Worksheets of {} imported".format(classe))
flat_df = extract_flat_marks(ws)
quest_df, exo_df, eval_df = digest_flat_df(flat_df)
logger.info("Worksheets parsed")
quest_df, exo_df, eval_df = select_eval(quest_df, exo_df, eval_df, evalname)
bilan_info = eval_info(classe, eval_df)
students = students_pov(quest_df, exo_df, eval_df)
datas = {"bilan_info": bilan_info, "students":students,
"quest_df":quest_df, "exo_df":exo_df, "eval_df":eval_df}
target = build_target_name(classe, evalname, path)
feed_bilan(target, datas, template)
def feed_bilan(target, datas, template):
""" Get the template and feed it to create bilans
:param target: path where the bilan will be saved
:param datas: dictonnary to feed the template
:param template: the template
"""
logger.info("Getting template {}".format(template))
bilan = texenv.get_template(template)
path_to_target = target.dirname()
if not path_to_target.exists():
path_to_target.mkdir()
with open(target, "w") as f:
f.write(bilan.render(**datas, directory=path_to_target))
logger.info("{} est construit! Ya plus qu'à compiler!".format(target))
# -----------------------------
# Reglages pour 'vim'
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
# cursor: 16 del

View File

@ -0,0 +1,101 @@
\documentclass{/media/documents/Cours/Prof/Enseignements/2016-2017/tools/style/classBilan}
\usepackage{/media/documents/Cours/Prof/Enseignements/2016-2017/theme}
\usepackage{booktabs}
% Title Page
\titre{\Var{bilan_info["Nom"]}}
% \seconde \premiereS \PSTMG \TSTMG
\classe{\Var{bilan_info["Classe"]}}
\date{\Var{bilan_info["Date"]}}
\begin{document}
\maketitle
Devoir sur \Var{eval_df["Bareme"].iloc[0]}
\vfill
\Var{eval_df.describe()[["Mark"]].T.to_latex()}
\vfill
\Var{eval_df| marks_hist | includegraphics(document_path=directory, scale=0.5)}
\pagebreak
%- for e in students
\maketitle
\begin{minipage}{0.5\linewidth}
\large
\Var{e["Nom"]}
\end{minipage}
\begin{minipage}{0.3\linewidth}
\begin{flushright}
\Large \Var{e["Total"]["Mark"]} / \Var{e["Total"]["Bareme"]}
\end{flushright}
\end{minipage}
\vfill
\fbox{%
\begin{minipage}{0.5\linewidth}
\hfill
\vspace{3cm}
\end{minipage}
}
\Var{e["quest"] | comp_radar | includegraphics(document_path=directory, scale=0.5)}
\vfill
\scriptsize
\begin{multicols}{3}
%- for exo in e["Exercices"]
\begin{tabular}{|p{2cm}|c|}
%- if exo["Nom"] in ["Bonus", "Malus", "Presentation"]
%- for _,q in exo["Questions"].iterrows()
%- if q["Mark"]
\hline
\rowcolor{highlightbg}
\Var{exo["Nom"]} (\Var{q["Question"]}) & \Var{q["Latex_rep"]} \\
%- endif
%- endfor
%- else
\hline
\rowcolor{highlightbg}
Exerice \Var{exo["Nom"]} & \Var{exo["Total"]["Mark"]} / \Var{exo["Total"]["Bareme"]} \\
%- for _,q in exo["Questions"].iterrows()
\hline
\Var{q["Question"]} \newline \Var{q["Commentaire"]} & \Var{q["Latex_rep"]} \\
%- endfor
%- endif
\hline
\end{tabular}
%- endfor
\end{multicols}
\vfill
\begin{center}
Pas de réponse \NoRep \hfill
Tout faux \RepZ \hfill
Beaucoup d'erreurs \RepU \hfill
Quelques erreurs \RepD \hfill
Juste \RepT \hfill
\end{center}
\normalsize
\pagebreak
%- endfor
\end{document}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: "master"
%%% End: