From ff94470fb4e171387a4469ee40297f3225d6d18a Mon Sep 17 00:00:00 2001 From: Bertrand Benjamin Date: Tue, 23 Feb 2021 16:14:05 +0100 Subject: [PATCH] Feat: Start feedback on eval --- recopytex/dashboard/create_exam/app.py | 28 ++++++++++++++++++++- recopytex/scripts/exam.py | 35 ++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/recopytex/dashboard/create_exam/app.py b/recopytex/dashboard/create_exam/app.py index 513e1d9..44318ab 100644 --- a/recopytex/dashboard/create_exam/app.py +++ b/recopytex/dashboard/create_exam/app.py @@ -5,6 +5,7 @@ import dash import dash_html_components as html import dash_core_components as dcc import dash_table +import plotly.graph_objects as go from datetime import date, datetime import uuid import pandas as pd @@ -141,7 +142,7 @@ layout = html.Div( id="competences-viz", ), html.Div( - id="domains-viz", + id="themes-viz", ), ], id="visualisation", @@ -316,6 +317,31 @@ def score_rate(data): return [html.P(f"Barème /{exam.score_rate}")] +@app.callback( + dash.dependencies.Output("competences-viz", "figure"), + dash.dependencies.Input("exam_store", "data"), + prevent_initial_call=True, +) +def competences_viz(data): + exam = Exam(**data) + return [html.P(str(exam.competences_rate))] + + +@app.callback( + dash.dependencies.Output("themes-viz", "children"), + dash.dependencies.Input("exam_store", "data"), + prevent_initial_call=True, +) +def themes_viz(data): + exam = Exam(**data) + themes_rate = exam.themes_rate + fig = go.Figure() + if themes_rate: + fig.add_trace(go.Pie(labels=list(themes_rate.keys()), values=list(themes_rate.values()))) + return [dcc.Graph(figure=fig)] + return [] + + @app.callback( dash.dependencies.Output("is-saved", "children"), dash.dependencies.Input("save-csv", "n_clicks"), diff --git a/recopytex/scripts/exam.py b/recopytex/scripts/exam.py index 40296ef..93170e9 100644 --- a/recopytex/scripts/exam.py +++ b/recopytex/scripts/exam.py @@ -165,3 +165,38 @@ class Exam: total += sum([q["score_rate"] for q in questions]) return total + + @property + def competences_rate(self): + """ Dictionnary with competences as key and total rate as value""" + rates = {} + for ex, questions in self._exercises.items(): + for q in questions: + try: + q["competence"] + except KeyError: + pass + else: + try: + rates[q["competence"]] += q["score_rate"] + except KeyError: + rates[q["competence"]] = q["score_rate"] + return rates + + @property + def themes_rate(self): + """ Dictionnary with themes as key and total rate as value""" + rates = {} + for ex, questions in self._exercises.items(): + for q in questions: + try: + q["theme"] + except KeyError: + pass + else: + if q["theme"]: + try: + rates[q["theme"]] += q["score_rate"] + except KeyError: + rates[q["theme"]] = q["score_rate"] + return rates