Feat: basic score_table
This commit is contained in:
parent
6ed55c07d4
commit
2031ade1ab
@ -15,6 +15,7 @@ layout = html.Div(
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
html.Main(
|
html.Main(
|
||||||
|
children=[
|
||||||
html.Section(
|
html.Section(
|
||||||
children=[
|
children=[
|
||||||
html.Div(
|
html.Div(
|
||||||
@ -39,19 +40,28 @@ layout = html.Div(
|
|||||||
],
|
],
|
||||||
id="selects",
|
id="selects",
|
||||||
),
|
),
|
||||||
# html.Section(
|
html.Section(
|
||||||
# children=[
|
children=[
|
||||||
# html.Div(
|
html.Div(
|
||||||
# children=[],
|
children=[],
|
||||||
# id="final_score_table_container",
|
id="final_score_table_container",
|
||||||
# ),
|
),
|
||||||
# ],
|
],
|
||||||
# id="analysis",
|
id="analysis",
|
||||||
# ),
|
),
|
||||||
# html.Section(
|
html.Section(
|
||||||
# children=[],
|
children=[
|
||||||
# id="scores_table",
|
dash_table.DataTable(
|
||||||
# ),
|
id="scores_table",
|
||||||
|
columns=[],
|
||||||
|
style_data_conditional=[],
|
||||||
|
fixed_columns={},
|
||||||
|
editable=True,
|
||||||
|
)
|
||||||
|
],
|
||||||
|
id="edit",
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
dcc.Store(id="scores"),
|
dcc.Store(id="scores"),
|
||||||
],
|
],
|
||||||
|
@ -1,14 +1,15 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
|
|
||||||
from dash.dependencies import Input, Output
|
from dash.dependencies import Input, Output, State
|
||||||
|
import dash
|
||||||
from dash.exceptions import PreventUpdate
|
from dash.exceptions import PreventUpdate
|
||||||
import dash_table
|
import dash_table
|
||||||
import json
|
import json
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
|
||||||
from ...app import app
|
from ...app import app
|
||||||
from .models import get_tribes, get_exams, get_scores
|
from .models import get_tribes, get_exams, get_unstack_scores, get_students_from_exam
|
||||||
|
|
||||||
|
|
||||||
@app.callback(
|
@app.callback(
|
||||||
@ -18,10 +19,10 @@ from .models import get_tribes, get_exams, get_scores
|
|||||||
],
|
],
|
||||||
[Input("tribe", "value")],
|
[Input("tribe", "value")],
|
||||||
)
|
)
|
||||||
def update_exams_choices(value):
|
def update_exams_choices(tribe):
|
||||||
if not value:
|
if not tribe:
|
||||||
raise PreventUpdate
|
raise PreventUpdate
|
||||||
exams = get_exams(value)
|
exams = get_exams(tribe)
|
||||||
exams.reset_index(inplace=True)
|
exams.reset_index(inplace=True)
|
||||||
if not exams.empty:
|
if not exams.empty:
|
||||||
return [
|
return [
|
||||||
@ -29,39 +30,38 @@ def update_exams_choices(value):
|
|||||||
], exams.loc[0].to_json()
|
], exams.loc[0].to_json()
|
||||||
return [], None
|
return [], None
|
||||||
|
|
||||||
|
|
||||||
@app.callback(
|
@app.callback(
|
||||||
[Output("scores", "data")],
|
[
|
||||||
[Input("exam_select", "value")]
|
Output("scores_table", "columns"),
|
||||||
|
Output("scores_table", "data"),
|
||||||
|
Output("scores_table", "style_data_conditional"),
|
||||||
|
Output("scores_table", "fixed_columns"),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
Input("exam_select", "value"),
|
||||||
|
],
|
||||||
)
|
)
|
||||||
def update_scores_store(value):
|
def update_scores_store(exam):
|
||||||
if not value:
|
ctx = dash.callback_context
|
||||||
return [[]]
|
if not exam:
|
||||||
exam = pd.DataFrame.from_dict([json.loads(value)])
|
return [[], [], [], {}]
|
||||||
return [get_scores(exam)]
|
exam = pd.DataFrame.from_dict([json.loads(exam)])
|
||||||
|
scores = get_unstack_scores(exam, "score", "student_name")
|
||||||
|
fixed_columns = [
|
||||||
|
"exercise",
|
||||||
|
"question",
|
||||||
|
"competence",
|
||||||
|
"theme",
|
||||||
|
"comment",
|
||||||
|
"score_rate",
|
||||||
|
"is_leveled",
|
||||||
|
]
|
||||||
|
columns = fixed_columns + list(get_students_from_exam(exam))
|
||||||
|
|
||||||
|
return [
|
||||||
|
[{"id": c, "name": c} for c in columns],
|
||||||
|
scores.to_dict("records"),
|
||||||
# @app.callback(
|
[],
|
||||||
# [
|
{"headers": True, "data": len(fixed_columns)},
|
||||||
# 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")]
|
|
||||||
|
@ -14,5 +14,21 @@ def get_exams(tribe):
|
|||||||
return LOADER.get_exams([tribe])
|
return LOADER.get_exams([tribe])
|
||||||
|
|
||||||
|
|
||||||
def get_scores(exam):
|
def get_record_scores(exam):
|
||||||
return LOADER.get_exam_scores(exam).to_dict('records')
|
return LOADER.get_exam_scores(exam)
|
||||||
|
|
||||||
|
|
||||||
|
def get_unstack_scores(exam, value_column="score", unstack_column="student_name"):
|
||||||
|
flat_scores = LOADER.get_exam_scores(exam)
|
||||||
|
pivot_columns = [col for col in LOADER.score_columns if col != value_column]
|
||||||
|
unstacked_df = (
|
||||||
|
flat_scores.set_index(pivot_columns)[value_column]
|
||||||
|
.unstack(unstack_column)
|
||||||
|
.reset_index()
|
||||||
|
)
|
||||||
|
return unstacked_df
|
||||||
|
|
||||||
|
|
||||||
|
def get_students_from_exam(exam):
|
||||||
|
flat_scores = LOADER.get_exam_scores(exam)
|
||||||
|
return flat_scores["student_name"].unique()
|
||||||
|
Loading…
Reference in New Issue
Block a user