コード例 #1
0
ファイル: stats.py プロジェクト: zijingng/scoring
def game_key_in_db(c, g):
  # check just two tables: player_recent_games and wins. This could result
  # in some duplicates being added, but I'm not sure if the trouble here is
  # worth it -- because the db doesn't store all games, it relies on (to some
  # degree) reading games in order no matter what.
  n = query_first(c, '''SELECT count(game_key) FROM player_recent_games
                                        WHERE game_key = %s''', g['game_key'])
  if n > 0:
    return True
  n = query_first(c, '''SELECT count(game_key) FROM wins
                                        WHERE game_key = %s''', g['game_key'])
  return n > 0
コード例 #2
0
 def init_most_recent_from_db(self, c):
     import morgue.time
     db_time = query_first(
         c, '''SELECT MAX(start_time) FROM all_recent_games''')
     if db_time is None:
         self.most_recent_start = None
         self.empty_db_start = True
     else:
         self.most_recent_start = morgue.time.morgue_timestring(db_time)
コード例 #3
0
ファイル: query.py プロジェクト: elliptic/dcss_scoring
def fixup_month(c, month):
  mwin = month['winners'].items()
  month['players'] = query_first(c, '''SELECT COUNT(DISTINCT player)
                                        FROM date_players
                                       WHERE which_month = %s''',
                                 month['month'].replace('-', ''))
  def sort_winners(a, b):
    if a[1] != b[1]:
      return int(b[1] - a[1])
    else:
      return (a[1] < b[1] and -1) or (a[1] > b[1] and 1) or 0
  mwin.sort(sort_winners)
  month['winners'] = fixup_winners(mwin)
  return month
コード例 #4
0
ファイル: stats.py プロジェクト: crawl/scoring
def update_topN(c, g, n):
  if topN_count(c) >= n:
    if g['sc'] > lowest_highscore(c):
      query_do(c,'''DELETE FROM top_games
                          WHERE id = %s''',
               query_first(c, '''SELECT id FROM top_games
                                  ORDER BY sc LIMIT 1'''))
      insert_game(c, g, 'top_games')
      lowest_highscore.flush()
      dirty_pages('top-N', 'overview')
  else:
    insert_game(c, g, 'top_games')
    dirty_pages('top-N', 'overview')
    topN_count.flush()
コード例 #5
0
ファイル: stats.py プロジェクト: crawl/scoring
def update_player_best_games(c, g):
  player = g['name']
  if player_best_game_count(c, player) >= MAX_PLAYER_BEST_GAMES:
    if g['sc'] > player_lowest_highscore(c, player):
      query_do(c, '''DELETE FROM player_best_games WHERE id = %s''',
               query_first(c, '''SELECT id FROM player_best_games
                                       WHERE name = %s
                                    ORDER BY sc LIMIT 1''',
                           player))
      insert_game(c, g, 'player_best_games')
      player_lowest_highscore.flush_key(player)
  else:
    insert_game(c, g, 'player_best_games')
    player_best_game_count.flush_key(player)
コード例 #6
0
ファイル: query.py プロジェクト: elliptic/dcss_scoring
def top_killers(c):
  deaths = query_first(c, '''SELECT SUM(kills) FROM top_killers''')
  logf = logfields_prefixed('k.')
  rows = query_rows(c,
                    "SELECT t.ckiller, t.kills, " +
                    logf +
                    ''' FROM top_killers t, killer_recent_kills k
                       WHERE t.ckiller = k.ckiller
                         AND t.ckiller NOT IN ('leaving', 'quitting', 'winning')
                       ORDER BY t.kills DESC, t.ckiller''')
  def fix_killer_row(r):
    perc = calc_perc_pretty(r[1], deaths) + '%'
    g = row_to_xdict(r[2:])
    return [r[0], perc, r[1], linked_text(g, morgue_link, g['name'])]
  return [fix_killer_row(x) for x in rows]
コード例 #7
0
ファイル: stats.py プロジェクト: zijingng/scoring
 def _player_create_streak_from_first(self, c, player, g):
   query_do(c, '''INSERT INTO streaks
                              (player, start_game_time, end_game_time,
                               active, ngames)
                       VALUES (%s, %s, %s, %s, %s)''',
            player, g['end_time'], g['end_time'],
            True, 0)
   sid = query_first(c, '''SELECT id FROM streaks
                                     WHERE player = %s AND active = 1''',
                      player)
   if self.db_streaks.has_key(player):
     error("Player %s already has an ongoing streak!" % player)
   self.db_streaks[player] = sid
   # return the newly-created streak id
   return sid
