diff --git a/tabbycat/motions/statistics.py b/tabbycat/motions/statistics.py index 48595c465ee..2e786550ed1 100644 --- a/tabbycat/motions/statistics.py +++ b/tabbycat/motions/statistics.py @@ -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: @@ -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) @@ -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):