Classe level_heatmap

This commit is contained in:
Benjamin Bertrand 2017-03-29 05:45:08 +03:00
parent 598d8f8848
commit 7febc6ba6b

View File

@ -3,6 +3,12 @@
import pandas as pd import pandas as pd
import numpy as np import numpy as np
from notes_tools.tools.marks_plottings import (pie_pivot_table,
parallel_on,
radar_on,
)
import seaborn as sns
class Student(object): class Student(object):
@ -89,6 +95,72 @@ class Student(object):
tabular.append(r"\end{tabular}") tabular.append(r"\end{tabular}")
return '\n'.join(tabular) return '\n'.join(tabular)
@property
def pies_on_competence(self):
""" Pies chart on competences """
try:
self._pies_on_competence
except AttributeError:
self._pies_on_competence = pie_pivot_table(self.quest_df,
index = "Level",
columns = "Competence",
values = "Eleve",
aggfunc = len,
fill_value = 0,
)
return self._pies_on_competence
@property
def pies_on_domaine(self):
""" Pies chart on domaines """
try:
self._pies_on_domaine
except AttributeError:
self._pies_on_domaine = pie_pivot_table(self.quest_df,
index = "Level",
columns = "Domaine",
values = "Eleve",
aggfunc = len,
fill_value = 0,
)
return self._pies_on_domaine
@property
def radar_on_competence(self):
""" Radar plot on competence """
try:
self._radar_on_competence
except AttributeError:
self._radar_on_competence = radar_on(self.quest_df,
"Competence")
return self._radar_on_competence
@property
def radar_on_domaine(self):
""" Radar plot on domaine """
try:
self._radar_on_domaine
except AttributeError:
self._radar_on_domaine = radar_on(self.quest_df,
"Domaine")
return self._radar_on_domaine
@property
def heatmap_on_domain(self):
""" Heatmap over evals on domains """
try:
self._heatmap_on_domain
except AttributeError:
comp = pd.pivot_table(self.quest_df,
index = "Competence",
columns = ["Exercice", "Question"],
values = ["Normalized"],
aggfunc = np.mean,
)
comp.columns = [f"{i['Exercice']} {i['Question']}" for _,i in self.quest_df[["Exercice", "Question"]].drop_duplicates().iterrows()]
self._heatmap_on_domain = sns.heatmap(comp)
return self._heatmap_on_domain
class Classe(object): class Classe(object):
""" """
@ -96,7 +168,68 @@ class Classe(object):
Those informations should not be modify or use for compute analysis otherwise they won't be spread over other POV. Those informations should not be modify or use for compute analysis otherwise they won't be spread over other POV.
""" """
pass def __init__(self, quest_df, exo_df, eval_df):
""" Init of a class from quest, exo and eval """
names = {*quest_df["Nom"].unique(),
*exo_df["Nom"].unique(),
*eval_df["Nom"].unique(),
}
if len(names) != 1:
raise ValueError("Can't initiate Classe: dfs contains different evaluation names")
self.name = names.pop()
self.quest_df = quest_df
self.exo_df = exo_df
self.eval_df = eval_df
@property
def marks_tabular(self):
""" Latex tabular with marks of students"""
try:
self._marks_tabular
except AttributeError:
self._marks_tabular = self.eval_df[["Eleve", "Mark_barem"]]
self._marks_tabular.columns = ["Élèves", "Note"]
return self._marks_tabular.to_latex()
@property
def level_heatmap(self):
""" Heapmap on acheivement level """
try:
self._level_heatmap
except AttributeError:
pv = pd.pivot_table(self.quest_df,
index = "Eleve",
columns = ["Exercice", "Question", "Commentaire"],
values = ["Normalized"],
aggfunc = "mean",
)
def lines_4_heatmap(c):
lines = []
ini = ''
for k,v in enumerate(c.labels[1][::-1]):
if v != ini:
lines.append(k)
ini = v
return lines[1:]
exercice_sep = lines_4_heatmap(pv.columns)
pv.columns = [f"{i[1]} {i[2]} {i[3]:.15}" for i in pv.columns.get_values()]
self._level_heatmap = sns.heatmap(pv.T)
self._level_heatmap.hlines(exercice_sep,
*self._level_heatmap.get_xlim(),
colors = "orange",
)
return self._level_heatmap
# TODO: à factoriser Il y a la même dans term.py |jeu. mars 23 19:36:28 EAT 2017 # TODO: à factoriser Il y a la même dans term.py |jeu. mars 23 19:36:28 EAT 2017
def select(quest_df, exo_df, eval_df, index, value): def select(quest_df, exo_df, eval_df, index, value):