コード例 #8
0
ファイル: stats.py プロジェクト: floraline/scoring
def update_player_best_games(c, g):
    player = g['name']
    if player_best_game_count(c, player) >= MAX_PLAYER_BEST_GAMES:
        if g['sc'] > player_lowest_highscore(c, player):
            query_do(
                c, '''DELETE FROM player_best_games WHERE id = %s''',
                query_first(
                    c, '''SELECT id FROM player_best_games
                                       WHERE name = %s
                                    ORDER BY sc LIMIT 1''', player))
            insert_game(c, g, 'player_best_games')
            player_lowest_highscore.flush_key(player)
    else:
        insert_game(c, g, 'player_best_games')
        player_best_game_count.flush_key(player)
コード例 #9
0
ファイル: stats.py プロジェクト: floraline/scoring
def update_topN(c, g, n):
    if topN_count(c) >= n:
        if g['sc'] > lowest_highscore(c):
            query_do(
                c, '''DELETE FROM top_games
                          WHERE id = %s''',
                query_first(
                    c, '''SELECT id FROM top_games
                                  ORDER BY sc LIMIT 1'''))
            insert_game(c, g, 'top_games')
            lowest_highscore.flush()
            dirty_pages('top-N', 'overview')
    else:
        insert_game(c, g, 'top_games')
        dirty_pages('top-N', 'overview')
        topN_count.flush()
コード例 #10
0
def top_killers(c):
    deaths = query_first(c, '''SELECT SUM(kills) FROM top_killers''')
    logf = logfields_prefixed('k.')
    rows = query_rows(
        c, "SELECT t.ckiller, t.kills, " + logf +
        ''' FROM top_killers t, killer_recent_kills k
                       WHERE t.ckiller = k.ckiller
                         AND t.ckiller NOT IN ('leaving', 'quitting', 'winning')
                       ORDER BY t.kills DESC, t.ckiller''')

    def fix_killer_row(r):
        perc = calc_perc_pretty(r[1], deaths) + '%'
        g = row_to_xdict(r[2:])
        return [r[0], perc, r[1], linked_text(g, morgue_link, g['name'])]

    return [fix_killer_row(x) for x in rows]
コード例 #11
0
ファイル: stats.py プロジェクト: zijingng/scoring
def update_topN(c, g, n):
  if topN_count(c) >= n:
    if g['sc'] > lowest_highscore(c):
      # note: for some reason this particular query is faster than just a simple
      # DELETE FROM ... ORDER BY query.
      query_do(c,'''DELETE FROM top_games
                          WHERE id = %s''',
               query_first(c, '''SELECT id FROM top_games
                                  ORDER BY sc LIMIT 1'''))
      insert_game(c, g, 'top_games')
      lowest_highscore.flush()
      dirty_pages('top-N', 'overview')
  else:
    insert_game(c, g, 'top_games')
    dirty_pages('top-N', 'overview')
    topN_count.flush()
コード例 #12
0
def fixup_month(c, month):
    mwin = month['winners'].items()
    month['players'] = query_first(
        c, '''SELECT COUNT(DISTINCT player)
                                        FROM date_players
                                       WHERE which_month = %s''',
        month['month'].replace('-', ''))

    def sort_winners(a, b):
        if a[1] != b[1]:
            return int(b[1] - a[1])
        else:
            return (a[1] < b[1] and -1) or (a[1] > b[1] and 1) or 0

    mwin.sort(sort_winners)
    month['winners'] = fixup_winners(mwin)
    return month
コード例 #13
0
ファイル: stats.py プロジェクト: zijingng/scoring
  def _player_create_streak_from_last(self, c, player):
    end_time = player_last_game_end_time(c, player)
    query_do(c, '''INSERT INTO streaks
                               (player, start_game_time, end_game_time,
                                active, ngames)
                        VALUES (%s, %s, %s, %s, %s)''',
             player, end_time, end_time,
             True, 1)

    # Record the game that started the streak:
    query_do(c,
             "INSERT INTO streak_games (" + scload.LOG_DB_SCOLUMNS + ") " +
             "SELECT " + scload.LOG_DB_SCOLUMNS +
             ''' FROM player_last_games WHERE name = %s''', player)

    sid = query_first(c, '''SELECT id FROM streaks
                                      WHERE player = %s AND active = 1''',
                         player)
    if self.db_streaks.has_key(player):
      error("Player %s already has an ongoing streak!" % player)
    # return the newly-created streak id
    self.db_streaks[player] = sid
    return sid
