diff --git a/recopytex/dashboard/common/formating.py b/recopytex/dashboard/common/formating.py new file mode 100644 index 0000000..492a2fa --- /dev/null +++ b/recopytex/dashboard/common/formating.py @@ -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 diff --git a/recopytex/dashboard/pages/exams_scores/callbacks.py b/recopytex/dashboard/pages/exams_scores/callbacks.py index b6ed1de..5cc8b30 100644 --- a/recopytex/dashboard/pages/exams_scores/callbacks.py +++ b/recopytex/dashboard/pages/exams_scores/callbacks.py @@ -8,8 +8,16 @@ import dash_table import json import pandas as pd -from ...app import app -from .models import get_tribes, get_exams, get_unstack_scores, get_students_from_exam +from recopytex.dashboard.app import app +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( @@ -57,11 +65,15 @@ def update_scores_store(exam): "score_rate", "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 [ [{"id": c, "name": c} for c in columns], scores.to_dict("records"), - [], + highlight_scores(students, score_color), {"headers": True, "data": len(fixed_columns)}, ] diff --git a/recopytex/dashboard/pages/exams_scores/models.py b/recopytex/dashboard/pages/exams_scores/models.py index e3386af..da3d446 100644 --- a/recopytex/dashboard/pages/exams_scores/models.py +++ b/recopytex/dashboard/pages/exams_scores/models.py @@ -28,3 +28,11 @@ def get_unstack_scores(exam): def get_students_from_exam(exam): flat_scores = LOADER.get_exam_scores(exam) 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