work on default setting for generate bilan

This commit is contained in:
Benjamin Bertrand 2016-11-08 12:34:06 +03:00
parent 83754edda2
commit dc8f3804a6
3 changed files with 68 additions and 12 deletions

View File

@ -1,7 +1,8 @@
#!/usr/bin/env python #!/usr/bin/env python
# encoding: utf-8 # encoding: utf-8
from generate_bilan import generate_bilan from .generate_bilan import generate_bilan
from .texenv import texenv
# ----------------------------- # -----------------------------
# Reglages pour 'vim' # Reglages pour 'vim'

View File

@ -3,13 +3,52 @@
from generate_bilan import generate_bilan from generate_bilan import generate_bilan
import optparse import optparse
import os
from path import Path
# Defaults settings
this_dir, this_filename = os.path.split(__file__)
default_template = Path(this_dir + "/tpl_bilan.tex")
parser = optparse.OptionParser() parser = optparse.OptionParser()
parser.add_option("-c","--classe",action="store",type="string",dest="classe", help="The classe") parser.add_option("-c",
parser.add_option("-e","--evaluation",action="store",type="string",dest="ds_name", help="The evaluation name.") "--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.")
parser.add_option("-p",
"--path",
action="store",
type="string",
dest="path",
default=Path("./"),
help="Path where xlsx are stored")
parser.add_option("-t",
"--template",
action="store",
type="string",
dest="template",
default=default_template,
help="The template file")
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
build_bilan(options.classe, options.ds_name) if not options.classe:
raise ValueError("Need to pass a class with -c. See -h for help")
if not options.ds_name:
raise ValueError("Need to pass a evaluation name with -e. See -h for help")
build_bilan(options.classe,
options.ds_name,
options.path,
options.template)
# ----------------------------- # -----------------------------
# Reglages pour 'vim' # Reglages pour 'vim'

View File

@ -6,9 +6,9 @@ from generate_bilan.texenv import texenv
import pandas as pd import pandas as pd
import numpy as np import numpy as np
import xlrd import xlrd
from path import Path
notStudent = ["Trimestre", "Nom", "Date", "Exercice", "Question", "Competence", "Domaine", "Commentaire", "Bareme", "Niveau"] notStudent = ["Trimestre", "Nom", "Date", "Exercice", "Question", "Competence", "Domaine", "Commentaire", "Bareme", "Niveau"]
pure_marks = ["Malus", "Bonus", "Presentation"]
def extract_students(df, notStudent = notStudent): def extract_students(df, notStudent = notStudent):
""" Extract the list of students from df """ """ Extract the list of students from df """
@ -67,13 +67,21 @@ def build_ds_info(classe, ds_df):
ds_info["Trimestre"] = ds_df["Trimestre"].unique()[0] ds_info["Trimestre"] = ds_df["Trimestre"].unique()[0]
return ds_info return ds_info
def build_target_name(classe, ds_name): def build_target_name(classe, ds_name, path = Path("./")):
return "./" + classe + "/bilan_" + ds_name + ".tex" """ 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 + classe + "/bilan_" + ds_name + ".tex"
def feed_bilan(target, datas, template = "./tpl_bilan.tex"): def feed_bilan(target, datas, template = "./tpl_bilan.tex"):
""" get the template and feed it to create bilans """ Get the template and feed it to create bilans
:param ???: :param target: path where the bilan will be saved
:param datas: dictonnary to feed the template :param datas: dictonnary to feed the template
:param template: the template :param template: the template
""" """
@ -82,8 +90,16 @@ def feed_bilan(target, datas, template = "./tpl_bilan.tex"):
f.write(bilan.render(**datas)) f.write(bilan.render(**datas))
print("{} est construit! Ya plus qu'à compiler!".format(target)) print("{} est construit! Ya plus qu'à compiler!".format(target))
def generate_bilan(classe, ds_name): def generate_bilan(classe, ds_name, path = Path('./'), template = "./tpl_bilan.tex"):
ws = get_class_ws(classe) """ Generate the bilan of a evaluation for a class
:param classe: the classe name
:param ds_name: name of the evaluation
:param path: path where xlsx are stored
:param template: template for the bilan
"""
ws = get_class_ws(classe, path)
flat_df = extract_flat_marks(ws) flat_df = extract_flat_marks(ws)
quest_df, exo_df, eval_df = digest_flat_df(flat_df) quest_df, exo_df, eval_df = digest_flat_df(flat_df)
@ -98,7 +114,7 @@ def generate_bilan(classe, ds_name):
datas = {"ds_info": ds_info, "students":students_df} datas = {"ds_info": ds_info, "students":students_df}
target = build_target_name(classe, ds_name) target = build_target_name(classe, ds_name)
feed_bilan(target, datas) feed_bilan(target, datas, template)