Beispiel #1
0
    def get_tables(self):
        if self.tournament.pref('teams_in_debate') != 'bp':
            logger.warning("Tried to access position balance report for a non-BP tournament")
            return []
        if self.round.prev is None:
            logger.warning("Tried to access position balance report for first round")
            return []
        if self.round.is_break_round:
            logger.warning("Tried to access position balance report for a break round")
            return []

        draw = self.round.debate_set_with_prefetches(ordering=('room_rank',), institutions=True)
        teams = Team.objects.filter(debateteam__debate__round=self.round)
        side_histories_before = get_side_history(teams, self.tournament.sides, self.round.prev.seq)
        side_histories_now = get_side_history(teams, self.tournament.sides, self.round.seq)
        metrics = self.tournament.pref('team_standings_precedence')
        generator = TeamStandingsGenerator(metrics[0:1], ())
        standings = generator.generate(teams, round=self.round.prev)

        summary_table = PositionBalanceReportSummaryTableBuilder(view=self,
                title=_("Teams with position imbalances"),
                empty_title=_("No teams with position imbalances! Hooray!") + " 😊")
        summary_table.build(draw, teams, side_histories_before, side_histories_now, standings)

        draw_table = PositionBalanceReportDrawTableBuilder(view=self, title=_("Annotated draw"))
        draw_table.build(draw, teams, side_histories_before, side_histories_now, standings)

        return [summary_table, draw_table]
Beispiel #2
0
    def get_tables(self):
        if self.tournament.pref('teams_in_debate') != 'bp':
            logger.warning("Tried to access position balance report for a non-BP tournament")
            return []
        if self.round.prev is None:
            logger.warning("Tried to access position balance report for first round")
            return []
        if self.round.is_break_round:
            logger.warning("Tried to access position balance report for a break round")
            return []

        draw = self.round.debate_set_with_prefetches(ordering=('room_rank',), institutions=True)
        teams = Team.objects.filter(debateteam__debate__round=self.round)
        side_histories_before = get_side_history(teams, self.tournament.sides, self.round.prev.seq)
        side_histories_now = get_side_history(teams, self.tournament.sides, self.round.seq)
        metrics = self.tournament.pref('team_standings_precedence')
        generator = TeamStandingsGenerator(metrics[0:1], ())
        standings = generator.generate(teams, round=self.round.prev)

        summary_table = PositionBalanceReportSummaryTableBuilder(view=self,
                title=_("Teams with position imbalances"),
                empty_title=_("No teams with position imbalances! Hooray!") + " 😊")
        summary_table.build(draw, teams, side_histories_before, side_histories_now, standings)

        draw_table = PositionBalanceReportDrawTableBuilder(view=self, title=_("Annotated draw"))
        draw_table.build(draw, teams, side_histories_before, side_histories_now, standings)

        return [summary_table, draw_table]
Beispiel #3
0
 def get_bp_position_balance_table(self):
     draw = self.get_draw()
     teams = Team.objects.filter(debateteam__debate__round=self.round)
     side_histories_before = get_side_history(teams, self.tournament.sides, self.round.prev.seq)
     side_histories_now = get_side_history(teams, self.tournament.sides, self.round.seq)
     generator = TeamStandingsGenerator(('points',), ())
     standings = generator.generate(teams, round=self.round.prev)
     draw_table = PositionBalanceReportDrawTableBuilder(view=self)
     draw_table.build(draw, teams, side_histories_before, side_histories_now, standings)
     self.highlighted_cells_exist = any(draw_table.get_imbalance_category(team) is not None for team in teams)
     return draw_table
Beispiel #4
0
 def get_bp_position_balance_table(self):
     draw = self.get_draw()
     teams = Team.objects.filter(debateteam__debate__round=self.round)
     side_histories_before = get_side_history(teams, self.tournament.sides, self.round.prev.seq)
     side_histories_now = get_side_history(teams, self.tournament.sides, self.round.seq)
     metrics = self.tournament.pref('team_standings_precedence')
     generator = TeamStandingsGenerator(metrics[0:1], ())
     standings = generator.generate(teams, round=self.round.prev)
     draw_table = PositionBalanceReportDrawTableBuilder(view=self)
     draw_table.build(draw, teams, side_histories_before, side_histories_now, standings)
     self.highlighted_cells_exist = any(draw_table.get_imbalance_category(team) is not None for team in teams)
     return draw_table
Beispiel #5
0
    def _populate_side_history(self, teams):
        sides = self.round.tournament.sides

        if self.round.prev:
            prev_seq = self.round.prev.seq
            side_history = get_side_history(teams, sides, prev_seq)
            for team in teams:
                team.side_history = side_history[team.id]
        else:
            for team in teams:
                team.side_history = [0] * len(sides)
Beispiel #6
0
    def _populate_side_history(self, teams):
        sides = self.round.tournament.sides

        if self.round.prev:
            prev_seq = self.round.prev.seq
            side_history = get_side_history(teams, sides, prev_seq)
            for team in teams:
                team.side_history = side_history[team.id]
        else:
            for team in teams:
                team.side_history = [0] * len(sides)
Beispiel #7
0
    def add_debate_side_history_columns(self, debates, round):
        # Teams should be prefetched in debates, so don't use a new Team queryset to collate teams
        teams_by_side = [[d.get_team(side) for d in debates] for side in self.tournament.sides]
        all_teams = [team for d in debates for team in d.teams]
        side_histories = get_side_history(all_teams, self.tournament.sides, round.seq)

        for i, (side, teams) in enumerate(zip(self.tournament.sides, teams_by_side)):
            name = _("side history<br>\n(number of times the team has been on each side before this round)")
            # Translators: Abbreviation for "side history"
            abbr = _("SH")
            header = self._prepend_side_header(side, name, abbr)
            cells = self._side_history_by_team(side_histories, teams)
            if i == 0:
                for cell in cells:
                    cell['class'] = 'highlight-col'
            self.add_column(header, cells)
Beispiel #8
0
    def add_debate_side_history_columns(self, debates, round):
        # Teams should be prefetched in debates, so don't use a new Team queryset to collate teams
        teams_by_side = [[d.get_team(side) for d in debates]
                         for side in self.tournament.sides]
        all_teams = [team for d in debates for team in d.teams]
        side_histories = get_side_history(all_teams, self.tournament.sides,
                                          round.seq)

        for i, (side,
                teams) in enumerate(zip(self.tournament.sides, teams_by_side)):
            name = _(
                "side history<br>\n(number of times the team has been on each side before this round)"
            )
            # Translators: Abbreviation for "side history"
            abbr = _("SH")
            header = self._prepend_side_header(side, name, abbr)
            cells = self._side_history_by_team(side_histories, teams)
            if i == 0:
                for cell in cells:
                    cell['class'] = 'highlight-col'
            self.add_column(header, cells)