Compare commits

..

3 Commits

Author SHA1 Message Date
8cdeecfc53 Feat: Score histogram 2021-04-20 19:13:14 +02:00
1a7c97d869 Feat: statistics table 2021-04-20 19:04:06 +02:00
ab5de2711e Feat: score_table style 2021-04-20 18:48:52 +02:00
2 changed files with 91 additions and 3 deletions

View File

@ -55,6 +55,23 @@ layout = html.Div(
],
id="final_score_table_container",
),
html.Div(
children=[
dash_table.DataTable(
id="score_statistics_table",
columns=[],
)
],
id="score_statistics_table_container",
),
html.Div(
children=[
dcc.Graph(
id="fig_exam_histo",
)
],
id="fig_exam_histo_container",
),
],
id="analysis",
),
@ -66,6 +83,14 @@ layout = html.Div(
style_data_conditional=[],
fixed_columns={},
editable=True,
style_table={"minWidth": "100%"},
style_cell={
"minWidth": "100px",
"width": "100px",
"maxWidth": "100px",
"overflow": "hidden",
"textOverflow": "ellipsis",
},
)
],
id="edit",

View File

@ -2,11 +2,12 @@
# encoding: utf-8
from dash.dependencies import Input, Output, State
import dash
from dash.exceptions import PreventUpdate
import plotly.graph_objects as go
import dash_table
import json
import pandas as pd
import numpy as np
from recopytex.dashboard.app import app
from recopytex.dashboard.common.formating import highlight_scores
@ -52,7 +53,6 @@ def update_exams_choices(tribe):
],
)
def update_scores_store(exam):
ctx = dash.callback_context
if not exam:
return [[], [], [], {}]
exam = pd.DataFrame.from_dict([json.loads(exam)])
@ -88,7 +88,70 @@ def update_scores_store(exam):
Input("scores_table", "data"),
],
)
def update_scores_store(scores):
def update_finale_score_table(scores):
scores_df = pd.DataFrame.from_records(scores)
# print(scores_df)
return score_to_final_mark(scores_df)
@app.callback(
[
Output("score_statistics_table", "columns"),
Output("score_statistics_table", "data"),
],
[
Input("final_score_table", "data"),
],
)
def update_statictics_table(finale_score):
df = pd.DataFrame.from_records(finale_score)
statistics = df["mark"].describe().to_frame().T
print(statistics)
return [
[{"id": c, "name": c} for c in statistics.columns],
statistics.to_dict("records"),
]
@app.callback(
[
Output("fig_exam_histo", "figure"),
],
[
Input("final_score_table", "data"),
],
)
def update_exam_histo(finale_scores):
scores = pd.DataFrame.from_records(finale_scores)
if scores.empty:
return [go.Figure(data=[go.Scatter(x=[], y=[])])]
ranges = np.linspace(
-0.5,
scores["score_rate"].max(),
int(scores["score_rate"].max() * 2 + 2),
)
bins = pd.cut(scores["mark"], ranges)
scores["Bin"] = bins
grouped = (
scores.reset_index()
.groupby("Bin")
.agg({"score_rate": "count", "student_name": lambda x: "\n".join(x)})
)
grouped.index = grouped.index.map(lambda i: i.right)
fig = go.Figure()
fig.add_bar(
x=grouped.index,
y=grouped["score_rate"],
text=grouped["student_name"],
textposition="auto",
hovertemplate="",
marker_color="#4E89DE",
)
fig.update_layout(
height=300,
margin=dict(l=5, r=5, b=5, t=5),
)
return [fig]