Example #1
0
 def ballot(self, game, ballot_type):
     """抽签算法"""
     if GameRecord.objects(game=game).count() == 0:
         self.round = 1
         return self.first_stage(game, ballot_type)
     else:
         self.round = max(GameRecord.objects(game=game).distinct('round')) + 1
         return self.ballot_by_score(game, ballot_type)
Example #2
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)