本文整理汇总了Python中models.Match.select方法的典型用法代码示例。如果您正苦于以下问题:Python Match.select方法的具体用法?Python Match.select怎么用?Python Match.select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Match
的用法示例。
在下文中一共展示了Match.select方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: matches
# 需要导入模块: from models import Match [as 别名]
# 或者: from models.Match import select [as 别名]
def matches():
if not session.get('user'):
return redirect('/login')
user = User.select().where(User.username == session.get('user'))[0]
count = Crush.select().where(Crush.crush == session.get('user')).count()
matches_1 = map(lambda m: m.user_2.username, Match.select().where(Match.user_1 == user))
matches_2 = map(lambda m: m.user_1.username, Match.select().where(Match.user_2 == user))
matches_1.extend(matches_2)
return render_template('match.html', matches=matches_1, count=count, user=user.username)
示例2: get_win_streak
# 需要导入模块: from models import Match [as 别名]
# 或者: from models.Match import select [as 别名]
def get_win_streak(self, player_slack_id):
win_streak = 0
matches = Match.select().where(Match.pending == False, (player_slack_id == Match.winner) | (player_slack_id == Match.loser)).order_by(Match.played.desc())
for match in matches:
if (player_slack_id == match.winner_id):
win_streak = win_streak + 1
else:
break
return win_streak
示例3: print_unconfirmed
# 需要导入模块: from models import Match [as 别名]
# 或者: from models.Match import select [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']) + '```')
示例4: delete
# 需要导入模块: from models import Match [as 别名]
# 或者: from models.Match import select [as 别名]
def delete(self, user, message_text):
values = re.split(DELETE_REGEX, message_text)
#0: blank, 1: match_id, 2: blank
if not values or len(values) != 3:
return
try:
match = Match.select(Match).where(Match.id == values[1], Match.winner == user, Match.pending == True).get()
match.delete_instance()
self.talk('Deleted match ' + values[1])
except:
self.talk('You are not the winner of match ' + values[1])
示例5: show_matches
# 需要导入模块: from models import Match [as 别名]
# 或者: from models.Match import select [as 别名]
def show_matches():
from models import Match
from terminaltables import SingleTable
# Initialize table data
data = [['keyword', 'answer']]
# List all matches
matches = list(Match.select().order_by(Match.keyword, Match.id))
for match in matches:
data.append([str(match.keyword), str(match.answer).replace('\n', '↵')[:30]])
# Create and print table
table = SingleTable(data)
table.title = '{} dialogues'.format(len(matches))
print(table.table)
示例6: confirm
# 需要导入模块: from models import Match [as 别名]
# 或者: from models.Match import select [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))
示例7: confirm_all
# 需要导入模块: from models import Match [as 别名]
# 或者: from models.Match import select [as 别名]
def confirm_all(self, message):
match_list = []
for match in Match.select(Match).where(Match.loser == message['user'], Match.pending == True):
match_list.append(match)
for match in match_list:
self.confirm(message['user'], 'Confirm '+ str(match.id))
示例8: TeachDialogRule
# 需要导入模块: from models import Match [as 别名]
# 或者: from models.Match import select [as 别名]
import json
import logging
import os
import random
from .rule import Rule
from models import User, Match, create_tables
DIALOGUES = {}
logger = logging.getLogger('bot')
for match in Match.select():
answers = DIALOGUES.get(match.keyword, [])
answers.append(match.answer)
DIALOGUES[match.keyword] = answers
class TeachDialogRule(Rule):
def __init__(self):
super().__init__()
self.supervisors = [user.user_id for user in User.select().where(User.is_admin == True)]
def match_expr(self):
return (r'我(如果|若|一旦)?(說|講|提到)\s*「?(?P<keyword>.+?)」?,?\s*你就?要?(說|講|大喊)\s*「?(?P<answer>.+?)」?\s*$',)
def run(self, message, keyword, answer, **kwargs):
if message.sender not in SUPERVISORS:
logger.warning('User %s triggered training but rejected', message.sender)
return None
if keyword in DIALOGUES:
DIALOGUES[keyword].append(answer)
else: