91 lines
2.8 KiB
Python
91 lines
2.8 KiB
Python
|
#!/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
|