From 3eafad5841a1d917d80cc0a7cbdc2201d42639cc Mon Sep 17 00:00:00 2001 From: Benjamin Bertrand Date: Tue, 8 Nov 2016 11:07:03 +0300 Subject: [PATCH] Clean imports and start packaging it --- generate_bilan/__init__.py | 9 ++++++ generate_bilan/__main__.py | 17 ++++++++++ generate_bilan/generate_bilan.py | 16 ++-------- generate_bilan/texenv.py | 53 ++++++++++++++++++++++++++++++++ notes_tools/__init__.py | 13 ++++++++ 5 files changed, 95 insertions(+), 13 deletions(-) create mode 100644 generate_bilan/__main__.py create mode 100644 generate_bilan/texenv.py diff --git a/generate_bilan/__init__.py b/generate_bilan/__init__.py index e69de29..dd9b638 100644 --- a/generate_bilan/__init__.py +++ b/generate_bilan/__init__.py @@ -0,0 +1,9 @@ +#!/usr/bin/env python +# encoding: utf-8 + +from generate_bilan import generate_bilan + +# ----------------------------- +# Reglages pour 'vim' +# vim:set autoindent expandtab tabstop=4 shiftwidth=4: +# cursor: 16 del diff --git a/generate_bilan/__main__.py b/generate_bilan/__main__.py new file mode 100644 index 0000000..2c27163 --- /dev/null +++ b/generate_bilan/__main__.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python +# encoding: utf-8 + +from generate_bilan import generate_bilan +import optparse + +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.") +(options, args) = parser.parse_args() + +build_bilan(options.classe, options.ds_name) + +# ----------------------------- +# Reglages pour 'vim' +# vim:set autoindent expandtab tabstop=4 shiftwidth=4: +# cursor: 16 del diff --git a/generate_bilan/generate_bilan.py b/generate_bilan/generate_bilan.py index f363d08..8af5d25 100755 --- a/generate_bilan/generate_bilan.py +++ b/generate_bilan/generate_bilan.py @@ -1,12 +1,10 @@ #!/usr/bin/env python # encoding: utf-8 -from extract import extract_flat_marks, get_class_ws -from df_marks_manip import digest_flat_df, students_pov -from opytex import texenv +from notes_tools import extract_flat_marks, get_class_ws, digest_flat_df, students_pov +from generate_bilan.texenv import texenv import pandas as pd import numpy as np -import optparse import xlrd notStudent = ["Trimestre", "Nom", "Date", "Exercice", "Question", "Competence", "Domaine", "Commentaire", "Bareme", "Niveau"] @@ -84,7 +82,7 @@ def feed_bilan(target, datas, template = "./tpl_bilan.tex"): f.write(bilan.render(**datas)) print("{} est construit! Ya plus qu'à compiler!".format(target)) -def build_bilan(classe, ds_name): +def generate_bilan(classe, ds_name): ws = get_class_ws(classe) flat_df = extract_flat_marks(ws) @@ -103,14 +101,6 @@ def build_bilan(classe, ds_name): feed_bilan(target, datas) -if __name__ == "__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.") - (options, args) = parser.parse_args() - - build_bilan(options.classe, options.ds_name) - # ----------------------------- # Reglages pour 'vim' diff --git a/generate_bilan/texenv.py b/generate_bilan/texenv.py new file mode 100644 index 0000000..4a35e68 --- /dev/null +++ b/generate_bilan/texenv.py @@ -0,0 +1,53 @@ +#!/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.FileSystemLoader(os.path.abspath('.')), + 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__': + from pymath.expression import Expression + exp = Expression("2/4 + 18") + print(do_calculus(exp.simplify())) + + + +# ----------------------------- +# Reglages pour 'vim' +# vim:set autoindent expandtab tabstop=4 shiftwidth=4: +# cursor: 16 del diff --git a/notes_tools/__init__.py b/notes_tools/__init__.py index e69de29..c6975c2 100644 --- a/notes_tools/__init__.py +++ b/notes_tools/__init__.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python +# encoding: utf-8 + + +from notes_tools.extract import extract_flat_marks, get_class_ws +from notes_tools.df_marks_manip import digest_flat_df, students_pov + + + +# ----------------------------- +# Reglages pour 'vim' +# vim:set autoindent expandtab tabstop=4 shiftwidth=4: +# cursor: 16 del