new eval_tools and new df_marks_manip

This commit is contained in:
Benjamin Bertrand 2016-11-14 19:06:19 +03:00
parent ae5a529602
commit dea2016ab5
3 changed files with 96 additions and 0 deletions

View File

@ -4,6 +4,7 @@
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

View File

@ -68,6 +68,53 @@ def note_to_mark(x):
return x["Note"] * x["Bareme"] / 3
return x["Note"]
def question_uniq_formater(row):
""" Create a kind of unique description of the question
>>> 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)
>>> question_uniq_formater(df.loc[0])
'Ex1 Q1'
>>> question_uniq_formater(df.loc[10])
'Ex1 Q1'
"""
ans = ""
try:
int(row['Exercice'])
except ValueError:
ans += str(row["Exercice"])
else:
ans += "Exo"+str(row["Exercice"])
ans += " "
try:
int(row["Question"])
except ValueError:
if not pd.isnull(row["Question"]):
ans += str(row["Question"])
else:
ans += "Qu"+str(row["Question"])
try:
row["Commentaire"]
except KeyError:
pass
else:
if not pd.isnull(row["Commentaire"]):
ans += " ({})".format(row["Commentaire"])
return ans
# DataFrame columns manipulations
def compute_marks(df):
@ -170,6 +217,10 @@ def compute_normalized(df):
"""
return df["Mark"] / df["Bareme"]
def compute_question_description(df):
""" Compute the unique description of a question """
return df.apply(question_uniq_formater, axis = 1)
# Computing custom values
def compute_exo_marks(df):
@ -273,6 +324,7 @@ def digest_flat_df(flat_df):
df["Mark"] = compute_marks(flat_df)
df["Latex_rep"] = compute_latex_rep(flat_df)
df["Normalized"] = compute_normalized(df)
df["Uniq_quest"] = compute_question_description(df)
exo_df = compute_exo_marks(df)
exo_df["Normalized"] = compute_normalized(exo_df)

View File

@ -0,0 +1,43 @@
#!/usr/bin/env python
# encoding: utf-8
import pandas as pd
import numpy as np
def select_eval(quest_df, exo_df, eval_df, evalname):
""" Return quest, exo and eval rows which correspond to evalname
:param quest_df: TODO
:param exo_df: TODO
:param eval_df: TODO
"""
qu = quest_df[quest_df["Nom"] == evalname]
exo = exo_df[exo_df["Nom"] == evalname]
ev = eval_df[eval_df["Nom"] == evalname]
return qu, exo, ev
def get_present_absent(eval_df):
""" Return list of student who where present (Mark > 0) and
the list of those who weren't
"""
presents = eval_df[eval_df["Mark"] > 0]["Eleve"]
absents = eval_df[eval_df["Mark"] == 0]["Eleve"]
return {"presents": presents, "absents": absents}
def keep_only_presents(quest_df, exo_df, eval_df, presents):
""" Return quest, exo and eval rows of presents students """
qu = quest_df[quest_df["Eleve"].isin(presents)]
exo = exo_df[exo_df["Eleve"].isin(presents)]
ev = eval_df[eval_df["Eleve"].isin(presents)]
return qu, exo, ev
# -----------------------------
# Reglages pour 'vim'
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
# cursor: 16 del