Feat: store exams_scores in store

This commit is contained in:
Bertrand Benjamin 2021-04-18 10:50:26 +02:00
parent 0739cfdae7
commit 646314ad88
3 changed files with 89 additions and 90 deletions

View File

@ -7,70 +7,52 @@ from .models import get_tribes, get_exams
from .callbacks import *
layout = html.Div(
children=[
html.Header(
children=[
html.H1("Analyse des notes"),
html.P("Dernière sauvegarde", id="lastsave"),
],
),
html.Main(
html.Section(
[
html.Div(
[
"Classe: ",
dcc.Dropdown(
id="tribe",
options=[
{"label": t["name"], "value": t["name"]}
for t in get_tribes().values()
],
value=next(iter(get_tribes().values()))["name"],
),
],
),
html.Div(
[
"Evaluation: ",
dcc.Dropdown(id="exam_select"),
],
html.P(id="test"),
],
id="select",
),
html.Section(
[
html.Div(
dash_table.DataTable(
id="final_score_table",
columns=[
{"id": "Eleve", "name": "Élève"},
{"id": "Note", "name": "Note"},
{"id": "Bareme", "name": "Barème"},
],
data=[],
style_data_conditional=[
{
"if": {"row_index": "odd"},
"backgroundColor": "rgb(248, 248, 248)",
}
],
style_data={
"width": "100px",
"maxWidth": "100px",
"minWidth": "100px",
},
),
id="final_score_table_container",
),
children=[
html.Header(
children=[
html.H1("Analyse des notes"),
html.P("Dernière sauvegarde", id="lastsave"),
],
id="analysis",
),
html.Section(
id="scores_table",
),
),
dcc.Store(id="scores"),
],
)
),
html.Main(
html.Section(
children=[
html.Div(
children=[
"Classe: ",
dcc.Dropdown(
id="tribe",
options=[
{"label": t["name"], "value": t["name"]}
for t in get_tribes().values()
],
value=next(iter(get_tribes().values()))["name"],
),
],
),
html.Div(
children=[
"Evaluation: ",
dcc.Dropdown(id="exam_select"),
],
),
],
id="selects",
),
# html.Section(
# children=[
# html.Div(
# children=[],
# id="final_score_table_container",
# ),
# ],
# id="analysis",
# ),
# html.Section(
# children=[],
# id="scores_table",
# ),
),
dcc.Store(id="scores"),
],
)

View File

@ -3,9 +3,12 @@
from dash.dependencies import Input, Output
from dash.exceptions import PreventUpdate
import dash_table
import json
import pandas as pd
from ...app import app
from .models import get_tribes, get_exams
from .models import get_tribes, get_exams, get_scores
@app.callback(
@ -15,39 +18,50 @@ from .models import get_tribes, get_exams
],
[Input("tribe", "value")],
)
def update_csvs(value):
def update_exams_choices(value):
if not value:
raise PreventUpdate
exams = get_exams(value)
exams.reset_index(inplace=True)
print(exams.loc[0, "name"])
if not exams.empty:
return [
{"label": e["name"], "value": e.to_json()} for i, e in exams.iterrows()
], exams.loc[0].to_json()
return [], None
@app.callback(
[
dash.dependencies.Output("final_score", "data"),
],
[dash.dependencies.Input("scores_table", "data")],
)
def update_final_scores(data):
if not data:
raise PreventUpdate
[Output("scores", "data")],
[Input("exam_select", "value")]
)
def update_scores_store(value):
if not value:
return [[]]
exam = pd.DataFrame.from_dict([json.loads(value)])
return [get_scores(exam)]
scores = pd.DataFrame.from_records(data)
try:
if scores.iloc[0]["Commentaire"] == "commentaire":
scores.drop([0], inplace=True)
except KeyError:
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(
# [
# Output("final_score", "data"),
# ],
# [Input("scores_table", "data")],
# )
# def update_final_scores(data):
# if not data:
# raise PreventUpdate
#
# scores = pd.DataFrame.from_records(data)
# try:
# if scores.iloc[0]["Commentaire"] == "commentaire":
# scores.drop([0], inplace=True)
# except KeyError:
# 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")]

View File

@ -13,3 +13,6 @@ def get_tribes():
def get_exams(tribe):
return LOADER.get_exams([tribe])
def get_scores(exam):
return LOADER.get_exam_scores(exam).to_dict('records')