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

@ -16,9 +16,9 @@ layout = html.Div(
), ),
html.Main( html.Main(
html.Section( html.Section(
[ children=[
html.Div( html.Div(
[ children=[
"Classe: ", "Classe: ",
dcc.Dropdown( dcc.Dropdown(
id="tribe", id="tribe",
@ -31,46 +31,28 @@ layout = html.Div(
], ],
), ),
html.Div( html.Div(
[ children=[
"Evaluation: ", "Evaluation: ",
dcc.Dropdown(id="exam_select"), 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",
), ),
], ],
id="analysis", id="selects",
),
html.Section(
id="scores_table",
), ),
# html.Section(
# children=[
# html.Div(
# children=[],
# id="final_score_table_container",
# ),
# ],
# id="analysis",
# ),
# html.Section(
# children=[],
# id="scores_table",
# ),
), ),
dcc.Store(id="scores"), dcc.Store(id="scores"),
], ],
) )

View File

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