repytex/repytex/reports/term_reports.py

85 lines
2.2 KiB
Python
Raw Normal View History

2016-11-26 15:44:13 +00:00
#!/usr/bin/env python
# encoding: utf-8
2017-04-17 10:10:20 +00:00
""" Making term reports """
2016-11-26 15:44:13 +00:00
import logging
2017-04-17 12:10:14 +00:00
from repytex.tools import (
2017-04-17 10:10:20 +00:00
extract_flat_marks,
get_class_ws,
digest_flat_df,
term
)
from .produce_compile import produce_compile
from path import Path
2017-03-07 10:08:50 +00:00
logger = logging.getLogger(__name__)
2016-11-26 15:44:13 +00:00
2017-04-17 10:10:20 +00:00
2016-11-26 15:44:13 +00:00
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
2017-04-17 10:10:20 +00:00
def build_target_name(classe, term_num, path=Path("./")):
2016-11-26 15:44:13 +00:00
""" Build the path where the .tex will be sored
>>> build_target_name("312", "DS1")
2017-03-07 10:08:50 +00:00
Path('./312/report_DS1.tex')
2016-11-26 15:44:13 +00:00
>>> build_target_name("312", "DS1", Path("plop/"))
2017-03-07 10:08:50 +00:00
Path('plop/312/report_DS1.tex')
2016-11-26 15:44:13 +00:00
"""
2017-04-17 10:10:20 +00:00
return Path(path + f"/{classe}/report_T{term_num}.tex")
2016-11-26 15:44:13 +00:00
2017-04-17 10:10:20 +00:00
def term_report(classe, term_num, path=Path('./'),
template="tpl_reports_term.tex", force=1):
2017-03-07 10:08:50 +00:00
""" Generate the report of a evaluation for a class
2016-11-26 15:44:13 +00:00
:param classe: the classe name
:param evalname: name of the evaluation
:param path: path where xlsx are stored
2017-03-07 10:08:50 +00:00
:param template: template for the report
2017-04-17 10:10:20 +00:00
:param force: Override existing documents
2016-11-26 15:44:13 +00:00
"""
ws = get_class_ws(classe, path)
2017-04-17 10:10:20 +00:00
logger.info(f"Worksheets of {classe} imported")
2016-11-26 15:44:13 +00:00
flat_df = extract_flat_marks(ws)
logger.info("Worksheets parsed")
2017-04-01 10:48:33 +00:00
term_df = flat_df[flat_df['Trimestre'] == term_num]
2017-03-07 06:27:40 +00:00
quest_df, exo_df, eval_df = digest_flat_df(term_df)
2016-11-26 15:44:13 +00:00
2017-03-07 10:08:50 +00:00
report_info = term_info(classe, eval_df)
2016-11-26 15:44:13 +00:00
2017-03-23 16:23:11 +00:00
students_pov = term.students_pov(quest_df, exo_df, eval_df)
class_pov = term.class_pov(quest_df, exo_df, eval_df)
2017-04-17 10:10:20 +00:00
datas = {
"report_info": report_info,
"classe": class_pov,
"students": students_pov,
}
2016-11-26 15:44:13 +00:00
2017-04-01 10:48:33 +00:00
target = build_target_name(classe, term_num, path)
2017-04-17 10:10:20 +00:00
produce_compile(template, datas, target, force)
2016-11-26 15:44:13 +00:00
# -----------------------------
# Reglages pour 'vim'
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
2017-04-17 10:10:20 +00:00
# cursor: 16 del