本文整理汇总了Python中models.Game.query方法的典型用法代码示例。如果您正苦于以下问题:Python Game.query方法的具体用法?Python Game.query怎么用?Python Game.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Game
的用法示例。
在下文中一共展示了Game.query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_team_map_win_loss
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import query [as 别名]
def _get_team_map_win_loss(team, map):
team_a_count = Game.query().filter(Game.map == map).filter(Game.team_a == team.name).count()
team_b_count = Game.query().filter(Game.map == map).filter(Game.team_b == team.name).count()
win_count = Game.query().filter(Game.map == map).filter(Game.winner == team.name).count()
game_count = team_b_count + team_a_count
per = 0 if not game_count else round(100 * float(win_count)/game_count)
return [map, game_count, win_count, per]
示例2: _get_team_win_loss
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import query [as 别名]
def _get_team_win_loss(team):
team_a_count = Game.query().filter(Game.team_a == team.name).count()
team_b_count = Game.query().filter(Game.team_b == team.name).count()
game_count = team_b_count + team_a_count
win_count = Game.query().filter(Game.winner == team.name).count()
per = round(100 * float(win_count)/game_count)
return [_get_team_name_link(team.name), team.elo, game_count, win_count, per]
示例3: _cache_average_win_rates
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import query [as 别名]
def _cache_average_win_rates():
"""Populates memcache with the average win rates of Games"""
# games_win = len(Game.query(Game.winner == "X").fetch())
# games_over = len(Game.query(Game.game_over == True).fetch())
games_win = Game.query(Game.winner == "X").count()
games_over = Game.query(Game.game_over == True).count()
if games_over > 0:
average = float(games_win)/games_over
memcache.set(MEMCACHE_WIN_RATES,
'The average win rate is {:.2f}'.format(average))
示例4: get_user_games
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import query [as 别名]
def get_user_games(self, request):
"""Task 3a: Returns all of an individual User's active games"""
user = User.query(User.name == request.user_name).get()
start = Game.query(Game.user == user.key).get()
if not user:
raise endpoints.NotFoundException(
'A User with that name does not exist!')
elif not start:
raise endpoints.NotFoundException('No games yet for User!')
else:
games = Game.query(Game.user == user.key and Game.game_over ==
False)
return GameForms(items=[game.to_form('') for game in games])
示例5: get_user_games
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import query [as 别名]
def get_user_games(self, request):
"""Return active games user is involved in"""
user = ndb.Key('User', request.user_id)
games = Game.query().filter(Game.player1 == user or Game.player2 == user).filter(Game.game_over == False)
return GameForms(items=[self._copyGameToForm(game) for game in games])
示例6: get
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import query [as 别名]
def get(self):
"""Send a reminder email to each User with an email who has
games in progress. Email body includes a count of active games and their
urlsafe keys
Called every hour using a cron job"""
users = User.query(User.email != None)
for user in users:
games = Game.query(ndb.OR(Game.user_x == user.key,
Game.user_o == user.key)). \
filter(Game.game_over == False)
if games.count() > 0:
subject = 'This is a reminder!'
body = 'Hello {}, you have {} games in progress. Their' \
' keys are: {}'. \
format(user.name,
games.count(),
', '.join(game.key.urlsafe() for game in games))
logging.debug(body)
# This will send test emails, the arguments to send_mail are:
# from, to, subject, body
mail.send_mail('[email protected]{}.appspotmail.com'.
format(app_identity.get_application_id()),
user.email,
subject,
body)
示例7: get
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import query [as 别名]
def get(self):
"""Send a reminder email to each User with an email about games.
Called every hour using a cron job"""
app_id = app_identity.get_application_id()
users = User.query(User.email != None)
# from the list off all users with email addresses, generate a list of
# all players with incomplete games:
contactable_users = []
for user in users:
game_search = Game.query(Game.user == user.key,
Game.game_over == False)
if len(game_search.fetch()) > 0:
contactable_users.append(user)
# Spam users with incomplete games.
for user in contactable_users:
subject = 'You have incomplete Hangman games!!'
body = ('Hello {}, stop what your doing and finish your game'
).format(user.name)
# This will send test emails, the arguments to send_mail are:
# from, to, subject, body
mail.send_mail('[email protected]{}.appspotmail.com'.format(app_id),
user.email,
subject,
body)
示例8: _check_game_state
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import query [as 别名]
def _check_game_state(game_id):
""" Checks whether there's a victory condition, losing condition, or no more available moves """
print("\n\nInside check game state, game_id: " + game_id)
moves = Move.query(Move.game_id == game_id).fetch()
game = Game.query(Game.game_id == game_id).get()
available_moves = Move.query(Move.available == True, Move.game_id == game_id).fetch()
if len(moves) == 0:
print("\n\n game_id not found {0} \n\n".format(game_id))
return "game_id_not_found"
winner_id = GuessANumberApi._check_winning_condition(game_id)
print("winner_id is " + str(winner_id))
if winner_id != False:
print("\n\n############### Game won by:" + winner_id + " ###############\n\n")
game.finish_game(winner_id, "game_won")
return winner_id
if len(available_moves) == 0:
print("\n\n Game Ended, No more moves left {0} \n\n".format(game_id))
game.finish_game(winner_id, "no_more_moves")
return "no_more_moves"
print("\n\nNo winners yet for game: {0} \n\n".format(game_id))
game.finished = False
game.state = "no_winners_yet"
game.put()
return "no_winners_yet"
示例9: get_user_games
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import query [as 别名]
def get_user_games(self, request):
"""Get all games created by user."""
user = User.query(User.name == request.user_name).get()
if not user:
raise endpoints.NotFoundException('A User with that name does not exist!')
query = Game.query(ancestor=user.key)
return GameForms(items=[game.to_form("") for game in query])
示例10: get
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import query [as 别名]
def get(self):
"""
Send a reminder email to each User with an email about games.
This sends each user one reminder daily if any active games. So if a
user has two active games, she will receive only one email.
Called every 24 hours using a cron job
"""
app_id = app_identity.get_application_id()
active_games = Game.query(Game.game_over == False)
all_users = User.query(User.email != None)
for user in all_users:
for game in active_games:
if user.key == game.user:
subject = 'This is a reminder!'
body = "Hello {}, you have at least one active" \
+ "hangman game!".format(user.name)
# This will send test emails,
# the arguments to send_mail are:
# from, to, subject, body
mail.send_mail('[email protected]{}.appspotmail.com'.format(app_id),
user.email,
subject,
body)
# once active game has been found for user, exit for loop
break
示例11: get_user_games
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import query [as 别名]
def get_user_games(self, request):
""" Get the user games. Requires the user info's """
user = self._get_user(request)
if not user:
raise endpoints.NotFoundException('A User with that name does not exist!')
games = Game.query(Game.user == user.key)
return GameForms(items=[game.to_form() for game in games])
示例12: get_user_games
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import query [as 别名]
def get_user_games(self, request):
"""Return all User's active games"""
user = User.query(User.name == request.user_name).get()
if not user:
raise endpoints.BadRequestException("User not found!")
games = Game.query(ndb.OR(Game.user_x == user.key, Game.user_o == user.key)).filter(Game.game_over == False)
return GameForms(items=[game.to_form() for game in games])
示例13: get_user_games
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import query [as 别名]
def get_user_games(self, request):
"""Return all user's active games"""
user = User.query(User.name == request.user_name).get()
if not user:
raise endpoints.BadRequestException('User not found.')
games = Game.query(Game.user == user.key)
return GameForms(items=[game.to_form('') for game in games])
示例14: get
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import query [as 别名]
def get(self):
"""Send a reminder email to each User with an email about games.
Called every hour using a cron job"""
app_id = app_identity.get_application_id()
onehourago = datetime.now() - timedelta(hours=1)
old_games = Game.query(Game.last_update < onehourago).fetch()
users_to_email = []
for game in old_games:
users_to_email.append(game.users[0])
users_to_email = set(users_to_email)
if users_to_email:
users_to_email = User.query(User.name.IN(users_to_email)).fetch()
for user in users_to_email:
subject = 'This is a reminder!'
body = """\
Hello, you have one or more pending Baskin Robbins 31 games!\
"""
# This will send test emails, the arguments to send_mail are:
# from, to, subject, body
mail.send_mail('[email protected]{}.appspotmail.com'.format(app_id),
user.email,
subject,
body)
示例15: _cache_unfinished_games
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import query [as 别名]
def _cache_unfinished_games():
"""Populates memcache with the number of unfinished games"""
games = Game.query(Game.game_over == False).fetch()
if games:
count = len(games)
memcache.set(MEMCACHE_UNFINISHED_GAMES,
'The total unfinished games remaining is {}'.format(count))