2016-11-26 13:52:46 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# encoding: utf-8
|
|
|
|
|
|
|
|
from .plottings import radar_graph
|
|
|
|
import pandas as pd
|
|
|
|
import numpy as np
|
|
|
|
|
2017-03-07 11:06:37 +00:00
|
|
|
__all__ = ["radar_on", "marks_hist", "parallele_on"]
|
|
|
|
|
2016-11-26 15:03:03 +00:00
|
|
|
def radar_on(df, index, optimum = None):
|
|
|
|
""" Plot the radar graph concerning index column of the df
|
2016-11-26 13:52:46 +00:00
|
|
|
|
2016-11-26 15:03:03 +00:00
|
|
|
:param df: DataFrame with index and "Normalized" column
|
2016-11-26 13:52:46 +00:00
|
|
|
:returns: exes with radar plot
|
|
|
|
|
|
|
|
"""
|
|
|
|
comp_pt = pd.pivot_table(df,
|
2016-11-26 15:03:03 +00:00
|
|
|
index = [index],
|
2016-11-26 13:52:46 +00:00
|
|
|
values = ["Normalized"],
|
|
|
|
aggfunc=np.mean,
|
|
|
|
)
|
|
|
|
labels = list(comp_pt.index)
|
|
|
|
values = [i[0] for i in comp_pt.values]
|
|
|
|
if optimum is None:
|
|
|
|
optimum = [1]*len(values)
|
|
|
|
fig, ax = radar_graph(labels, values, optimum)
|
|
|
|
return fig, ax
|
|
|
|
|
|
|
|
def marks_hist(df):
|
|
|
|
""" Return axe for the histogramme of the dataframe
|
|
|
|
|
|
|
|
:param df: Dataframe with "Mark" and "Bareme" columns. If it has "Nom" column, it is use in title.
|
|
|
|
"""
|
|
|
|
bareme = df["Bareme"].max()
|
2017-01-31 11:06:45 +00:00
|
|
|
bins = int(bareme*2)
|
2016-11-26 13:52:46 +00:00
|
|
|
|
|
|
|
ax = df["Mark"].hist(bins = bins, range=(0,bareme))
|
|
|
|
|
|
|
|
try:
|
|
|
|
nom = df["Nom"].unique()
|
|
|
|
except KeyError:
|
|
|
|
title="Histogramme"
|
|
|
|
else:
|
|
|
|
title="Histogramme pour {}".format(" ".join(nom))
|
|
|
|
|
|
|
|
ax.set_title(title)
|
|
|
|
|
|
|
|
return ax
|
|
|
|
|
2016-11-26 16:26:47 +00:00
|
|
|
def parallele_on(df, index, student=None):
|
|
|
|
""" Plot parallele one line by student
|
|
|
|
|
|
|
|
:param df: TODO
|
|
|
|
:param index: TODO
|
|
|
|
:returns: TODO
|
|
|
|
|
|
|
|
"""
|
|
|
|
pt = pd.pivot_table(df,
|
|
|
|
index = [index],
|
|
|
|
values = ["Normalized"],
|
|
|
|
columns = ["Eleve"],
|
|
|
|
aggfunc = np.mean,
|
|
|
|
)["Normalized"]
|
|
|
|
ax = pt.plot(color="b", figsize=(10,5), legend=False)
|
|
|
|
pt.T.describe().T[["min", "25%","50%", "75%", "max"]].plot(ax=ax,
|
|
|
|
kind='area', stacked=False, alpha=0.2)
|
|
|
|
if not student is None:
|
|
|
|
pt.ix[:,student].plot(ax=ax, color="r")
|
|
|
|
return ax
|
2016-11-26 13:52:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
# -----------------------------
|
|
|
|
# Reglages pour 'vim'
|
|
|
|
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
|
|
|
# cursor: 16 del
|