コード例 #14
0
ファイル: stats.py プロジェクト: crawl/scoring
def player_recent_game_count(c, player):
  return query_first(c, '''SELECT COUNT(*) FROM player_recent_games
                                          WHERE name = %s''',
                     player)
コード例 #15
0
ファイル: stats.py プロジェクト: crawl/scoring
def player_lowest_highscore(c, player):
  return query_first(c, '''SELECT MIN(sc) FROM player_best_games
                                         WHERE name = %s''',
                     player)
コード例 #16
0
ファイル: stats.py プロジェクト: floraline/scoring
def ziggurat_entry_count(c):
    return query_first(c, '''SELECT COUNT(*) FROM ziggurats''')
コード例 #17
0
ファイル: stats.py プロジェクト: crawl/scoring
def lowest_highscore(c):
  return query_first(c, '''SELECT MIN(sc) FROM top_games''')
コード例 #18
0
ファイル: stats.py プロジェクト: floraline/scoring
def player_last_game_end_time(c, player):
    return query_first(
        c, '''SELECT end_time FROM player_last_games
                                          WHERE name = %s''', player)
コード例 #19
0
ファイル: stats.py プロジェクト: crawl/scoring
def low_xl_rune_count(c):
  return query_first(c, '''SELECT COUNT(*) FROM low_xl_rune_finds''')
コード例 #20
0
ファイル: stats.py プロジェクト: crawl/scoring
def player_active_streak_id(c, player):
  return query_first(c, '''SELECT id FROM streaks
                                    WHERE player = %s AND active = 1''',
                     player)
コード例 #21
0
ファイル: stats.py プロジェクト: floraline/scoring
def lowest_highscore(c):
    return query_first(c, '''SELECT MIN(sc) FROM top_games''')
コード例 #22
0
def count_players_per_day(c, day):
    return query_first(
        c, '''SELECT COUNT(*) FROM date_players
                                       WHERE which_day = %s''', day)
コード例 #23
0
ファイル: stats.py プロジェクト: floraline/scoring
def player_lowest_highscore(c, player):
    return query_first(
        c, '''SELECT MIN(sc) FROM player_best_games
                                         WHERE name = %s''', player)
コード例 #24
0
ファイル: stats.py プロジェクト: floraline/scoring
def low_xl_rune_count(c):
    return query_first(c, '''SELECT COUNT(*) FROM low_xl_rune_finds''')
コード例 #25
0
ファイル: stats.py プロジェクト: floraline/scoring
def player_recent_game_count(c, player):
    return query_first(
        c, '''SELECT COUNT(*) FROM player_recent_games
                                          WHERE name = %s''', player)
コード例 #26
0
ファイル: stats.py プロジェクト: floraline/scoring
def player_active_streak_id(c, player):
    return query_first(
        c, '''SELECT id FROM streaks
                                    WHERE player = %s AND active = 1''',
        player)
コード例 #27
0
ファイル: stats.py プロジェクト: crawl/scoring
def all_recent_game_count(c):
  return query_first(c, '''SELECT COUNT(*) FROM all_recent_games''')
コード例 #28
0
ファイル: stats.py プロジェクト: crawl/scoring
def player_last_game_end_time(c, player):
  return query_first(c, '''SELECT end_time FROM player_last_games
                                          WHERE name = %s''',
                     player)
コード例 #29
0
ファイル: query.py プロジェクト: elliptic/dcss_scoring
def count_players_per_day(c, day):
  return query_first(c,
                     '''SELECT COUNT(*) FROM date_players
                                       WHERE which_day = %s''',
                     day)
コード例 #30
0
ファイル: stats.py プロジェクト: floraline/scoring
def topN_count(c):
    return query_first(c, '''SELECT COUNT(*) FROM top_games''')
コード例 #31
0
ファイル: stats.py プロジェクト: crawl/scoring
def topN_count(c):
  return query_first(c, '''SELECT COUNT(*) FROM top_games''')
コード例 #32
0
ファイル: stats.py プロジェクト: crawl/scoring
def ziggurat_entry_count(c):
  return query_first(c, '''SELECT COUNT(*) FROM ziggurats''')
コード例 #33
0
ファイル: stats.py プロジェクト: floraline/scoring
def all_recent_game_count(c):
    return query_first(c, '''SELECT COUNT(*) FROM all_recent_games''')