當前位置: 首頁>>代碼示例>>Python>>正文


Python Alphabet.format_timestamp方法代碼示例

本文整理匯總了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)
開發者ID:halldorel,項目名稱:Netskrafl,代碼行數:32,代碼來源:admin.py

示例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)
開發者ID:halldorel,項目名稱:Netskrafl,代碼行數:19,代碼來源:admin.py

示例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)
開發者ID:s31415,項目名稱:Netskrafl,代碼行數:5,代碼來源:skraflgame.py

示例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)
開發者ID:s31415,項目名稱:Netskrafl,代碼行數:5,代碼來源:skraflgame.py

示例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
#.........這裏部分代碼省略.........
開發者ID:magnussig,項目名稱:Netskrafl,代碼行數:103,代碼來源:skraflstats.py


注:本文中的languages.Alphabet.format_timestamp方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。