class POV for term

This commit is contained in:
Benjamin Bertrand 2017-03-09 15:55:32 +03:00
parent e8e1220ecd
commit 412b174027
3 changed files with 71 additions and 5 deletions

View File

@ -14,6 +14,8 @@ from notes_tools.tools.marks_plottings import (pie_pivot_table,
parallel_on,
radar_on,
)
import pandas as pd
import numpy as np
__all__ = ["Student", "Classe"]
@ -112,11 +114,56 @@ class Student(object):
class Classe(object):
"""Docstring for Classe. """
"""
Informations on a class which can be use inside template.
Those informations should not be modify or use for compute analysis otherwise they won't be spread over other POV.
"""
def __init__(self):
"""TODO: to be defined1. """
pass
def __init__(self, quest_df, exo_df, eval_df):
""" Init of a class from quest, exo and eval """
self.quest_df = quest_df
self.exo_df = exo_df
self.eval_df = eval_df
@property
def evals_tabular(self):
""" Summary of all evaluations for all students """
try:
self._evals_tabular
except AttributeError:
self._evals_tabular = pd.pivot_table(self.eval_df,
index = "Eleve",
columns = "Nom",
values = "Mark_barem",
aggfunc = lambda x: " ".join(x)).to_latex()
return self._evals_tabular
@property
def parallel_on_evals(self):
""" Parallel coordinate plot of the class """
return parallel_on(self.eval_df, "Nom")
@property
def pies_eff_pts_on_competence(self):
""" Pie charts on competence with repartition of evaluated times and attributed points """
return pie_pivot_table(self.quest_df,
index = "Competence",
#columns = "Level",
values = "Bareme",
aggfunc=[len,np.sum],
fill_value=0)
@property
def pies_eff_pts_on_domaine(self):
""" Pie charts on domaine with repartition of evaluated times and attributed points """
return pie_pivot_table(self.quest_df,
index = "Domaine",
#columns = "Level",
values = "Bareme",
aggfunc=[len,np.sum],
fill_value=0)

View File

@ -17,6 +17,15 @@ def round_half_point(val):
except TypeError:
return val
def num_format(num):
""" Tranform a number into an appropriate string """
try:
if int(num) == num:
return str(int(num))
except ValueError:
pass
return f"{num:.1f}".replace(".", ",")
latex_caract = ["\\NoRep", "\\RepZ", "\\RepU", "\\RepD", "\\RepT"]
def note_to_rep(x):
r""" Transform a Note to the latex caracter
@ -112,6 +121,10 @@ def note_to_level(x):
else:
return int(ceil(x["Note"] / x["Bareme"] * 3))
def mark_bareme_formater(row):
""" Create m/b string """
return f"{num_format(row['Mark'])} / {num_format(row['Bareme'])}"
def question_uniq_formater(row):
""" Create a kind of unique description of the question
@ -294,6 +307,10 @@ def compute_normalized(df):
"""
return df["Mark"] / df["Bareme"]
def compute_mark_barem(df):
""" Build the string mark m/b """
return df.apply(mark_bareme_formater, axis=1)
def compute_question_description(df):
""" Compute the unique description of a question """
return df.apply(question_uniq_formater, axis = 1)
@ -458,8 +475,10 @@ def digest_flat_df(flat_df):
exo_df = compute_exo_marks(df)
exo_df["Normalized"] = compute_normalized(exo_df)
exo_df["Mark_barem"] = compute_mark_barem(exo_df)
eval_df = compute_eval_marks(exo_df)
eval_df["Normalized"] = compute_normalized(eval_df)
eval_df["Mark_barem"] = compute_mark_barem(eval_df)
return df, exo_df, eval_df

View File

@ -81,7 +81,7 @@ def my_autopct(values):
def pivot_table_to_pie(pv, pies_per_lines = 3):
nbr_pies = len(pv.columns)
nbr_cols = min(pies_per_lines, nbr_pies)
nbr_rows = nbr_pies // nbr_cols + 1
nbr_rows = nbr_pies // nbr_cols
f, axs = plt.subplots(nbr_rows, nbr_cols, figsize = (4*nbr_cols,4*nbr_rows))
for (c, ax) in zip(pv, axs.flatten()):
datas = pv[c]