本文整理汇总了Python中models.Player.select方法的典型用法代码示例。如果您正苦于以下问题:Python Player.select方法的具体用法?Python Player.select怎么用?Python Player.select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Player
的用法示例。
在下文中一共展示了Player.select方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post_vote
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import select [as 别名]
def post_vote(room_code):
sessid = request.cookies.get("sessid")
you = Player.select(Player, Room).join(Room).where(Player.sessid == sessid, Room.code == room_code).get()
room = you.room
vote = request.params["vote"]
mission_id = request.params["missionId"]
mission = Mission.get(Mission.id == mission_id, Mission.room == room)
Vote.insert(player=you, mission=mission, vote=vote).execute()
votes = Vote.select(Vote, Player).join(Player).where(Vote.mission == mission).execute()
if votes.count == room.size:
upvotes = sum(1 for v in votes if v.vote == "yes")
agreed = True if (upvotes * 2 > votes.count) else False
votes_message_data = {
"votes": [
{"player": {"id": vote.player.id, "name": vote.player.name}, "vote": vote.vote} for vote in votes
],
"agreed": agreed,
}
messages = [Msg("votes", votes_message_data)]
if agreed:
room.phase = Room.PHASE_MISSION
room.save()
else:
room.phase = Room.PHASE_TEAM_BUILD
leader = next_leader(room)
leader_message_data = {"leader": {"id": leader.id, "name": leader.name}}
messages.append(Msg("leader", leader_message_data))
post_message(messages, room=room)
示例2: poll_message
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import select [as 别名]
def poll_message(room_code):
"""
Route used to poll messages waiting for the user.
It adds a queue to the set of player's message queues.
Fetches new messages from the database and, if no messages, it waits until
a new message appears in the queue.
"""
sessid = request.cookies.get("sessid")
try:
player = Player.select(Player, Room).join(Room).where(Player.sessid == sessid, Room.code == room_code).get()
except Player.DoesNotExist:
return HTTPError(404)
last_update_ts = float(request.query.get("lastUpdate", time.time()))
last_update = datetime.fromtimestamp(last_update_ts)
queue = gevent.queue.Queue()
message_queue[player.id].add(queue)
messages = Message.select().where(Message.player == player, Message.timestamp > last_update).execute()
if messages.count == 0:
def get_messages(queue):
while True:
try:
message = queue.get(timeout=90)
except gevent.queue.Empty:
return
if message is StopIteration:
return
yield message
messages = list(get_messages(queue))
message_queue[player.id].remove(queue)
return {"messages": [message.dict() for message in messages], "timestamp": time.time()}
示例3: print_leaderboard
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import select [as 别名]
def print_leaderboard(self):
table = []
for player in Player.select().where((Player.wins + Player.losses) > 0).order_by(Player.rating.desc()).limit(25):
table.append(['<@' + player.slack_id + '>', player.rating, player.wins, player.losses])
self.talk('```' + tabulate(table, headers=['Name', 'ELO', 'Wins', 'Losses']) + '```')
示例4: print_leaderboard
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import select [as 别名]
def print_leaderboard(self):
table = []
min_streak_len = config['min_streak_length']
for player in Player.select().where((Player.wins + Player.losses) > 0).order_by(Player.rating.desc()).limit(25):
win_streak = self.get_win_streak(player.slack_id)
streak_text = ('(won ' + str(win_streak) + ' in a row)') if win_streak >= min_streak_len else ''
table.append(['<@' + player.slack_id + '>', player.rating, player.wins, player.losses, streak_text])
self.talk('```' + tabulate(table, headers=['Name', 'ELO', 'Wins', 'Losses', 'Streak']) + '```')
示例5: lobby
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import select [as 别名]
def lobby(room_code):
"""
Route displays current lobby to the authenticated and authorized user.
"""
sessid = request.cookies.get("sessid")
try:
player = Player.select(Player, Room).join(Room).where(Player.sessid == sessid, Room.code == room_code).get()
except Player.DoesNotExist:
return HTTPError(404)
room = player.room
players = Player.select().where(Player.room == room).execute()
return template(
"lobby",
room=room,
you=player,
players=players,
owner=(player == room.owner),
message_url="/game/%s/message" % room_code,
timestamp=time.time(),
)
示例6: search
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import select [as 别名]
def search(args, i):
num_steps = args.step_limit
total_steps = (3 * (num_steps**2)) - (3 * num_steps) + 1
position = get_pos_by_name(args.location)
position = (position[0], position[1], 0)
api = args.api
if api._auth_provider and api._auth_provider._ticket_expire:
remaining_time = api._auth_provider._ticket_expire/1000 - time.time()
if remaining_time > 60:
log.info("Skipping Pokemon Go login process since already logged in for another {:.2f} seconds".format(remaining_time))
else:
login(args, position)
else:
login(args, position)
for step, step_location in enumerate(generate_location_steps(position, num_steps), 1):
log.info('Scanning step {:d} of {:d}.'.format(step, total_steps))
log.info('Scan location is {:f}, {:f}'.format(step_location[0], step_location[1]))
update_player_position(args, step_location[0], step_location[1])
response_dict = {}
failed_consecutive = 0
while not response_dict:
if player_has_reset_initial_position(args):
# we stop this loop and start another one
player_id = get_player_id(args)
player = Player.select().where(Player.player_id == player_id)[0]
args.location = str(player.start_latitude) + ' ' + str(player.start_longitude)
search_loop(args)
return
response_dict = send_map_request(api, step_location)
if response_dict:
try:
parse_map(response_dict, i, step, step_location)
except KeyError:
log.error('Scan step {:d} failed. Response dictionary key error.'.format(step))
failed_consecutive += 1
if(failed_consecutive >= config['REQ_MAX_FAILED']):
log.error('Niantic servers under heavy load. Waiting before trying again')
time.sleep(config['REQ_HEAVY_SLEEP'])
failed_consecutive = 0
else:
log.info('Map Download failed. Trying again.')
log.info('Completed {:5.2f}% of scan.'.format(float(step) / num_steps**2*100))
time.sleep(config['REQ_SLEEP'])
return True
示例7: initialize_player_position
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import select [as 别名]
def initialize_player_position(args):
player_id = get_player_id(args)
start_position = get_pos_by_name(args.location)
if len(Player.select().where(Player.player_id == player_id)) == 0:
Player.create(
player_id=player_id,
name=args.username,
enabled=True,
last_modified=datetime.now(),
start_latitude=start_position[0],
start_longitude=start_position[1]
)
else:
Player.update(
last_modified=datetime.now(),
start_latitude=start_position[0],
start_longitude=start_position[1]
).where(Player.player_id == player_id).execute()
示例8: post_team
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import select [as 别名]
def post_team(room_code):
sessid = request.cookies.get("sessid")
you = Player.select(Player, Room).join(Room).where(Player.sessid == sessid, Room.code == room_code).get()
room = you.room
if you.queue_position != room.leader_queue:
return HTTPError(400, "You are not the leader")
team_ids = request.params.getall("team[]")
team = room.players.where(Player.id << team_ids).execute()
mission = Mission.create(room=room, leader=you, team_size=0)
with db.atomic():
for plr in team:
PlayerMission.insert(player=plr, mission=mission).execute()
room.phase = "vote"
room.save()
message_data = {
"mission_id": mission.id,
"leader": {"id": you.id, "name": you.name},
"team": [{"id": plr.id, "name": plr.name} for plr in team],
}
post_message([Msg("team", message_data)], room=room)
示例9: game
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import select [as 别名]
def game(room_code):
sessid = request.cookies.get("sessid")
you = Player.select(Player, Room).join(Room).where(Player.sessid == sessid, Room.code == room_code).get()
room = you.room
leader = Player.get(queue_position=room.leader_queue, room=room)
players = room.players.execute()
initial_data = {
"game": {"phase": room.phase, "round": room.round, "leader_queue": room.leader_queue},
"leader": {"id": leader.id, "name": leader.name},
"players": [{"id": plr.id, "name": plr.name, "queue_position": plr.queue_position} for plr in players],
"you": {"id": you.id, "name": you.name, "role": you.role},
}
context = {
"you": you,
"players": players,
"base_url": "/game/%s" % room_code,
"timestamp": time.time(),
"initial_data": json.dumps(initial_data),
}
if you.role == "spy":
spies = you.room.players.where(Player.role == "spy").execute()
context["spies"] = spies
return template("game", **context)
示例10: player_has_reset_initial_position
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import select [as 别名]
def player_has_reset_initial_position(args):
player_id = get_player_id(args)
player = Player.select().where(Player.player_id == player_id)[0]
start_position = get_pos_by_name(args.location)
return not (almost_equals(player.start_latitude, start_position[0]) and almost_equals(player.start_longitude, start_position[1]))