From 2645dc0c03d6eaccc6bc5e9b64a9fc855896d90c Mon Sep 17 00:00:00 2001 From: Benjamin Bertrand Date: Sat, 26 Nov 2016 18:04:46 +0300 Subject: [PATCH] reorga eval marks manipulation --- notes_tools/generate_bilan/eval_bilan.py | 6 +-- notes_tools/tools/__init__.py | 4 +- notes_tools/tools/df_marks_manip.py | 56 ------------------------ notes_tools/tools/eval_tools.py | 53 +++++++++++++++++++++- 4 files changed, 57 insertions(+), 62 deletions(-) diff --git a/notes_tools/generate_bilan/eval_bilan.py b/notes_tools/generate_bilan/eval_bilan.py index 20373da..3159f1b 100755 --- a/notes_tools/generate_bilan/eval_bilan.py +++ b/notes_tools/generate_bilan/eval_bilan.py @@ -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} diff --git a/notes_tools/tools/__init__.py b/notes_tools/tools/__init__.py index a8609cb..4f548ef 100644 --- a/notes_tools/tools/__init__.py +++ b/notes_tools/tools/__init__.py @@ -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 diff --git a/notes_tools/tools/df_marks_manip.py b/notes_tools/tools/df_marks_manip.py index 1b06e64..4b5ee01 100644 --- a/notes_tools/tools/df_marks_manip.py +++ b/notes_tools/tools/df_marks_manip.py @@ -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' diff --git a/notes_tools/tools/eval_tools.py b/notes_tools/tools/eval_tools.py index 290975c..94ed607 100644 --- a/notes_tools/tools/eval_tools.py +++ b/notes_tools/tools/eval_tools.py @@ -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 # -----------------------------