Ejemplo n.º 1
0
    def get_ranked_teams(game):
        teams = {x:Team(x) for x in NameList.objects(game=game)}
        for record in GameRecord.objects(game=game):
            if record.result == u'红方胜':
                teams[record.red].add_score(2)
                teams[record.red].add_diff(record.diff)
                teams[record.blue].add_diff(0 - record.diff)
            elif record.result == u'蓝方胜':
                teams[record.blue].add_score(2)
                teams[record.blue].add_diff(record.diff)
                teams[record.red].add_diff(0 - record.diff)
            elif record.result == u'平局':
                teams[record.blue].add_score(1)
                teams[record.red].add_score(1)
            elif record.result == u'红方弃权':
                teams[record.red].add_score(-1)
                teams[record.red].add_diff(-6)
                teams[record.blue].add_score(2)
                teams[record.blue].add_diff(6)
            elif record.result == u'蓝方弃权':
                teams[record.blue].add_score(-1)
                teams[record.blue].add_diff(-6)
                teams[record.red].add_score(2)
                teams[record.red].add_diff(6)
            teams[record.red].add_against(teams[record.blue])
            teams[record.blue].add_against(teams[record.red])

        for team in teams.values():
            team.compute_sscore()

        team_list = teams.values()
        random.shuffle(team_list)
        return sorted(team_list, key=attrgetter('total_score', 'total_sscore', 'total_diff'), reverse=True)
Ejemplo n.º 2
0
 def first_stage(self, game, ballot_type):
     """首轮抽签"""
     results = []
     teams = list(NameList.objects(game=game).order_by('no').all())
     team_count = len(teams) / 2 * 2
     if ballot_type == 'sequence':
         for i in range(0, team_count, 2):
             result = dict(desk_no=i/2+1, red=teams[i], blue=teams[i+1])
             results.append(result)
         return results
     else:
         return self.ballot_by_score(game, ballot_type)