Skip to content

Commit

Permalink
Merge pull request #13 from UWCS/fix/results-graphical-bugs
Browse files Browse the repository at this point in the history
Fix results graphical bugs
  • Loading branch information
Mole1424 authored Mar 12, 2024
2 parents d8274f6 + b6bf928 commit cff34b1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
4 changes: 2 additions & 2 deletions votes/templates/votes/parts/table.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
{% elif style == "changed" %}
<td colspan="{{ width }}"><strong>{{ content }}</strong></td>
{% elif style == "float" %}
<td colspan="{{ width }}">{{ content|floatformat }}</td>
<td colspan="{{ width }}">{{ content|floatformat:-3 }}</td>
{% else %}
<td colspan="{{ width }}">{{ content }}</td>
{% endif %}
Expand All @@ -39,7 +39,7 @@
{% elif style == "changed" %}
<td colspan="{{ width }}"><strong>{{ content }}</strong></td>
{% elif style == "float" %}
<td colspan="{{ width }}">{{ content|floatformat }}</td>
<td colspan="{{ width }}">{{ content|floatformat:-3 }}</td>
{% else %}
<td colspan="{{ width }}">{{ content }}</td>
{% endif %}
Expand Down
9 changes: 5 additions & 4 deletions votes/templates/votes/stv_results.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{% extends "votes/approval_results.html" %}
{% load vote_tags %}
{% block results %}
<h2>Total Turnout: {{ election.stvvote_set.count }}</h2>
<h2>Available seats: {{ election.seats }}</h2>
<hr>
<p>Total Turnout: {{ election.stvvote_set.count }}</p>
<p>Available seats: {{ election.seats }}</p>
<h2>Winner{{ result.winners.all|pluralize }}</h2>
<div class="list-group">
<div class="list-group mb-3">
{% for winner in result.winners.all %}
<div class="list-group-item mb-3">
<div class="list-group-item">
{{ winner.name }}
</div>
{% endfor %}
Expand Down
23 changes: 18 additions & 5 deletions votes/templatetags/vote_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,16 @@ def vote_breakdown_table(election: Election):
str(x.id) for x in election.candidate_set.all()
] # JSON keys have to be strings
scores = {candidate: [] for candidate in candidates}
states = {
candidate: ["HOPEFUL"] for candidate in candidates
} # States are offset by one round due to r0
states = None
for i in actions:
type_ = i["type"]
detail = i["details"]
if type_ == "round" and detail["round"] == 0:
states = {
candidate: [detail["candidates"][candidate]["status"]]
for candidate in candidates
} # States are offset by one round due to r0
assert states is not None
wastage = []
total = []
threshold = []
Expand Down Expand Up @@ -112,14 +119,20 @@ def vote_breakdown_table(election: Election):
row = []
key = str(candidate.id)
row.append((candidate.name, 1, "standard"))
row.append((states[key][0], 1, "standard"))
row.append(
(
states[key][0],
1,
"standard" if states[key][0] != "WITHDRAWN" else "changed",
)
)
for i in range(rounds):
row.append((scores[key][i], 1, "float"))
if tiebreak[i] is not False:
if key == tiebreak[i][0]:
row.append(
(
mark_safe('<i class="fas fa-check-circle"></i>'),
mark_safe('<i class="fas fa-dot-circle"></i>'),
1,
"standard",
)
Expand Down

0 comments on commit cff34b1

Please sign in to comment.