Remove try:... for plots to free memory
This commit is contained in:
parent
db4d6c2b79
commit
2acdcc64b0
@ -4,6 +4,7 @@
|
||||
from uuid import uuid4
|
||||
from path import Path
|
||||
import logging
|
||||
import matplotlib.pyplot as plt
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def includegraphics(fig_ax, document_path="./", fig_path="fig/",
|
||||
@ -34,6 +35,7 @@ def includegraphics(fig_ax, document_path="./", fig_path="fig/",
|
||||
fig.tight_layout()
|
||||
fig.savefig(path_to_file/filename)
|
||||
logger.info("Graphique {} sauvé à {}".format(filename, path_to_file))
|
||||
plt.close(fig)
|
||||
return "\includegraphics[scale={sc}]{{{f}}}".format(sc = scale,
|
||||
f=Path(fig_path)/filename)
|
||||
|
||||
|
@ -50,9 +50,12 @@ Compétences
|
||||
|
||||
|
||||
\vfill
|
||||
\Var{e.pies_on_competence | includegraphics(document_path=directory, scale=0.3)}
|
||||
|
||||
\Var{e.pies_on_domaine | includegraphics(document_path=directory, scale=0.3)}
|
||||
\Var{e.heatmap_on_competence | includegraphics(document_path=directory, scale=0.6)}
|
||||
|
||||
\Var{e.heatmap_on_domain | includegraphics(document_path=directory, scale=0.6)}
|
||||
%# \Var{e.pies_on_competence | includegraphics(document_path=directory, scale=0.3)}
|
||||
%# \Var{e.pies_on_domaine | includegraphics(document_path=directory, scale=0.3)}
|
||||
|
||||
|
||||
%#\Var{conn_df}
|
||||
|
@ -102,68 +102,48 @@ class Student(object):
|
||||
@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
|
||||
return pie_pivot_table(self.quest_df,
|
||||
index = "Level",
|
||||
columns = "Competence",
|
||||
values = "Eleve",
|
||||
aggfunc = len,
|
||||
fill_value = 0,
|
||||
)
|
||||
|
||||
@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
|
||||
return pie_pivot_table(self.quest_df,
|
||||
index = "Level",
|
||||
columns = "Domaine",
|
||||
values = "Eleve",
|
||||
aggfunc = len,
|
||||
fill_value = 0,
|
||||
)
|
||||
|
||||
@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,
|
||||
return 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,
|
||||
return 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
|
||||
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()]
|
||||
return sns.heatmap(comp)
|
||||
|
||||
class Classe(object):
|
||||
|
||||
@ -201,45 +181,38 @@ class Classe(object):
|
||||
@property
|
||||
def hist_boxplot(self):
|
||||
""" Marks histogram and associed box plot """
|
||||
try:
|
||||
self._hist_boxplot
|
||||
except AttributeError:
|
||||
self._hist_boxplot = hist_boxplot(self.eval_df)
|
||||
return self._hist_boxplot
|
||||
return hist_boxplot(self.eval_df)
|
||||
|
||||
@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",
|
||||
)
|
||||
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)
|
||||
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[3]:.15} {i[1]} {i[2]}" for i in pv.columns.get_values()]
|
||||
pv.columns = [f"{i[3]:.15} {i[1]} {i[2]}" for i in pv.columns.get_values()]
|
||||
|
||||
self._level_heatmap = sns.heatmap(pv.T)
|
||||
level_heatmap = sns.heatmap(pv.T)
|
||||
|
||||
self._level_heatmap.hlines(exercice_sep,
|
||||
*self._level_heatmap.get_xlim(),
|
||||
colors = "orange",
|
||||
)
|
||||
level_heatmap.hlines(exercice_sep,
|
||||
*self._level_heatmap.get_xlim(),
|
||||
colors = "orange",
|
||||
)
|
||||
return level_heatmap
|
||||
|
||||
return self._level_heatmap
|
||||
|
||||
@property
|
||||
def pies_eff_pts_on_competence(self):
|
||||
|
@ -53,69 +53,60 @@ class Student(object):
|
||||
@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,
|
||||
return 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,
|
||||
return 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,
|
||||
return 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,
|
||||
return 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 = ["Date","Nom"],
|
||||
values = ["Normalized"],
|
||||
aggfunc = np.mean,
|
||||
)
|
||||
comp.columns = [i[1].strftime("%Y-%m-%d") + "\n" + i[2] for i in comp.columns]
|
||||
self._heatmap_on_domain = sns.heatmap(comp)
|
||||
return self._heatmap_on_domain
|
||||
comp = pd.pivot_table(self.quest_df,
|
||||
index = "Domaine",
|
||||
columns = ["Date","Nom"],
|
||||
values = ["Normalized"],
|
||||
aggfunc = np.mean,
|
||||
)
|
||||
comp.columns = [i[1].strftime("%Y-%m-%d") + "\n" + i[2] for i in comp.columns]
|
||||
return sns.heatmap(comp)
|
||||
|
||||
@property
|
||||
def heatmap_on_competence(self):
|
||||
""" Heatmap over evals on competences """
|
||||
comp = pd.pivot_table(self.quest_df,
|
||||
index = "Competence",
|
||||
columns = ["Date","Nom"],
|
||||
values = ["Normalized"],
|
||||
aggfunc = np.mean,
|
||||
)
|
||||
comp.columns = [i[1].strftime("%Y-%m-%d") + "\n" + i[2] for i in comp.columns]
|
||||
return sns.heatmap(comp)
|
||||
|
||||
def parallel_on_evals(self, classe_evals):
|
||||
""" Parallel coordinate plot of the class with student line highlight """
|
||||
|
Loading…
Reference in New Issue
Block a user