Feat: visualisation des Competences et des themes dans students

This commit is contained in:
Bertrand Benjamin 2021-02-27 10:31:52 +01:00
parent d9e95f2186
commit c84f9845b2

View File

@ -18,10 +18,19 @@ from ...config import NO_ST_COLUMNS
from ..app import app from ..app import app
from ...scripts.exam import Exam from ...scripts.exam import Exam
def get_students(csv): def get_students(csv):
return list(pd.read_csv(csv).T.to_dict().values()) return list(pd.read_csv(csv).T.to_dict().values())
COLORS = {
".": "black",
0: "#E7472B",
1: "#FF712B",
2: "#F2EC4C",
3: "#68D42F",
}
QUESTION_COLUMNS = [ QUESTION_COLUMNS = [
{"id": "id", "name": "Question"}, {"id": "id", "name": "Question"},
{ {
@ -119,9 +128,6 @@ layout = html.Div(
), ),
id="eval-table", id="eval-table",
), ),
html.Div(
id="describe",
),
], ],
id="Évaluations", id="Évaluations",
), ),
@ -131,7 +137,7 @@ layout = html.Div(
id="competences-viz", id="competences-viz",
), ),
html.Div( html.Div(
id="themes-viz", id="themes-vizz",
), ),
], ],
id="visualisation", id="visualisation",
@ -213,5 +219,85 @@ def update_exam_scores(data):
scores = pp_q_scores(scores) scores = pp_q_scores(scores)
assessment_scores = scores.groupby(["Nom"]).agg({"Note": "sum", "Bareme": "sum"}) assessment_scores = scores.groupby(["Nom"]).agg({"Note": "sum", "Bareme": "sum"})
return [assessment_scores.reset_index().to_dict("records")] return [assessment_scores.reset_index().to_dict("records")]
return [{}]
@app.callback(
[
dash.dependencies.Output("competences-viz", "children"),
],
[
dash.dependencies.Input("student-scores", "data"),
],
)
def update_competences_viz(data):
scores = pd.DataFrame.from_records(data)
scores = pp_q_scores(scores)
pt = pd.pivot_table(
scores,
index=["Competence"],
columns="Score",
aggfunc="size",
fill_value=0,
)
fig = go.Figure()
bars = [
{"score": -1, "name": "Pas de réponse", "color": COLORS["."]},
{"score": 0, "name": "Faux", "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=list(config["competences"].keys()), 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 [dcc.Graph(figure=fig)]
@app.callback(
[
dash.dependencies.Output("themes-vizz", "children"),
],
[
dash.dependencies.Input("student-scores", "data"),
],
)
def update_themes_viz(data):
scores = pd.DataFrame.from_records(data)
scores = pp_q_scores(scores)
pt = pd.pivot_table(
scores,
index=["Domaine"],
columns="Score",
aggfunc="size",
fill_value=0,
)
fig = go.Figure()
bars = [
{"score": -1, "name": "Pas de réponse", "color": COLORS["."]},
{"score": 0, "name": "Faux", "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=list(pt.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 [dcc.Graph(figure=fig)]