本文整理汇总了Python中languages.Alphabet.format_timestamp方法的典型用法代码示例。如果您正苦于以下问题:Python Alphabet.format_timestamp方法的具体用法?Python Alphabet.format_timestamp怎么用?Python Alphabet.format_timestamp使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类languages.Alphabet
的用法示例。
在下文中一共展示了Alphabet.format_timestamp方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: admin_loadgame
# 需要导入模块: from languages import Alphabet [as 别名]
# 或者: from languages.Alphabet import format_timestamp [as 别名]
def admin_loadgame():
""" Fetch a game object and return it as JSON """
uuid = request.form.get("uuid", None)
game = None
if uuid:
# Attempt to load the game whose id is in the URL query string
game = Game.load(uuid)
if game:
board = game.state.board()
g = dict(
uuid = game.uuid,
timestamp = Alphabet.format_timestamp(game.timestamp),
player0 = game.player_ids[0],
player1 = game.player_ids[1],
robot_level = game.robot_level,
ts_last_move = Alphabet.format_timestamp(game.ts_last_move),
irack0 = game.initial_racks[0],
irack1 = game.initial_racks[1],
prefs = game._preferences,
over = game.is_over(),
moves = [ (m.player, m.move.summary(board),
m.rack, Alphabet.format_timestamp(m.ts)) for m in game.moves ]
)
else:
g = None
return jsonify(game = g)
示例2: admin_fetchgames
# 需要导入模块: from languages import Alphabet [as 别名]
# 或者: from languages.Alphabet import format_timestamp [as 别名]
def admin_fetchgames():
""" Return a JSON representation of all finished games """
q = GameModel.query(GameModel.over == True).order(GameModel.ts_last_move)
gamelist = []
for gm in q.fetch():
gamelist.append(dict(
id = gm.key.id(),
ts = Alphabet.format_timestamp(gm.timestamp),
lm = Alphabet.format_timestamp(gm.ts_last_move or gm.timestamp),
p0 = None if gm.player0 is None else gm.player0.id(),
p1 = None if gm.player1 is None else gm.player1.id(),
rl = gm.robot_level,
s0 = gm.score0,
s1 = gm.score1,
pr = gm.prefs
))
return jsonify(gamelist = gamelist)
示例3: start_time
# 需要导入模块: from languages import Alphabet [as 别名]
# 或者: from languages.Alphabet import format_timestamp [as 别名]
def start_time(self):
""" Returns the timestamp of the game in a readable format """
return u"" if self.timestamp is None else Alphabet.format_timestamp(self.timestamp)
示例4: end_time
# 需要导入模块: from languages import Alphabet [as 别名]
# 或者: from languages.Alphabet import format_timestamp [as 别名]
def end_time(self):
""" Returns the time of the last move in a readable format """
return u"" if self.ts_last_move is None else Alphabet.format_timestamp(self.ts_last_move)
示例5: _run_stats
# 需要导入模块: from languages import Alphabet [as 别名]
# 或者: from languages.Alphabet import format_timestamp [as 别名]
def _run_stats(from_time, to_time):
""" Runs a process to update user statistics and Elo ratings """
logging.info(u"Generating stats from {0} to {1}".format(from_time, to_time))
if from_time is None or to_time is None:
# Time range must be specified
return
if from_time >= to_time:
# Null time range
return
# Iterate over all finished games within the time span in temporal order
q = GameModel.query(GameModel.over == True).order(GameModel.ts_last_move) \
.filter(GameModel.ts_last_move > from_time) \
.filter(GameModel.ts_last_move <= to_time)
# The accumulated user statistics
users = dict()
def _init_stat(user_id, robot_level):
""" Returns the newest StatsModel instance available for the given user """
return StatsModel.newest_before(from_time, user_id, robot_level)
cnt = 0
ts_last_processed = None
try:
# Use i as a progress counter
for i, gm in enumerate(q):
ts = Alphabet.format_timestamp(gm.timestamp)
lm = Alphabet.format_timestamp(gm.ts_last_move or gm.timestamp)
p0 = None if gm.player0 is None else gm.player0.id()
p1 = None if gm.player1 is None else gm.player1.id()
robot_game = (p0 is None) or (p1 is None)
if robot_game:
rl = gm.robot_level
else:
rl = 0
s0 = gm.score0
s1 = gm.score1
if (s0 == 0) and (s1 == 0):
# When a game ends by resigning immediately,
# make sure that the weaker player
# doesn't get Elo points for a draw; in fact,
# ignore such a game altogether in the statistics
continue
if p0 is None:
k0 = "robot-" + str(rl)
else:
k0 = p0
if p1 is None:
k1 = "robot-" + str(rl)
else:
k1 = p1
if k0 in users:
urec0 = users[k0]
else:
users[k0] = urec0 = _init_stat(p0, rl if p0 is None else 0)
if k1 in users:
urec1 = users[k1]
else:
users[k1] = urec1 = _init_stat(p1, rl if p1 is None else 0)
# Number of games played
urec0.games += 1
urec1.games += 1
if not robot_game:
urec0.human_games += 1
urec1.human_games += 1
# Total scores
urec0.score += s0
urec1.score += s1
urec0.score_against += s1
urec1.score_against += s0
if not robot_game:
urec0.human_score += s0
urec1.human_score += s1
urec0.human_score_against += s1
urec1.human_score_against += s0
# Wins and losses
if s0 > s1:
urec0.wins += 1
urec1.losses += 1
elif s1 > s0:
urec1.wins += 1
urec0.losses += 1
if not robot_game:
if s0 > s1:
urec0.human_wins += 1
urec1.human_losses += 1
elif s1 > s0:
urec1.human_wins += 1
urec0.human_losses += 1
# Find out whether players are established or beginners
est0 = urec0.games > ESTABLISHED_MARK
est1 = urec1.games > ESTABLISHED_MARK
#.........这里部分代码省略.........