Feat: add competence fig and better error management
This commit is contained in:
parent
0a5a931d01
commit
09ac9f01f8
@ -75,7 +75,7 @@ app.layout = html.Div(
|
|||||||
columns=[
|
columns=[
|
||||||
{"id": "Élève", "name": "Élève"},
|
{"id": "Élève", "name": "Élève"},
|
||||||
{"id": "Note", "name": "Note"},
|
{"id": "Note", "name": "Note"},
|
||||||
{"id": "Barème", "name": "Bareme"},
|
{"id": "Barème", "name": "Barème"},
|
||||||
],
|
],
|
||||||
data=[],
|
data=[],
|
||||||
style_data_conditional=[
|
style_data_conditional=[
|
||||||
@ -99,11 +99,21 @@ app.layout = html.Div(
|
|||||||
[
|
[
|
||||||
dash_table.DataTable(
|
dash_table.DataTable(
|
||||||
id="final_score_describe",
|
id="final_score_describe",
|
||||||
|
columns=[{"id": "count", "name": "count"},
|
||||||
|
{"id": "mean", "name": "mean"},
|
||||||
|
{"id": "std", "name": "std"},
|
||||||
|
{"id": "min", "name": "min"},
|
||||||
|
{"id": "25%", "name": "25%"},
|
||||||
|
{"id": "50%", "name": "50%"},
|
||||||
|
{"id": "75%", "name": "75%"},
|
||||||
|
{"id": "max", "name": "max"},
|
||||||
|
]
|
||||||
|
|
||||||
),
|
),
|
||||||
dcc.Graph(
|
dcc.Graph(
|
||||||
id="fig_assessment_hist",
|
id="fig_assessment_hist",
|
||||||
),
|
),
|
||||||
# dcc.Graph(id="fig_competences"),
|
dcc.Graph(id="fig_competences"),
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@ -156,42 +166,47 @@ def update_csvs(value):
|
|||||||
def update_final_scores(data):
|
def update_final_scores(data):
|
||||||
if not data:
|
if not data:
|
||||||
raise PreventUpdate
|
raise PreventUpdate
|
||||||
|
|
||||||
|
scores = pd.DataFrame.from_records(data)
|
||||||
try:
|
try:
|
||||||
scores = pd.DataFrame.from_records(data)
|
if scores.iloc[0]["Commentaire"] == "commentaire":
|
||||||
scores = flat_df_students(scores).dropna(subset=["Score"])
|
scores.drop([0], inplace=True)
|
||||||
scores = pp_q_scores(scores)
|
|
||||||
assessment_scores = scores.groupby(["Eleve"]).agg(
|
|
||||||
{"Note": "sum", "Bareme": "sum"}
|
|
||||||
)
|
|
||||||
return [assessment_scores.reset_index().to_dict("records")]
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise PreventUpdate
|
pass
|
||||||
|
scores = flat_df_students(scores).dropna(subset=["Score"])
|
||||||
|
if scores.empty:
|
||||||
|
return [{}]
|
||||||
|
|
||||||
|
scores = pp_q_scores(scores)
|
||||||
|
assessment_scores = scores.groupby(["Eleve"]).agg(
|
||||||
|
{"Note": "sum", "Bareme": "sum"}
|
||||||
|
)
|
||||||
|
return [assessment_scores.reset_index().to_dict("records")]
|
||||||
|
|
||||||
|
|
||||||
@app.callback(
|
@app.callback(
|
||||||
[
|
[
|
||||||
dash.dependencies.Output("final_score_table", "columns"),
|
|
||||||
dash.dependencies.Output("final_score_table", "data"),
|
dash.dependencies.Output("final_score_table", "data"),
|
||||||
],
|
],
|
||||||
[dash.dependencies.Input("final_score", "data")],
|
[dash.dependencies.Input("final_score", "data")],
|
||||||
)
|
)
|
||||||
def update_final_scores_table(data):
|
def update_final_scores_table(data):
|
||||||
assessment_scores = pd.DataFrame.from_records(data)
|
assessment_scores = pd.DataFrame.from_records(data)
|
||||||
return [
|
return [assessment_scores.to_dict("records")]
|
||||||
{"id": c, "name": c} for c in assessment_scores.columns
|
|
||||||
], assessment_scores.to_dict("records")
|
|
||||||
|
|
||||||
|
|
||||||
@app.callback(
|
@app.callback(
|
||||||
[
|
[
|
||||||
dash.dependencies.Output("final_score_describe", "columns"),
|
|
||||||
dash.dependencies.Output("final_score_describe", "data"),
|
dash.dependencies.Output("final_score_describe", "data"),
|
||||||
],
|
],
|
||||||
[dash.dependencies.Input("final_score", "data")],
|
[dash.dependencies.Input("final_score", "data")],
|
||||||
)
|
)
|
||||||
def update_final_scores_descr(data):
|
def update_final_scores_descr(data):
|
||||||
desc = pd.DataFrame.from_records(data)["Note"].describe()
|
scores = pd.DataFrame.from_records(data)
|
||||||
return [{"id": c, "name": c} for c in desc.keys()], [desc.to_dict()]
|
if scores.empty:
|
||||||
|
return [[{}]]
|
||||||
|
desc = scores["Note"].describe().T
|
||||||
|
return [[desc.to_dict()]]
|
||||||
|
|
||||||
|
|
||||||
@app.callback(
|
@app.callback(
|
||||||
@ -203,6 +218,9 @@ def update_final_scores_descr(data):
|
|||||||
def update_final_scores_hist(data):
|
def update_final_scores_hist(data):
|
||||||
assessment_scores = pd.DataFrame.from_records(data)
|
assessment_scores = pd.DataFrame.from_records(data)
|
||||||
|
|
||||||
|
if assessment_scores.empty:
|
||||||
|
return [{}]
|
||||||
|
|
||||||
ranges = np.linspace(
|
ranges = np.linspace(
|
||||||
0, assessment_scores.Bareme.max(), int(assessment_scores.Bareme.max() * 2 + 1)
|
0, assessment_scores.Bareme.max(), int(assessment_scores.Bareme.max() * 2 + 1)
|
||||||
)
|
)
|
||||||
@ -230,51 +248,64 @@ def update_final_scores_hist(data):
|
|||||||
return [fig]
|
return [fig]
|
||||||
|
|
||||||
|
|
||||||
# @app.callback(
|
@app.callback(
|
||||||
# [
|
[
|
||||||
# dash.dependencies.Output("fig_competences", "figure"),
|
dash.dependencies.Output("fig_competences", "figure"),
|
||||||
# ],
|
],
|
||||||
# [dash.dependencies.Input("scores_table", "data")],
|
[dash.dependencies.Input("scores_table", "data")],
|
||||||
# )
|
)
|
||||||
# def update_competence_fig(data):
|
def update_competence_fig(data):
|
||||||
# scores = pd.DataFrame.from_records(data)
|
scores = pd.DataFrame.from_records(data)
|
||||||
# scores = flat_df_students(scores).dropna(subset=["Score"])
|
try:
|
||||||
# scores = pp_q_scores(scores)
|
if scores.iloc[0]["Commentaire"] == "commentaire":
|
||||||
# pt = pd.pivot_table(
|
scores.drop([0], inplace=True)
|
||||||
# scores,
|
except KeyError:
|
||||||
# index=["Exercice", "Question", "Commentaire"],
|
pass
|
||||||
# columns="Score",
|
scores = flat_df_students(scores).dropna(subset=["Score"])
|
||||||
# aggfunc="size",
|
|
||||||
# fill_value=0,
|
if scores.empty:
|
||||||
# )
|
return [{}]
|
||||||
# for i in {i for i in pt.index.get_level_values(0)}:
|
|
||||||
# pt.loc[(str(i), "", ""), :] = ""
|
scores = pp_q_scores(scores)
|
||||||
# pt.sort_index(inplace=True)
|
pt = pd.pivot_table(
|
||||||
# index = (
|
scores,
|
||||||
# pt.index.get_level_values(0)
|
index=["Exercice", "Question", "Commentaire"],
|
||||||
# + ":"
|
columns="Score",
|
||||||
# + pt.index.get_level_values(1)
|
aggfunc="size",
|
||||||
# + " "
|
fill_value=0,
|
||||||
# + pt.index.get_level_values(2)
|
)
|
||||||
# )
|
for i in {i for i in pt.index.get_level_values(0)}:
|
||||||
#
|
pt.loc[(str(i), "", ""), :] = ""
|
||||||
# fig = go.Figure()
|
pt.sort_index(inplace=True)
|
||||||
# bars = [
|
index = (
|
||||||
# {"score": -1, "name": "Pas de réponse", "color": COLORS["."]},
|
pt.index.get_level_values(0)
|
||||||
# {"score": 0, "name": "Faut", "color": COLORS[0]},
|
+ ":"
|
||||||
# {"score": 1, "name": "Peu juste", "color": COLORS[1]},
|
+ pt.index.get_level_values(1)
|
||||||
# {"score": 2, "name": "Presque juste", "color": COLORS[2]},
|
+ " "
|
||||||
# {"score": 3, "name": "Juste", "color": COLORS[3]},
|
+ pt.index.get_level_values(2)
|
||||||
# ]
|
)
|
||||||
# for b in bars:
|
|
||||||
# try:
|
fig = go.Figure()
|
||||||
# fig.add_bar(
|
bars = [
|
||||||
# x=index, y=pt[b["score"]], name=b["name"], marker_color=b["color"]
|
{"score": -1, "name": "Pas de réponse", "color": COLORS["."]},
|
||||||
# )
|
{"score": 0, "name": "Faut", "color": COLORS[0]},
|
||||||
# except KeyError:
|
{"score": 1, "name": "Peu juste", "color": COLORS[1]},
|
||||||
# pass
|
{"score": 2, "name": "Presque juste", "color": COLORS[2]},
|
||||||
# fig.update_layout(barmode="relative")
|
{"score": 3, "name": "Juste", "color": COLORS[3]},
|
||||||
# return [fig]
|
]
|
||||||
|
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")
|
||||||
|
fig.update_layout(
|
||||||
|
height=500,
|
||||||
|
margin=dict(l=5, r=5, b=5, t=5),
|
||||||
|
)
|
||||||
|
return [fig]
|
||||||
|
|
||||||
|
|
||||||
@app.callback(
|
@app.callback(
|
||||||
|
Loading…
Reference in New Issue
Block a user