当前位置: 首页>>代码示例>>Python>>正文


Python Player.alias方法代码示例

本文整理汇总了Python中models.Player.alias方法的典型用法代码示例。如果您正苦于以下问题:Python Player.alias方法的具体用法?Python Player.alias怎么用?Python Player.alias使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Player的用法示例。


在下文中一共展示了Player.alias方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: print_unconfirmed

# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import alias [as 别名]
    def print_unconfirmed(self):
        table = []

        Winner = Player.alias()
        Loser  = Player.alias()
        for match in Match.select(Match, Winner, Loser).join(Winner, on=(Match.winner == Winner.slack_id)).join(Loser, on=(Match.loser == Loser.slack_id)).where(Match.pending == True).order_by(Match.played.desc()).limit(25):
            match_played_utc = match.played.replace(tzinfo=from_zone)
            match_played_pst = match_played_utc.astimezone(to_zone)
            table.append([match.id, '<@' + match.loser.slack_id + '>', '<@' + match.winner.slack_id + '>', str(match.winner_score) + '-' + str(match.loser_score), match_played_pst.strftime('%m/%d/%y %I:%M %p')])

        self.talk('```' + tabulate(table, headers=['Match', 'Needs to Confirm', 'Opponent', 'Score', 'Date']) + '```')
开发者ID:mburst,项目名称:slack-elobot,代码行数:13,代码来源:elobot.py

示例2: confirm

# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import alias [as 别名]
    def confirm(self, user, message_text):
        values = re.split(CONFIRM_REGEX, message_text)

        #0: blank, 1: match_id, 2: blank
        if not values or len(values) != 3:
            return

        try:
            #http://stackoverflow.com/questions/24977236/saving-peewee-queries-with-multiple-foreign-key-relationships-against-the-same-t
            Winner = Player.alias()
            Loser  = Player.alias()
            match = Match.select(Match, Winner, Loser).join(Winner, on=(Match.winner == Winner.slack_id)).join(Loser, on=(Match.loser == Loser.slack_id)).where(Match.id == values[1], Match.loser == user, Match.pending == True).get()

            with db.transaction():
                match.winner.wins  += 1
                match.loser.losses += 1

                winner_old_elo = match.winner.rating
                loser_old_elo  = match.loser.rating

                #https://metinmediamath.wordpress.com/2013/11/27/how-to-calculate-the-elo-rating-including-example/
                winner_transformed_rating = 10**(match.winner.rating/400.0)
                loser_transformed_rating  = 10**(match.loser.rating/400.0)

                winner_expected_score = winner_transformed_rating /(winner_transformed_rating + loser_transformed_rating)
                loser_expected_score  = loser_transformed_rating /(winner_transformed_rating + loser_transformed_rating)

                match.winner.rating = round(match.winner.rating + match.winner.k_factor() * (1 - winner_expected_score))
                match.loser.rating = round(match.loser.rating + match.loser.k_factor() * (0 - loser_expected_score))

                match.pending = False
                match.save()
                match.winner.save()
                match.loser.save()

                self.talk('<@' + match.winner.slack_id + '> your new ELO is: ' + str(match.winner.rating) + ' You won ' + str(match.winner.rating - winner_old_elo) + ' ELO')
                self.talk('<@' + match.loser.slack_id + '> your new ELO is: ' + str(match.loser.rating) + ' You lost ' + str(abs(match.loser.rating - loser_old_elo)) + ' ELO')
        except Exception as e:
            self.talk('Unable to confirm ' + values[1] + '. ' + str(e))
开发者ID:mburst,项目名称:slack-elobot,代码行数:41,代码来源:elobot.py


注:本文中的models.Player.alias方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。