本文整理汇总了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']) + '```')
示例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))