reorga eval marks manipulation

This commit is contained in:
Benjamin Bertrand 2016-11-26 18:04:46 +03:00
parent 591fc10c30
commit 2645dc0c03
4 changed files with 57 additions and 62 deletions

View File

@ -1,7 +1,7 @@
#!/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 notes_tools.tools import extract_flat_marks, get_class_ws, digest_flat_df, eval_tools #students_pov, select_eval
from .texenv import feed_template
import pandas as pd
import numpy as np
@ -54,10 +54,10 @@ def eval_bilan(classe, evalname, path = Path('./'), template = "tpl_bilan_eval.t
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)
quest_df, exo_df, eval_df = eval_tools.select(quest_df, exo_df, eval_df, evalname)
bilan_info = eval_info(classe, eval_df)
students = students_pov(quest_df, exo_df, eval_df)
students = eval_tools.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}

View File

@ -3,8 +3,8 @@
from .extract import extract_flat_marks, get_class_ws
from .df_marks_manip import digest_flat_df, students_pov
from .eval_tools import select_eval, get_present_absent, keep_only_presents
from .df_marks_manip import digest_flat_df#, students_pov
#from .eval_tools import select_eval, get_present_absent, keep_only_presents
from .plottings import radar_graph

View File

@ -384,62 +384,6 @@ def digest_flat_df(flat_df):
return df, exo_df, eval_df
# Organize data
def students_pov(quest_df, exo_df, eval_df):
"""
>>> d = {"Eleve":["E1"]*6 + ["E2"]*6,
... "Nom": ["N1"]*4+["N2"]*2 + ["N1"]*4+["N2"]*2,
... "Exercice":["Ex1"]*2+["Ex2"]*2+["Ex1"]+["Ex2"] + ["Ex1"]*2+["Ex2"]*2+["Ex1"]+["Ex2"],
... "Question":["Q1"]+["Q2"]+["Q1"]+["Q2"]+["Q1"]+["Q1"] + ["Q1"]+["Q2"]+["Q1"]+["Q2"]+["Q1"]+["Q1"],
... "Date":["16/09/2016"]*4+["01/10/2016"]*2 + ["16/09/2016"]*4+["01/10/2016"]*2,
... "Trimestre": ["1"]*12,
... "Bareme":[1]*2+[2]*2+[2]*2 + [1]*2+[2]*2+[2]*2,
... "Niveau":[0]*4+[1]*2 + [0]*4+[1]*2,
... "Note":[1, 0.33, 2, 1.5, 1, 3, 0.666, 1, 1.5, 1, 2, 3],
... }
>>> df = pd.DataFrame(d)
>>> quest_df, exo_df, eval_df = digest_flat_df(df)
>>> std_pov = students_pov(quest_df, exo_df, eval_df)
>>> std = std_pov[0]
>>> std["Nom"]
'E1'
>>> "{} / {}".format(std["Total"]["Mark"], std["Total"]["Bareme"])
'5.0 / 6.0'
>>> for exo in std["Exercices"]:
... print("{}: {} / {}".format(exo["Nom"], exo["Total"]["Mark"], exo["Total"]["Bareme"]))
Ex1: 1.5 / 2.0
Ex2: 3.5 / 4.0
>>> exo = std["Exercices"][0]
>>> for _,q in exo["Questions"].iterrows():
... print("{} : {}".format(q["Question"], q["Latex_rep"]))
Q1 : 1.0
Q2 : 0.33
Q1 : \RepU
"""
es = []
for e in eval_df["Eleve"].unique():
eleve = {"Nom":e}
e_quest = quest_df[quest_df["Eleve"] == e]
eleve["quest"] = e_quest
e_exo = exo_df[exo_df["Eleve"] == e]
#e_df = ds_df[ds_df["Eleve"] == e][["Exercice", "Question", "Bareme", "Commentaire", "Niveau", "Mark", "Latex_rep"]]
eleve["Total"] = eval_df[eval_df["Eleve"]==e].iloc[0]
exos = []
for exo in e_exo["Exercice"].unique():
ex = {"Nom":exo}
ex["Total"] = e_exo[e_exo["Exercice"]==exo].iloc[0]
ex["Questions"] = e_quest[e_quest["Exercice"] == exo]
exos.append(ex)
eleve["Exercices"] = exos
es.append(eleve)
return es
# -----------------------------
# Reglages pour 'vim'

