From 090be7a34866528fd768152e0a0bf2fd89698696 Mon Sep 17 00:00:00 2001 From: Benjamin Bertrand Date: Tue, 7 Mar 2017 13:08:50 +0300 Subject: [PATCH] change bilan to report --- .../__main__.py => generate_reports_main.py} | 26 +++++++++---------- .../{generate_bilan => reports}/__init__.py | 0 .../eval_bilan.py => reports/eval_reports.py} | 18 ++++++------- .../{generate_bilan => reports}/filters.py | 2 +- .../reports_tools.py} | 12 ++++----- .../templates/tpl_reports.tex} | 6 ++--- .../templates/tpl_reports_eval.tex} | 4 +-- .../templates/tpl_reports_term.tex} | 6 +++-- .../term_bilan.py => reports/term_reports.py} | 20 +++++++------- .../{generate_bilan => reports}/texenv.py | 15 ++++++----- setup.py | 2 +- 11 files changed, 57 insertions(+), 54 deletions(-) rename notes_tools/{generate_bilan/__main__.py => generate_reports_main.py} (81%) rename notes_tools/{generate_bilan => reports}/__init__.py (100%) rename notes_tools/{generate_bilan/eval_bilan.py => reports/eval_reports.py} (79%) rename notes_tools/{generate_bilan => reports}/filters.py (96%) rename notes_tools/{generate_bilan/bilan_tools.py => reports/reports_tools.py} (81%) rename notes_tools/{generate_bilan/templates/tpl_bilan.tex => reports/templates/tpl_reports.tex} (80%) rename notes_tools/{generate_bilan/templates/tpl_bilan_eval.tex => reports/templates/tpl_reports_eval.tex} (96%) rename notes_tools/{generate_bilan/templates/tpl_bilan_term.tex => reports/templates/tpl_reports_term.tex} (85%) rename notes_tools/{generate_bilan/term_bilan.py => reports/term_reports.py} (77%) rename notes_tools/{generate_bilan => reports}/texenv.py (82%) diff --git a/notes_tools/generate_bilan/__main__.py b/notes_tools/generate_reports_main.py similarity index 81% rename from notes_tools/generate_bilan/__main__.py rename to notes_tools/generate_reports_main.py index 7e66390..acf9d9a 100644 --- a/notes_tools/generate_bilan/__main__.py +++ b/notes_tools/generate_reports_main.py @@ -4,7 +4,7 @@ import logging # création de l'objet logger qui va nous servir à écrire dans les logs -logger = logging.getLogger("generate_bilan") +logger = logging.getLogger(__name__) # on met le niveau du logger à DEBUG, comme ça il écrit tout logger.setLevel(logging.DEBUG) formatter = logging.Formatter('%(asctime)s :: %(name)s :: %(levelname)s :: %(message)s') @@ -62,7 +62,7 @@ def main(): "--list", action="store_true", dest="list", - help="List classe and possible bilan") + help="List classe and possible reports") (options, args) = parser.parse_args() @@ -70,23 +70,23 @@ def main(): logger.setLevel(logging.DEBUG) if options.list: - from .bilan_tools import print_bilan - logger.info("Listing all bilan in {}".format(options.path)) - print_bilan(options.path) + from .reports.reports_tools import print_reports + logger.info("Listing all reports in {}".format(options.path)) + print_reports(options.path) elif options.term: if not options.classe: logger.error("Need to pass a class with -c. See -h for help") sys.exit() - logger.info("Creating term {} bilan".format(options.term)) - from .term_bilan import term_bilan + logger.info("Creating term {} report".format(options.term)) + from .reports.term_reports import term_report if options.template: logger.info("Not default template: {}".format(options.template)) template = options.template else: - template = "tpl_bilan_term.tex" + template = "tpl_reports_term.tex" - term_bilan(options.classe, + term_report(options.classe, options.term, options.path, template) @@ -95,15 +95,15 @@ def main(): if not options.classe: logger.error("Need to pass a class with -c. See -h for help") sys.exit() - logger.info("Creating {} bilan".format(options.eval)) - from .eval_bilan import eval_bilan + logger.info("Creating {} report".format(options.eval)) + from .reports.eval_reports import eval_report if options.template: logger.info("Not default template: {}".format(options.template)) template = options.template else: - template = "tpl_bilan_eval.tex" + template = "tpl_reports_eval.tex" - eval_bilan(options.classe, + eval_report(options.classe, options.eval, options.path, template) diff --git a/notes_tools/generate_bilan/__init__.py b/notes_tools/reports/__init__.py similarity index 100% rename from notes_tools/generate_bilan/__init__.py rename to notes_tools/reports/__init__.py diff --git a/notes_tools/generate_bilan/eval_bilan.py b/notes_tools/reports/eval_reports.py similarity index 79% rename from notes_tools/generate_bilan/eval_bilan.py rename to notes_tools/reports/eval_reports.py index 3159f1b..438daad 100755 --- a/notes_tools/generate_bilan/eval_bilan.py +++ b/notes_tools/reports/eval_reports.py @@ -9,7 +9,7 @@ import xlrd from path import Path import logging -logger = logging.getLogger("generate_bilan") +logger = logging.getLogger(__name__) def eval_info(classe, ds_df): """TODO: Docstring for build_ds_info. @@ -31,20 +31,20 @@ 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') + Path('./312/report_DS1.tex') >>> build_target_name("312", "DS1", Path("plop/")) - Path('plop/312/bilan_DS1.tex') + Path('plop/312/report_DS1.tex') """ - return Path(path + "/" + classe + "/bilan_" + evalname + ".tex") + return Path(path + "/" + classe + "/report_" + evalname + ".tex") -def eval_bilan(classe, evalname, path = Path('./'), template = "tpl_bilan_eval.tex"): - """ Generate the bilan of a evaluation for a class +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 bilan + :param template: template for the report """ ws = get_class_ws(classe, path) @@ -56,10 +56,10 @@ def eval_bilan(classe, evalname, path = Path('./'), template = "tpl_bilan_eval.t quest_df, exo_df, eval_df = eval_tools.select(quest_df, exo_df, eval_df, evalname) - bilan_info = eval_info(classe, eval_df) + report_info = eval_info(classe, eval_df) students = eval_tools.students_pov(quest_df, exo_df, eval_df) - datas = {"bilan_info": bilan_info, "students":students, + 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) diff --git a/notes_tools/generate_bilan/filters.py b/notes_tools/reports/filters.py similarity index 96% rename from notes_tools/generate_bilan/filters.py rename to notes_tools/reports/filters.py index 5828cea..40b7a9a 100644 --- a/notes_tools/generate_bilan/filters.py +++ b/notes_tools/reports/filters.py @@ -4,7 +4,7 @@ from uuid import uuid4 from path import Path import logging -logger = logging.getLogger("generate_bilan") +logger = logging.getLogger(__name__) def includegraphics(fig_ax, document_path="./", fig_path="fig/", prefix="", scale=1): diff --git a/notes_tools/generate_bilan/bilan_tools.py b/notes_tools/reports/reports_tools.py similarity index 81% rename from notes_tools/generate_bilan/bilan_tools.py rename to notes_tools/reports/reports_tools.py index ea82b4c..3a236b2 100755 --- a/notes_tools/generate_bilan/bilan_tools.py +++ b/notes_tools/reports/reports_tools.py @@ -8,11 +8,11 @@ import xlrd from path import Path import logging -logger = logging.getLogger("generate_bilan") +logger = logging.getLogger(__name__) -def print_bilan_of(classe_ws): - """TODO: Docstring for list_bilan. +def print_report_of(classe_ws): + """TODO: Docstring for list_report. :param arg1: TODO :returns: TODO @@ -31,8 +31,8 @@ def print_bilan_of(classe_ws): for t in df['Trimestre'].unique(): print("\t-Trimestre {}".format(t)) -def print_bilan(path): - """ List all bilan which can be generate in the directory +def print_reports(path): + """ List all report which can be generate in the directory :param path: the directory :returns: TODO @@ -42,7 +42,7 @@ def print_bilan(path): for c in list_classes(path): print("Classe de {}".format(c)) ws = get_class_ws(c, path) - print_bilan_of(ws) + print_report_of(ws) # ----------------------------- # Reglages pour 'vim' diff --git a/notes_tools/generate_bilan/templates/tpl_bilan.tex b/notes_tools/reports/templates/tpl_reports.tex similarity index 80% rename from notes_tools/generate_bilan/templates/tpl_bilan.tex rename to notes_tools/reports/templates/tpl_reports.tex index 78cb1fb..5f9ee25 100644 --- a/notes_tools/generate_bilan/templates/tpl_bilan.tex +++ b/notes_tools/reports/templates/tpl_reports.tex @@ -4,10 +4,10 @@ \usepackage{booktabs} % Title Page -\titre{\Var{bilan_info["Nom"]}} +\titre{\Var{report_info["Nom"]}} % \seconde \premiereS \PSTMG \TSTMG -\classe{\Var{bilan_info["Classe"]}} -\date{\Var{bilan_info["Date"]}} +\classe{\Var{report_info["Classe"]}} +\date{\Var{report_info["Date"]}} \begin{document} diff --git a/notes_tools/generate_bilan/templates/tpl_bilan_eval.tex b/notes_tools/reports/templates/tpl_reports_eval.tex similarity index 96% rename from notes_tools/generate_bilan/templates/tpl_bilan_eval.tex rename to notes_tools/reports/templates/tpl_reports_eval.tex index efc2e32..b25b3a7 100644 --- a/notes_tools/generate_bilan/templates/tpl_bilan_eval.tex +++ b/notes_tools/reports/templates/tpl_reports_eval.tex @@ -1,6 +1,6 @@ -%- extends "tpl_bilan.tex" +%- extends "tpl_reports.tex" -% FILENAME: "tpl_bilan_eval.tex +% FILENAME: "tpl_reports_eval.tex %- block classPOV \maketitle diff --git a/notes_tools/generate_bilan/templates/tpl_bilan_term.tex b/notes_tools/reports/templates/tpl_reports_term.tex similarity index 85% rename from notes_tools/generate_bilan/templates/tpl_bilan_term.tex rename to notes_tools/reports/templates/tpl_reports_term.tex index fccb167..a9a7e93 100644 --- a/notes_tools/generate_bilan/templates/tpl_bilan_term.tex +++ b/notes_tools/reports/templates/tpl_reports_term.tex @@ -1,5 +1,5 @@ -%- extends "tpl_bilan.tex" -% FILENAME: "tpl_bilan_term.tex +%- extends "tpl_reports.tex" +% FILENAME: "tpl_reports_term.tex %- block classPOV %- endblock @@ -20,7 +20,9 @@ \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 diff --git a/notes_tools/generate_bilan/term_bilan.py b/notes_tools/reports/term_reports.py similarity index 77% rename from notes_tools/generate_bilan/term_bilan.py rename to notes_tools/reports/term_reports.py index 875e951..8dcbd10 100755 --- a/notes_tools/generate_bilan/term_bilan.py +++ b/notes_tools/reports/term_reports.py @@ -9,7 +9,7 @@ import xlrd from path import Path import logging -logger = logging.getLogger("generate_bilan") +logger = logging.getLogger(__name__) def term_info(classe, ds_df): """TODO: Docstring for build_ds_info. @@ -29,20 +29,20 @@ def build_target_name(classe, term, path = Path("./")): """ Build the path where the .tex will be sored >>> build_target_name("312", "DS1") - Path('./312/bilan_DS1.tex') + Path('./312/report_DS1.tex') >>> build_target_name("312", "DS1", Path("plop/")) - Path('plop/312/bilan_DS1.tex') + Path('plop/312/report_DS1.tex') """ - return Path(path + "/{cls}/bilan_T{term}.tex".format(cls=classe, term=term)) + return Path(path + "/{cls}/report_T{term}.tex".format(cls=classe, term=term)) -def term_bilan(classe, term, path = Path('./'), - template = "tpl_bilan_term.tex"): - """ Generate the bilan of a evaluation for a class +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 bilan + :param template: template for the report """ ws = get_class_ws(classe, path) @@ -56,10 +56,10 @@ def term_bilan(classe, term, path = Path('./'), quest_df, exo_df, eval_df = digest_flat_df(term_df) conn_df = exo_df[exo_df["Nom"].str.contains('Conn')] - bilan_info = term_info(classe, eval_df) + report_info = term_info(classe, eval_df) students = term_tools.students_pov(quest_df, exo_df, eval_df) - datas = {"bilan_info": bilan_info, "students":students, + datas = {"report_info": report_info, "students":students, "quest_df":quest_df, "exo_df":exo_df, "eval_df":eval_df, "conn_df": conn_df} diff --git a/notes_tools/generate_bilan/texenv.py b/notes_tools/reports/texenv.py similarity index 82% rename from notes_tools/generate_bilan/texenv.py rename to notes_tools/reports/texenv.py index fd70582..07f235a 100644 --- a/notes_tools/generate_bilan/texenv.py +++ b/notes_tools/reports/texenv.py @@ -5,7 +5,7 @@ import jinja2, os from .filters import includegraphics import logging -logger = logging.getLogger("generate_bilan") +logger = logging.getLogger(__name__) __all__ = ["texenv"] @@ -20,7 +20,7 @@ texenv = jinja2.Environment( comment_end_string = '}', line_statement_prefix = '%-', line_comment_prefix = '%#', - loader = jinja2.ChoiceLoader([jinja2.PackageLoader("notes_tools.generate_bilan", "templates"), + loader = jinja2.ChoiceLoader([jinja2.PackageLoader("notes_tools.reports", "templates"), jinja2.FileSystemLoader(['./']), ]), extensions = ['jinja2.ext.do'] @@ -37,25 +37,26 @@ 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 bilans + """ Get the template and feed it to create reports - :param target: path where the bilan will be saved + :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)) - bilan = texenv.get_template(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(bilan.render(**datas, directory=path_to_target)) + 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_bilan.tex") + texenv.get_template("tpl_reports.tex") diff --git a/setup.py b/setup.py index 6f83acd..f36c780 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ setup(name="notes_analysis", 'path.py', ], entry_points = { - "console_scripts": ['generate_bilan = notes_tools.generate_bilan.__main__:main'] + "console_scripts": ['generate_bilan = notes_tools.generate_reports_main:main'] }, zip_safe=False )