change bilan to report
This commit is contained in:
10
notes_tools/reports/__init__.py
Normal file
10
notes_tools/reports/__init__.py
Normal file
@@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
#from .generate_bilan import generate_bilan
|
||||
from .texenv import texenv
|
||||
|
||||
# -----------------------------
|
||||
# Reglages pour 'vim'
|
||||
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
||||
# cursor: 16 del
|
||||
72
notes_tools/reports/eval_reports.py
Executable file
72
notes_tools/reports/eval_reports.py
Executable file
@@ -0,0 +1,72 @@
|
||||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
from notes_tools.tools import extract_flat_marks, get_class_ws, digest_flat_df, eval_tools #students_pov, select_eval
|
||||
from .texenv import feed_template
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
import xlrd
|
||||
from path import Path
|
||||
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
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/report_DS1.tex')
|
||||
>>> build_target_name("312", "DS1", Path("plop/"))
|
||||
Path('plop/312/report_DS1.tex')
|
||||
"""
|
||||
return Path(path + "/" + classe + "/report_" + evalname + ".tex")
|
||||
|
||||
|
||||
def eval_report(classe, evalname, path = Path('./'), template = "tpl_reports_eval.tex"):
|
||||
""" Generate the report 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 report
|
||||
|
||||
"""
|
||||
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 = eval_tools.select(quest_df, exo_df, eval_df, evalname)
|
||||
|
||||
report_info = eval_info(classe, eval_df)
|
||||
students = eval_tools.students_pov(quest_df, exo_df, eval_df)
|
||||
|
||||
datas = {"report_info": report_info, "students":students,
|
||||
"quest_df":quest_df, "exo_df":exo_df, "eval_df":eval_df}
|
||||
|
||||
target = build_target_name(classe, evalname, path)
|
||||
feed_template(target, datas, template)
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# Reglages pour 'vim'
|
||||
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
||||
# cursor: 16 del
|
||||
43
notes_tools/reports/filters.py
Normal file
43
notes_tools/reports/filters.py
Normal file
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
from uuid import uuid4
|
||||
from path import Path
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
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.
|
||||
|
||||
:param fig_ax: TODO
|
||||
:param path: TODO
|
||||
:param prefix: TODO
|
||||
:param scale: TODO
|
||||
:returns: TODO
|
||||
|
||||
"""
|
||||
try:
|
||||
fig, ax = fig_ax
|
||||
except TypeError:
|
||||
ax = fig_ax
|
||||
fig = ax.figure
|
||||
|
||||
if prefix:
|
||||
filename = "{}_{}.pdf".format(prefix, str(uuid4())[:8])
|
||||
else:
|
||||
filename = "{}.pdf".format(str(uuid4())[:8])
|
||||
|
||||
path_to_file = Path(document_path/fig_path)
|
||||
path_to_file.mkdir_p()
|
||||
|
||||
fig.savefig(path_to_file/filename)
|
||||
logger.info("Graphique {} sauvé à {}".format(filename, path_to_file))
|
||||
return "\includegraphics[scale={sc}]{{{f}}}".format(sc = scale,
|
||||
f=Path(fig_path)/filename)
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# Reglages pour 'vim'
|
||||
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
||||
# cursor: 16 del
|
||||
50
notes_tools/reports/reports_tools.py
Executable file
50
notes_tools/reports/reports_tools.py
Executable file
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
from notes_tools.tools import extract_flat_marks, get_class_ws, list_classes
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
import xlrd
|
||||
from path import Path
|
||||
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def print_report_of(classe_ws):
|
||||
"""TODO: Docstring for list_report.
|
||||
|
||||
:param arg1: TODO
|
||||
:returns: TODO
|
||||
|
||||
"""
|
||||
try:
|
||||
df = extract_flat_marks(classe_ws)
|
||||
# TODO: il faudrait renommer l'exeption |lun. nov. 28 16:17:21 EAT 2016
|
||||
except ValueError:
|
||||
print("Erreur avec cette feuille de calcul")
|
||||
return None
|
||||
print("Évaluations")
|
||||
for e in df["Nom"].unique():
|
||||
print("\t-{}".format(e))
|
||||
print("Trimestre")
|
||||
for t in df['Trimestre'].unique():
|
||||
print("\t-Trimestre {}".format(t))
|
||||
|
||||
def print_reports(path):
|
||||
""" List all report which can be generate in the directory
|
||||
|
||||
:param path: the directory
|
||||
:returns: TODO
|
||||
|
||||
"""
|
||||
print("Liste des bilans disponibles")
|
||||
for c in list_classes(path):
|
||||
print("Classe de {}".format(c))
|
||||
ws = get_class_ws(c, path)
|
||||
print_report_of(ws)
|
||||
|
||||
# -----------------------------
|
||||
# Reglages pour 'vim'
|
||||
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
||||
# cursor: 16 del
|
||||
28
notes_tools/reports/templates/tpl_reports.tex
Normal file
28
notes_tools/reports/templates/tpl_reports.tex
Normal file
@@ -0,0 +1,28 @@
|
||||
\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{report_info["Nom"]}}
|
||||
% \seconde \premiereS \PSTMG \TSTMG
|
||||
\classe{\Var{report_info["Classe"]}}
|
||||
\date{\Var{report_info["Date"]}}
|
||||
|
||||
|
||||
\begin{document}
|
||||
|
||||
\Block{block classPOV}\Block{endblock}
|
||||
|
||||
\pagebreak
|
||||
|
||||
|
||||
\Block{block students}\Block{endblock}
|
||||
|
||||
\end{document}
|
||||
|
||||
%%% Local Variables:
|
||||
%%% mode: latex
|
||||
%%% TeX-master: "master"
|
||||
%%% End:
|
||||
|
||||
93
notes_tools/reports/templates/tpl_reports_eval.tex
Normal file
93
notes_tools/reports/templates/tpl_reports_eval.tex
Normal file
@@ -0,0 +1,93 @@
|
||||
%- extends "tpl_reports.tex"
|
||||
|
||||
% FILENAME: "tpl_reports_eval.tex
|
||||
|
||||
%- block classPOV
|
||||
\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)}
|
||||
%- endblock
|
||||
|
||||
|
||||
%-block students
|
||||
%- 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
|
||||
|
||||
\begin{minipage}{0.6\linewidth}
|
||||
\fbox{%
|
||||
\begin{minipage}{0.9\linewidth}
|
||||
\hfill
|
||||
\vspace{2cm}
|
||||
\end{minipage}
|
||||
}
|
||||
\end{minipage}
|
||||
\begin{minipage}{0.4\linewidth}
|
||||
\Var{e["quest"] | radar_on("Competence") | includegraphics(document_path=directory, scale=0.4)}
|
||||
\end{minipage}
|
||||
|
||||
\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
|
||||
%- endblock
|
||||
|
||||
|
||||
34
notes_tools/reports/templates/tpl_reports_term.tex
Normal file
34
notes_tools/reports/templates/tpl_reports_term.tex
Normal file
@@ -0,0 +1,34 @@
|
||||
%- extends "tpl_reports.tex"
|
||||
% FILENAME: "tpl_reports_term.tex
|
||||
|
||||
%- block classPOV
|
||||
%- endblock
|
||||
|
||||
%-block students
|
||||
%- for e in students
|
||||
\maketitle
|
||||
|
||||
{\Large \Var{e["Nom"]}}
|
||||
|
||||
\vfill
|
||||
|
||||
\Var{e["eval"].groupby("Nom").sum()[["Mark","Bareme"]].T.to_latex()}
|
||||
|
||||
\vfill
|
||||
\Var{e["quest"] | radar_on("Competence") | includegraphics(document_path=directory, scale=0.6)}
|
||||
\Var{e["quest"] | radar_on("Domaine") | includegraphics(document_path=directory, scale=0.6)}
|
||||
|
||||
\vfill
|
||||
%#\Var{conn_df}
|
||||
%- if not conn_df.empty
|
||||
\Var{conn_df | parallele_on("Exercice", e["Nom"]) | includegraphics(document_path=directory, scale=0.5)}
|
||||
%- endif
|
||||
|
||||
\vfill
|
||||
\vfill
|
||||
|
||||
\normalsize
|
||||
\pagebreak
|
||||
%- endfor
|
||||
%- endblock
|
||||
|
||||
73
notes_tools/reports/term_reports.py
Executable file
73
notes_tools/reports/term_reports.py
Executable file
@@ -0,0 +1,73 @@
|
||||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
from notes_tools.tools import extract_flat_marks, get_class_ws, digest_flat_df, term_tools
|
||||
from .texenv import feed_template
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
import xlrd
|
||||
from path import Path
|
||||
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def term_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["Trimestre"] = ds_df["Trimestre"].unique()[0]
|
||||
return eval_info
|
||||
|
||||
def build_target_name(classe, term, path = Path("./")):
|
||||
""" Build the path where the .tex will be sored
|
||||
|
||||
>>> build_target_name("312", "DS1")
|
||||
Path('./312/report_DS1.tex')
|
||||
>>> build_target_name("312", "DS1", Path("plop/"))
|
||||
Path('plop/312/report_DS1.tex')
|
||||
"""
|
||||
return Path(path + "/{cls}/report_T{term}.tex".format(cls=classe, term=term))
|
||||
|
||||
def term_report(classe, term, path = Path('./'),
|
||||
template = "tpl_reports_term.tex"):
|
||||
""" Generate the report 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 report
|
||||
|
||||
"""
|
||||
ws = get_class_ws(classe, path)
|
||||
logger.info("Worksheets of {} imported".format(classe))
|
||||
|
||||
flat_df = extract_flat_marks(ws)
|
||||
logger.info("Worksheets parsed")
|
||||
|
||||
term_df = flat_df[flat_df['Trimestre'] == term]
|
||||
|
||||
quest_df, exo_df, eval_df = digest_flat_df(term_df)
|
||||
conn_df = exo_df[exo_df["Nom"].str.contains('Conn')]
|
||||
|
||||
report_info = term_info(classe, eval_df)
|
||||
students = term_tools.students_pov(quest_df, exo_df, eval_df)
|
||||
|
||||
datas = {"report_info": report_info, "students":students,
|
||||
"quest_df":quest_df, "exo_df":exo_df, "eval_df":eval_df,
|
||||
"conn_df": conn_df}
|
||||
|
||||
target = build_target_name(classe, term, path)
|
||||
feed_template(target, datas, template)
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# Reglages pour 'vim'
|
||||
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
||||
# cursor: 16 del
|
||||
66
notes_tools/reports/texenv.py
Normal file
66
notes_tools/reports/texenv.py
Normal file
@@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
import jinja2, os
|
||||
from .filters import includegraphics
|
||||
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
__all__ = ["texenv"]
|
||||
|
||||
# Definition of jinja syntax for latex
|
||||
texenv = jinja2.Environment(
|
||||
block_start_string = '\Block{',
|
||||
# Gros WTF!! Si on le met en maj ça ne marche pas alors que c'est en maj dans le template...
|
||||
block_end_string = '}',
|
||||
variable_start_string = '\Var{',
|
||||
variable_end_string = '}',
|
||||
comment_start_string = '\#{',
|
||||
comment_end_string = '}',
|
||||
line_statement_prefix = '%-',
|
||||
line_comment_prefix = '%#',
|
||||
loader = jinja2.ChoiceLoader([jinja2.PackageLoader("notes_tools.reports", "templates"),
|
||||
jinja2.FileSystemLoader(['./']),
|
||||
]),
|
||||
extensions = ['jinja2.ext.do']
|
||||
)
|
||||
|
||||
# Filters
|
||||
|
||||
from .filters import includegraphics
|
||||
texenv.filters['includegraphics'] = includegraphics
|
||||
|
||||
from notes_tools.tools.marks_plottings import radar_on, marks_hist, parallele_on
|
||||
texenv.filters['radar_on'] = radar_on
|
||||
texenv.filters['marks_hist'] = marks_hist
|
||||
texenv.filters['parallele_on'] = parallele_on
|
||||
|
||||
def feed_template(target, datas, template):
|
||||
""" Get the template and feed it to create reports
|
||||
|
||||
:param target: path where the report will be saved
|
||||
:param datas: dictonnary to feed the template
|
||||
:param template: the template
|
||||
"""
|
||||
logger.info("Getting template {}".format(template))
|
||||
report = 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(report.render(**datas, directory=path_to_target))
|
||||
logger.info("{} est construit! Ya plus qu'à compiler!".format(target))
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(texenv.list_templates())
|
||||
texenv.get_template("tpl_reports.tex")
|
||||
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# Reglages pour 'vim'
|
||||
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
||||
# cursor: 16 del
|
||||
Reference in New Issue
Block a user