Feat: add competence bar plot

This commit is contained in:
Bertrand Benjamin 2021-01-13 08:28:54 +01:00
parent f6bfac4144
commit 894ebc4ec8
1 changed files with 45 additions and 2 deletions

View File

@ -30,7 +30,7 @@ app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
# app = dash.Dash(__name__)
app.layout = html.Div(
[
children=[
html.H1("Analyse des notes"),
html.Div(
[
@ -80,6 +80,7 @@ app.layout = html.Div(
id="final_score_describe",
),
dcc.Graph(id="fig_assessment_hist"),
dcc.Graph(id="fig_competences"),
]
),
],
@ -168,7 +169,6 @@ def update_final_scores_table(data):
)
def update_final_scores_descr(data):
desc = pd.DataFrame.from_records(data)["Note"].describe()
print(desc.keys())
return [{"id": c, "name": c} for c in desc.keys()], [desc.to_dict()]
@ -202,6 +202,49 @@ def update_final_scores_hist(data):
)
return [fig]
@app.callback(
[
dash.dependencies.Output("fig_competences", "figure"),
],
[dash.dependencies.Input("scores_table", "data")],
)
def update_competence_fig(data):
scores = pd.DataFrame.from_records(data)
scores = flat_df_students(scores).dropna(subset=["Score"])
scores = pp_q_scores(scores)
pt = pd.pivot_table(
scores,
index=["Exercice", "Question", "Commentaire"],
columns="Score",
aggfunc="size",
fill_value=0,
)
for i in {i for i in pt.index.get_level_values(0)}:
pt.loc[(str(i), "", ""), :] = ""
pt.sort_index(inplace=True)
index = (
pt.index.get_level_values(0)
+ ":"
+ pt.index.get_level_values(1)
+ " "
+ pt.index.get_level_values(2)
)
fig = go.Figure()
bars = [
{"score": -1, "name":"Pas de réponse", "color": COLORS["."]},
{"score": 0, "name":"Faut", "color": COLORS[0]},
{"score": 1, "name":"Peu juste", "color": COLORS[1]},
{"score": 2, "name":"Presque juste", "color": COLORS[2]},
{"score": 3, "name":"Juste", "color": COLORS[3]},
]
for b in bars:
try:
fig.add_bar(x=index, y=pt[b["score"]], name=b["name"], marker_color=b["color"])
except KeyError:
pass
fig.update_layout(barmode="relative")
return [fig]
@app.callback(
[dash.dependencies.Output("lastsave", "children")],