Skip to content

Commit

Permalink
Show side abbrevations on the motion statistics page again.
Browse files Browse the repository at this point in the history
Tabbycat used to show side names, but at some point this broke. This commit fixes this.
  • Loading branch information
teymour-aldridge committed Oct 30, 2024
1 parent 14234e3 commit ae7f9ba
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions tabbycat/motions/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
from .models import Motion, RoundMotion


def abbrv_of_bp_side(side: int) -> str:
"""
Get the abbreviated name of a BP side.
"""
assert 0 <= side < 4
return {0: "OG", 1: "OO", 2: "CG", 3: "CO"}.get(side)


def _annotate_annotations(dict_motions, queryset, fields):
for item in queryset:
for field in fields:
Expand Down Expand Up @@ -236,16 +244,17 @@ def _collate_prelim_motion_annotations(self):
motion.counts_by_bench = {'gov': 0, 'opp': 0}

for side in self.tournament.sides:
side_abbrv = abbrv_of_bp_side(side)
average = getattr(motion, 's%d_average' % side)
if average is None:
continue
motion.averages.append((side, average, average / 6 * 100))
motion.averages.append((side_abbrv, average, average / 6 * 100))
counts = []
for points in [3, 2, 1, 0]:
count = getattr(motion, 's%d_%d_count' % (side, points))
percentage = count / motion.ndebates * 100 if motion.ndebates > 0 else 0
counts.append((points, count, percentage))
motion.counts_by_side.append((side, counts))
motion.counts_by_side.append((side_abbrv, counts))

if side == DebateSide.OG or side == DebateSide.OO:
motion.counts_by_half['top'] += (average / 2)
Expand Down Expand Up @@ -295,11 +304,12 @@ def _collate_elim_motion_annotations(self):
motion.counts_by_side = []

for side in self.tournament.sides:
side_abbr = abbrv_of_bp_side(side)
advancing = getattr(motion, 's%d_advancing' % side)
advancing_pc = advancing / motion.ndebates * 100 if motion.ndebates > 0 else 0
eliminated = getattr(motion, 's%d_eliminated' % side)
eliminated_pc = eliminated / motion.ndebates * 100 if motion.ndebates > 0 else 0
motion.counts_by_side.append((side, advancing, advancing_pc, eliminated, eliminated_pc))
motion.counts_by_side.append((side_abbr, advancing, advancing_pc, eliminated, eliminated_pc))


class RoundMotionBPStatsCalculator(MotionBPStatsCalculator):
Expand Down

0 comments on commit ae7f9ba

Please sign in to comment.