From 2397fdb7155ddf4b8046b1c3f62fbae11e562ccf Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Fri, 16 Apr 2021 17:27:42 +0200 Subject: [PATCH] =?UTF-8?q?Rajoute=20des=20couleurs=20sur=20le=20tableau?= =?UTF-8?q?=20r=C3=A9capitulatif?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- elections/templates/elections/results/rank.html | 4 ++-- elections/utils.py | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/elections/templates/elections/results/rank.html b/elections/templates/elections/results/rank.html index 73ccbb8..0c65c57 100644 --- a/elections/templates/elections/results/rank.html +++ b/elections/templates/elections/results/rank.html @@ -35,8 +35,8 @@ - {% for cell in line %} - {{ cell }} + {% for cell, class in line %} + {{ cell }} {% endfor %} {% endwith %} diff --git a/elections/utils.py b/elections/utils.py index 9e04a87..373dea1 100644 --- a/elections/utils.py +++ b/elections/utils.py @@ -249,11 +249,21 @@ class ResultsData: options = list(question.options.all()) n = len(options) - matrix = np.zeros((n, n), dtype=int) + _matrix = np.zeros((n, n), dtype=int) + matrix = np.zeros((n, n), dtype=tuple) for d in duels: i, j = options.index(d.loser), options.index(d.winner) - matrix[i, j] = d.amount + _matrix[i, j] = d.amount + + for i in range(n): + for j in range(n): + if _matrix[i, j] > _matrix[j, i]: + matrix[i, j] = (_matrix[i, j], "is-success") + elif _matrix[i, j] < _matrix[j, i]: + matrix[i, j] = (_matrix[i, j], "is-danger") + else: + matrix[i, j] = (_matrix[i, j], "") return render_to_string( "elections/results/rank.html",