Feat: start analysis dash board

This commit is contained in:
Bertrand Benjamin 2021-01-10 20:46:14 +01:00
parent 27d7c45980
commit 8fcad94df4
2 changed files with 129 additions and 0 deletions

View File

@ -0,0 +1,125 @@
#!/usr/bin/env python
# encoding: utf-8
import dash
import dash_html_components as html
import dash_core_components as dcc
import dash_table
from dash.exceptions import PreventUpdate
from pathlib import Path
import pandas as pd
from .. import flat_df_students, pp_q_scores
from .getconfig import config, CONFIGPATH
COLORS = {
".": "black",
0: "#E7472B",
1: "#FF712B",
2: "#F2EC4C",
3: "#68D42F",
}
app = dash.Dash(__name__)
app.layout = html.Div([
html.H1("Coucou"),
html.Div(["Classe: ", dcc.Dropdown(
id='tribe',
options=[{"label": t["name"], "value": t["name"]} for t in config["tribes"]],
value=config["tribes"][0]["name"],
)]),
html.Div(["Evaluation: ", dcc.Dropdown(id='exam')]),
html.Div([dash_table.DataTable(
id="final_score_table",
columns = [{"id": "Élève", "name": "Élève"}, {"id": "Note", "name": "Note"},{"id": "Barème", "name": "Bareme"}],
data=[],
style_data_conditional=[
{
'if': {'row_index': 'odd'},
'backgroundColor': 'rgb(248, 248, 248)'
}
],
style_header={
'backgroundColor': 'rgb(230, 230, 230)',
'fontWeight': 'bold'
},
style_data={
'width': '100px',
'maxWidth': '100px',
'minWidth': '100px',
},
),
]),
html.Br(),
html.Div([dash_table.DataTable(
id="scores_table",
columns = [{"id": "plop", "name": "popo"}],
style_cell={
'whiteSpace': 'normal',
'height': 'auto',
},
style_data_conditional=[]
)]),
])
@app.callback(
[dash.dependencies.Output("exam", "options"), dash.dependencies.Output("exam", "value")],
[dash.dependencies.Input("tribe", "value")],
)
def update_exams(value):
if not value:
raise PreventUpdate
p = Path(value)
csvs = list(p.glob("*.csv"))
return [{"label": str(c), "value": str(c)} for c in csvs], str(csvs[0])
@app.callback(
[dash.dependencies.Output("final_score_table", "columns"), dash.dependencies.Output("final_score_table", "data")],
[dash.dependencies.Input("exam", "value")],
)
def update_scores_table(value):
if not value:
raise PreventUpdate
try:
scores = pd.read_csv(value, encoding="UTF8")
comments = scores.iloc[0]
scores.drop([0], inplace=True)
scores = flat_df_students(scores).dropna(subset=["Score"])
scores = pp_q_scores(scores)
assessment_scores = scores.groupby(["Eleve"]).agg({"Note": "sum", "Bareme": "sum"})
return [{"id": c, "name": c} for c in assessment_scores.reset_index().columns], assessment_scores.reset_index().to_dict('records')
except KeyError:
raise PreventUpdate
def highlight_value(df):
""" Cells style """
hight = []
for v, color in COLORS.items():
hight +=[
{
'if': {
'filter_query': '{{{}}} = {}'.format(col, v),
'column_id': col
},
'backgroundColor': color,
'color': 'white'
} for col in df.columns if col not in ["Exercice", "Question", "Commentaire"]
]
return hight
@app.callback(
[dash.dependencies.Output("scores_table", "columns"), dash.dependencies.Output("scores_table", "data"), dash.dependencies.Output("scores_table", "style_data_conditional"), ],
[dash.dependencies.Input("exam", "value")],
)
def update_scores_table(value):
if not value:
raise PreventUpdate
scores = pd.read_csv(value, encoding="UTF8")
try:
stack = scores.drop(columns=["Nom", "Trimestre", "Date", "Competence", "Domaine", "Est_nivele", "Bareme"])
except KeyError:
stack = scores
return [{"id": c, "name": c} for c in stack.columns], stack.to_dict('records'), highlight_value(stack)

View File

@ -13,6 +13,7 @@ from .getconfig import config, CONFIGPATH
from .prompts import prompt_exam, prompt_exercise, prompt_validate
from ..config import NO_ST_COLUMNS
from .exam import Exam
from .exam_dash import app as exam_app
@click.group()
@ -84,6 +85,9 @@ def new_exam():
base_df.to_csv(exam.path(".csv"), index=False)
print(f"Le fichier note a été enregistré à {exam.path('.csv')}")
@cli.command()
def exam_analysis():
exam_app.run_server(debug=True)
@cli.command()
@click.argument("csv_file")