Skip to content

Commit

Permalink
Refactor: Eliminated duplication in adjudicator metric annotators
Browse files Browse the repository at this point in the history
  • Loading branch information
TrudeauOkech committed Jan 3, 2025
1 parent f00e32d commit 9911847
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions tabbycat/standings/speakers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from .base import BaseStandingsGenerator
from .metrics import QuerySetMetricAnnotator
from .ranking import BasicRankAnnotator
from .teams import NumberOfAdjudicatorsMetricAnnotator as TeamsAnnotator

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -132,11 +133,11 @@ class SpeakerNumberOfThirdsMetricAnnotator(SpeakerScoreQuerySetMetricAnnotator):


class NumberOfAdjudicatorsMetricAnnotator(SpeakerScoreQuerySetMetricAnnotator):
key = "num_adjs"
name = _("number of adjudicators who voted for this team")
abbr = _("Ballots")
choice_name = _("votes/ballots carried")
function = Sum
key = TeamsAnnotator.key
name = TeamsAnnotator.name
abbr = TeamsAnnotator.abbr
choice_name = TeamsAnnotator.choice_name
function = TeamsAnnotator.function

def __init__(self, adjs_per_debate=3):
self.adjs_per_debate = adjs_per_debate
Expand All @@ -146,11 +147,8 @@ def get_field(self):
NullIf('team__debateteam__teamscore__votes_possible', 0, output_field=FloatField()) *
self.adjs_per_debate)

def annotate_with_queryset(self, queryset, standings):
cast = int if all(t.num_adjs == int(t.num_adjs) for t in queryset if t.num_adjs is not None) else float
for item in queryset:
metric = item.num_adjs or 0
standings.add_metric(item, self.key, cast(metric))
# Use the annotate_with_queryset from teams
annotate_with_queryset = TeamsAnnotator.annotate_with_queryset


class StandardDeviationSpeakerScoreMetricAnnotator(SpeakerScoreQuerySetMetricAnnotator):
Expand Down

0 comments on commit 9911847

Please sign in to comment.