Feat: filter dans store scores

This commit is contained in:
Bertrand Benjamin 2021-02-23 17:40:18 +01:00
parent b5bf1ac137
commit 3dbfc85447

View File

@ -10,8 +10,10 @@ from datetime import date, datetime
import uuid
import pandas as pd
import yaml
from pathlib import Path
from ...scripts.getconfig import config
from ... import flat_df_students, pp_q_scores
from ...config import NO_ST_COLUMNS
from ..app import app
from ...scripts.exam import Exam
@ -117,9 +119,11 @@ layout = html.Div(
]
),
dcc.Store(id="student-scores"),
html.P(id="test"),
]
)
@app.callback(
[
dash.dependencies.Output("student", "options"),
@ -131,22 +135,61 @@ layout = html.Div(
def update_students_list(tribe):
tribe_config = [t for t in config["tribes"] if t["name"] == tribe][0]
students = get_students(tribe_config["students"])
options=[
options = [
{"label": t["Nom"], "value": t["Nom"]}
for t in students
]
value=students[0]["Nom"]
value = students[0]["Nom"]
return options, value
# @app.callback(
# [
# dash.dependencies.Output("student-scores", "data"),
# ],
# [
# dash.dependencies.Input("tribe", "value"),
# dash.dependencies.Input("student", "value"),
# dash.dependencies.Input("term", "value"),
# ],
# )
# def update_student_scores(tribe, student, term):
# return []
@app.callback(
[
dash.dependencies.Output("student-scores", "data"),
],
[
dash.dependencies.Input("tribe", "value"),
dash.dependencies.Input("student", "value"),
dash.dependencies.Input("term", "value"),
],
)
def update_student_scores(tribe, student, term):
tribe_config = [t for t in config["tribes"] if t["name"] == tribe][0]
p = Path(tribe_config["name"])
csvs = list(p.glob("*.csv"))
dfs = []
for csv in csvs:
try:
scores = pd.read_csv(csv)
except pd.errors.ParserError:
pass
else:
try:
if scores.iloc[0]["Commentaire"] == "commentaire":
scores.drop([0], inplace=True)
except KeyError:
pass
scores = flat_df_students(scores).dropna(subset=["Score"])
scores = scores[scores["Eleve"] == student]
scores = scores[scores["Trimestre"] == term]
dfs.append(scores)
df = pd.concat(dfs)
return [df.to_dict("records")]
@app.callback(
[
dash.dependencies.Output("test", "children"),
],
[
dash.dependencies.Input("student-scores", "data"),
],
)
def update_test(data):
return [str(data)]