Feat: score table color formating based on score
This commit is contained in:
parent
effc049578
commit
7553628306
23
recopytex/dashboard/common/formating.py
Normal file
23
recopytex/dashboard/common/formating.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# encoding: utf-8
|
||||||
|
|
||||||
|
|
||||||
|
def highlight_scores(highlight_columns, score_color):
|
||||||
|
""" Cells style in a datatable for scores
|
||||||
|
|
||||||
|
:param highlight_columns: columns to highlight
|
||||||
|
:param value_color: dictionnary {"score": "color"}
|
||||||
|
|
||||||
|
"""
|
||||||
|
hight = []
|
||||||
|
for v, color in score_color.items():
|
||||||
|
if v:
|
||||||
|
hight += [
|
||||||
|
{
|
||||||
|
"if": {"filter_query": "{{{}}} = {}".format(col, v), "column_id": col},
|
||||||
|
"backgroundColor": color,
|
||||||
|
"color": "white",
|
||||||
|
}
|
||||||
|
for col in highlight_columns
|
||||||
|
]
|
||||||
|
return hight
|
@ -8,8 +8,16 @@ import dash_table
|
|||||||
import json
|
import json
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
|
||||||
from ...app import app
|
from recopytex.dashboard.app import app
|
||||||
from .models import get_tribes, get_exams, get_unstack_scores, get_students_from_exam
|
from recopytex.dashboard.common.formating import highlight_scores
|
||||||
|
|
||||||
|
from .models import (
|
||||||
|
get_tribes,
|
||||||
|
get_exams,
|
||||||
|
get_unstack_scores,
|
||||||
|
get_students_from_exam,
|
||||||
|
get_score_colors,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@app.callback(
|
@app.callback(
|
||||||
@ -57,11 +65,15 @@ def update_scores_store(exam):
|
|||||||
"score_rate",
|
"score_rate",
|
||||||
"is_leveled",
|
"is_leveled",
|
||||||
]
|
]
|
||||||
columns = fixed_columns + list(get_students_from_exam(exam))
|
|
||||||
|
students = list(get_students_from_exam(exam))
|
||||||
|
columns = fixed_columns + students
|
||||||
|
|
||||||
|
score_color = get_score_colors()
|
||||||
|
|
||||||
return [
|
return [
|
||||||
[{"id": c, "name": c} for c in columns],
|
[{"id": c, "name": c} for c in columns],
|
||||||
scores.to_dict("records"),
|
scores.to_dict("records"),
|
||||||
[],
|
highlight_scores(students, score_color),
|
||||||
{"headers": True, "data": len(fixed_columns)},
|
{"headers": True, "data": len(fixed_columns)},
|
||||||
]
|
]
|
||||||
|
@ -28,3 +28,11 @@ def get_unstack_scores(exam):
|
|||||||
def get_students_from_exam(exam):
|
def get_students_from_exam(exam):
|
||||||
flat_scores = LOADER.get_exam_scores(exam)
|
flat_scores = LOADER.get_exam_scores(exam)
|
||||||
return flat_scores["student_name"].unique()
|
return flat_scores["student_name"].unique()
|
||||||
|
|
||||||
|
|
||||||
|
def get_score_colors():
|
||||||
|
scores_config = LOADER.get_config()["valid_scores"]
|
||||||
|
score_color = {}
|
||||||
|
for key, score in scores_config.items():
|
||||||
|
score_color[score["value"]] = score["color"]
|
||||||
|
return score_color
|
||||||
|
Loading…
Reference in New Issue
Block a user