View File

@ -5,7 +5,7 @@ import pandas as pd
import numpy as np
def select_eval(quest_df, exo_df, eval_df, evalname):
def select(quest_df, exo_df, eval_df, evalname):
""" Return quest, exo and eval rows which correspond to evalname
:param quest_df: TODO
@ -34,7 +34,58 @@ def keep_only_presents(quest_df, exo_df, eval_df, presents):
ev = eval_df[eval_df["Eleve"].isin(presents)]
return qu, exo, ev
def students_pov(quest_df, exo_df, eval_df):
"""
>>> d = {"Eleve":["E1"]*6 + ["E2"]*6,
... "Nom": ["N1"]*4+["N2"]*2 + ["N1"]*4+["N2"]*2,
... "Exercice":["Ex1"]*2+["Ex2"]*2+["Ex1"]+["Ex2"] + ["Ex1"]*2+["Ex2"]*2+["Ex1"]+["Ex2"],
... "Question":["Q1"]+["Q2"]+["Q1"]+["Q2"]+["Q1"]+["Q1"] + ["Q1"]+["Q2"]+["Q1"]+["Q2"]+["Q1"]+["Q1"],
... "Date":["16/09/2016"]*4+["01/10/2016"]*2 + ["16/09/2016"]*4+["01/10/2016"]*2,
... "Trimestre": ["1"]*12,
... "Bareme":[1]*2+[2]*2+[2]*2 + [1]*2+[2]*2+[2]*2,
... "Niveau":[0]*4+[1]*2 + [0]*4+[1]*2,
... "Note":[1, 0.33, 2, 1.5, 1, 3, 0.666, 1, 1.5, 1, 2, 3],
... }
>>> df = pd.DataFrame(d)
>>> quest_df, exo_df, eval_df = digest_flat_df(df)
>>> std_pov = students_pov(quest_df, exo_df, eval_df)
>>> std = std_pov[0]
>>> std["Nom"]
'E1'
>>> "{} / {}".format(std["Total"]["Mark"], std["Total"]["Bareme"])
'5.0 / 6.0'
>>> for exo in std["Exercices"]:
... print("{}: {} / {}".format(exo["Nom"], exo["Total"]["Mark"], exo["Total"]["Bareme"]))
Ex1: 1.5 / 2.0
Ex2: 3.5 / 4.0
>>> exo = std["Exercices"][0]
>>> for _,q in exo["Questions"].iterrows():
... print("{} : {}".format(q["Question"], q["Latex_rep"]))
Q1 : 1.0
Q2 : 0.33
Q1 : \RepU
"""
es = []
for e in eval_df["Eleve"].unique():
eleve = {"Nom":e}
e_quest = quest_df[quest_df["Eleve"] == e]
eleve["quest"] = e_quest
e_exo = exo_df[exo_df["Eleve"] == e]
#e_df = ds_df[ds_df["Eleve"] == e][["Exercice", "Question", "Bareme", "Commentaire", "Niveau", "Mark", "Latex_rep"]]
eleve["Total"] = eval_df[eval_df["Eleve"]==e].iloc[0]
exos = []
for exo in e_exo["Exercice"].unique():
ex = {"Nom":exo}
ex["Total"] = e_exo[e_exo["Exercice"]==exo].iloc[0]
ex["Questions"] = e_quest[e_quest["Exercice"] == exo]
exos.append(ex)
eleve["Exercices"] = exos
es.append(eleve)
return es
# -----------------------------