repytex/notes_tools/reports/term_reports.py

77 lines
2.2 KiB
Python
Executable File

#!/usr/bin/env python
# encoding: utf-8
from notes_tools.tools import extract_flat_marks, get_class_ws, digest_flat_df, term
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_num, 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_num}.tex".format(cls=classe, term_num=term_num))
def term_report(classe, term_num, 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_num]
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_pov = term.students_pov(quest_df, exo_df, eval_df)
class_pov = term.class_pov(quest_df, exo_df, eval_df)
datas = {"report_info": report_info,
"classe": class_pov,
"students":students_pov,
}
target = build_target_name(classe, term_num, path)
feed_template(target, datas, template)
# -----------------------------
# Reglages pour 'vim'
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
# cursor: 16 del