reorga files
This commit is contained in:
10
notes_tools/generate_bilan/__init__.py
Normal file
10
notes_tools/generate_bilan/__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
|
||||
59
notes_tools/generate_bilan/__main__.py
Normal file
59
notes_tools/generate_bilan/__main__.py
Normal file
@@ -0,0 +1,59 @@
|
||||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
from .generate_bilan import generate_bilan
|
||||
import optparse
|
||||
import os
|
||||
from path import Path
|
||||
|
||||
# Defaults settings
|
||||
default_template = "tpl_bilan.tex"
|
||||
|
||||
|
||||
def main():
|
||||
parser = optparse.OptionParser()
|
||||
parser.add_option("-c",
|
||||
"--classe",
|
||||
action="store",
|
||||
type="string",
|
||||
dest="classe",
|
||||
help="The classe")
|
||||
parser.add_option("-e",
|
||||
"--evaluation",
|
||||
action="store",
|
||||
type="string",
|
||||
dest="ds_name",
|
||||
help="The evaluation name.")
|
||||
parser.add_option("-p",
|
||||
"--path",
|
||||
action="store",
|
||||
type="string",
|
||||
dest="path",
|
||||
default=Path("./"),
|
||||
help="Path where xlsx are stored")
|
||||
parser.add_option("-t",
|
||||
"--template",
|
||||
action="store",
|
||||
type="string",
|
||||
dest="template",
|
||||
default=default_template,
|
||||
help="The template file")
|
||||
(options, args) = parser.parse_args()
|
||||
|
||||
if not options.classe:
|
||||
raise ValueError("Need to pass a class with -c. See -h for help")
|
||||
if not options.ds_name:
|
||||
raise ValueError("Need to pass a evaluation name with -e. See -h for help")
|
||||
|
||||
generate_bilan(options.classe,
|
||||
options.ds_name,
|
||||
options.path,
|
||||
options.template)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
# -----------------------------
|
||||
# Reglages pour 'vim'
|
||||
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
||||
# cursor: 16 del
|
||||
128
notes_tools/generate_bilan/generate_bilan.py
Executable file
128
notes_tools/generate_bilan/generate_bilan.py
Executable file
@@ -0,0 +1,128 @@
|
||||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
from notes_tools.tools import extract_flat_marks, get_class_ws, digest_flat_df, students_pov
|
||||
from .texenv import texenv
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
import xlrd
|
||||
from path import Path
|
||||
|
||||
notStudent = ["Trimestre", "Nom", "Date", "Exercice", "Question", "Competence", "Domaine", "Commentaire", "Bareme", "Niveau"]
|
||||
|
||||
def extract_students(df, notStudent = notStudent):
|
||||
""" Extract the list of students from df """
|
||||
students = df.columns.difference(notStudent)
|
||||
return students
|
||||
|
||||
def build_students(df1, df2, notStudent = notStudent):
|
||||
""" Build students list """
|
||||
students_from_notes = extract_students(df1, notStudent)
|
||||
students_from_conn = extract_students(df2, notStudent)
|
||||
if students_from_conn.equals(students_from_notes):
|
||||
return students_from_conn
|
||||
else:
|
||||
raise ValueError("Not same list of students between df1 = {} ans df2 = {}".format(df1, df2))
|
||||
|
||||
def flat_df_students(df, students):
|
||||
""" Flat the ws for students """
|
||||
flat_df = pd.DataFrame()
|
||||
flat_data = []
|
||||
dfT = df.T
|
||||
for n in dfT:
|
||||
pre_di = dfT[n][notStudent].to_dict()
|
||||
for e in students:
|
||||
data = pre_di.copy()
|
||||
data["Eleve"] = e
|
||||
data["Note"] = dfT[n].loc[e]
|
||||
flat_data.append(data)
|
||||
return pd.DataFrame.from_dict(flat_data)
|
||||
|
||||
def select_ds(ds_name, flat_df):
|
||||
"""TODO: Docstring for select_ds.
|
||||
|
||||
:param ds_name: TODO
|
||||
:param flat_df: TODO
|
||||
:returns: TODO
|
||||
|
||||
"""
|
||||
ds = flat_df[flat_df["Nom"] == ds_name]
|
||||
if len(ds) == 0:
|
||||
raise ValueError("{} is not a registered evaluation".format(ds_name))
|
||||
return ds
|
||||
|
||||
def build_ds_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
|
||||
"""
|
||||
ds_info = {}
|
||||
ds_info["Classe"] = classe
|
||||
ds_info["Nom"] = ds_df["Nom"].unique()[0]
|
||||
ds_info["Date"] = pd.to_datetime(ds_df["Date"].unique()[0]).strftime("%d-%m-%Y")
|
||||
ds_info["Trimestre"] = ds_df["Trimestre"].unique()[0]
|
||||
return ds_info
|
||||
|
||||
def build_target_name(classe, ds_name, 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_" + ds_name + ".tex")
|
||||
|
||||
def feed_bilan(target, datas, template = "tpl_bilan.tex"):
|
||||
""" 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
|
||||
"""
|
||||
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))
|
||||
print("{} est construit! Ya plus qu'à compiler!".format(target))
|
||||
|
||||
def generate_bilan(classe, ds_name, path = Path('./'), template = "tpl_bilan.tex"):
|
||||
""" Generate the bilan of a evaluation for a class
|
||||
|
||||
:param classe: the classe name
|
||||
:param ds_name: name of the evaluation
|
||||
:param path: path where xlsx are stored
|
||||
:param template: template for the bilan
|
||||
|
||||
"""
|
||||
ws = get_class_ws(classe, path)
|
||||
|
||||
flat_df = extract_flat_marks(ws)
|
||||
quest_df, exo_df, eval_df = digest_flat_df(flat_df)
|
||||
|
||||
quest_df = select_ds(ds_name, quest_df)
|
||||
exo_df = select_ds(ds_name, exo_df)
|
||||
eval_df = select_ds(ds_name, eval_df)
|
||||
|
||||
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}
|
||||
|
||||
target = build_target_name(classe, ds_name, path)
|
||||
feed_bilan(target, datas, template)
|
||||
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# Reglages pour 'vim'
|
||||
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
||||
# cursor: 16 del
|
||||
88
notes_tools/generate_bilan/templates/tpl_bilan.tex
Normal file
88
notes_tools/generate_bilan/templates/tpl_bilan.tex
Normal file
@@ -0,0 +1,88 @@
|
||||
\documentclass{/media/documents/Cours/Prof/Enseignements/2016-2017/tools/style/classBilan}
|
||||
\usepackage{/media/documents/Cours/Prof/Enseignements/2016-2017/theme}
|
||||
|
||||
\usepackage{multicol}
|
||||
|
||||
% Title Page
|
||||
\titre{\Var{ds_info["Nom"]}}
|
||||
% \seconde \premiereS \PSTMG \TSTMG
|
||||
\classe{\Var{ds_info["Classe"]}}
|
||||
\date{\Var{ds_info["Date"]}}
|
||||
|
||||
|
||||
\begin{document}
|
||||
|
||||
\Block{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.9\linewidth}
|
||||
\hfill
|
||||
\vspace{3cm}
|
||||
\end{minipage}
|
||||
}
|
||||
|
||||
\vfill
|
||||
|
||||
\scriptsize
|
||||
\begin{multicols}{3}
|
||||
|
||||
\Block{for exo in e["Exercices"]}
|
||||
\begin{tabular}{|p{2cm}|c|}
|
||||
|
||||
\Block{if exo["Nom"] in ["Bonus", "Malus", "Presentation"]}
|
||||
\Block{for _,q in exo["Questions"].iterrows()}
|
||||
\Block{if q["Mark"]}
|
||||
\hline
|
||||
\rowcolor{highlightbg}
|
||||
\Var{exo["Nom"]} (\Var{q["Question"]}) & \Var{q["Latex_rep"]} \\
|
||||
\Block{endif}
|
||||
\Block{endfor}
|
||||
\Block{else}
|
||||
|
||||
\hline
|
||||
\rowcolor{highlightbg}
|
||||
Exerice \Var{exo["Nom"]} & \Var{exo["Total"]["Mark"]} / \Var{exo["Total"]["Bareme"]} \\
|
||||
\Block{for _,q in exo["Questions"].iterrows()}
|
||||
\hline
|
||||
\Var{q["Question"]} \newline \Var{q["Commentaire"]} & \Var{q["Latex_rep"]} \\
|
||||
\Block{endfor}
|
||||
\Block{endif}
|
||||
|
||||
|
||||
\hline
|
||||
\end{tabular}
|
||||
\Block{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
|
||||
\Block{endfor}
|
||||
|
||||
\end{document}
|
||||
|
||||
%%% Local Variables:
|
||||
%%% mode: latex
|
||||
%%% TeX-master: "master"
|
||||
%%% End:
|
||||
|
||||
52
notes_tools/generate_bilan/texenv.py
Normal file
52
notes_tools/generate_bilan/texenv.py
Normal file
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
import jinja2, os
|
||||
|
||||
__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 = '}',
|
||||
loader = jinja2.PackageLoader("notes_tools.generate_bilan", "templates"),
|
||||
extensions = ['jinja2.ext.do']
|
||||
)
|
||||
|
||||
# Filters
|
||||
|
||||
def do_calculus(steps, name = "A", sep = "=", end = "", joining = " \\\\ \n"):
|
||||
"""Display properly the calculus
|
||||
|
||||
Generate this form string:
|
||||
"name & sep & a_step end joining"
|
||||
|
||||
:param steps: list of steps
|
||||
:returns: latex string ready to be endbeded
|
||||
|
||||
|
||||
"""
|
||||
|
||||
ans = joining.join([name + " & " + sep + " & " + str(s) + end for s in steps])
|
||||
return ans
|
||||
|
||||
texenv.filters['calculus'] = do_calculus
|
||||
|
||||
from random import shuffle
|
||||
texenv.filters['shuffle'] = shuffle
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(texenv.list_templates())
|
||||
texenv.get_template("tpl_bilan.tex")
|
||||
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# Reglages pour 'vim'
|
||||
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
||||
# cursor: 16 del
|
||||
Reference in New Issue
Block a user