Feat: store exams_scores in store
This commit is contained in:
parent
0739cfdae7
commit
646314ad88
@ -7,70 +7,52 @@ from .models import get_tribes, get_exams
|
|||||||
from .callbacks import *
|
from .callbacks import *
|
||||||
|
|
||||||
layout = html.Div(
|
layout = html.Div(
|
||||||
children=[
|
children=[
|
||||||
html.Header(
|
html.Header(
|
||||||
children=[
|
children=[
|
||||||
html.H1("Analyse des notes"),
|
html.H1("Analyse des notes"),
|
||||||
html.P("Dernière sauvegarde", id="lastsave"),
|
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",
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
id="analysis",
|
),
|
||||||
),
|
html.Main(
|
||||||
html.Section(
|
html.Section(
|
||||||
id="scores_table",
|
children=[
|
||||||
),
|
html.Div(
|
||||||
),
|
children=[
|
||||||
dcc.Store(id="scores"),
|
"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"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
@ -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")]
|
||||||
|
@ -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')
|
||||||
|
Loading…
Reference in New Issue
Block a user