Example #1
0
def update_player_stats(c, g):
    global player_stats_cache, all_recent_games_cache, streaks_cache
    global player_recent_cache, player_best_cache, wins_cache
    winc = game_is_win(g) and 1 or 0

    if player_recent_cache.game_key_exists(c, g):
        error("Ignoring duplicate game '%s' from logfile '%s'" %
              (g.get('game_key'), g.get('source_file')))
        return False

    player_recent_cache.update(g)

    if winc:
        dirty_page('best-players-total-score')
        dirty_page('all-players')
        dirty_player(g['name'])
    else:
        if g['sc'] > 0:
            factor = int(g['sc'] / 40000) + 1
            dirty_page('best-players-total-score', factor)
            dirty_page('all-players', factor)
            dirty_player(g['name'], factor)
        else:
            dirty_player(g['name'], 1)

    player_stats_cache.update(g)

    streaks_cache.init_from_db(c)  # TODO: could do this somewhere else
    streaks_cache.update(g)

    player_best_cache.update(g)
    all_recent_games_cache.update(g)
    wins_cache.update(g)
    update_player_first_game(c, g)
    return True
Example #2
0
def update_per_day_stats(c, g):
  if is_junk_game(g):
    return

  # Grab just the date portion.
  edate = g['end_time'][:8]
  winc = game_is_win(g) and 1 or 0

  count_players_per_day.flush_key(edate)
  if winc:
    winners_for_day.flush_key(edate)

  query_do(c, '''INSERT INTO per_day_stats (which_day, games_ended,
                                            games_won)
                                    VALUES (%s, %s, %s)
                        ON DUPLICATE KEY UPDATE
                                     games_ended = games_ended + 1,
                                     games_won = games_won + %s''',
           edate, 1, winc, winc)

  player = g['name']
  query_do(c, '''INSERT INTO date_players (which_day, which_month, player,
                                           games, wins)
                                   VALUES (%s, %s, %s, %s, %s)
                        ON DUPLICATE KEY UPDATE
                                        games = games + 1,
                                        wins = wins + %s''',
           edate, edate[:6], player, 1, winc, winc)
Example #3
0
    def update(self, g):
        lname = g['name'].lower()
        winc = game_is_win(g) and 1 or 0
        if not self.pl_char.has_key((lname, g['charabbr'])):
            self.pl_char[(lname, g['charabbr'])] = [1, g['xl'], winc]
        else:
            d = self.pl_char[(lname, g['charabbr'])]
            d[0] += 1
            d[1] = max(d[1], g['xl'])
            d[2] += winc

        if not self.players.has_key(lname):
            self.players[lname] = {
                'name': g['name'],
                'games_played': 1,
                'games_won': winc,
                'total_score': g['sc'],
                'best_score': g['sc'],
                'best_xl': g['xl'],
                'first_game_start': g['start_time'],
                'last_game_end': g['end_time'],
                'max_runes': g['urune']
            }
        else:
            d = self.players[lname]
            d['games_played'] += 1
            d['games_won'] += winc
            d['total_score'] += g['sc']
            d['best_score'] = max(d['best_score'], g['sc'])
            d['best_xl'] = max(d['best_xl'], g['xl'])
            # WARNING: game start/end time assumes lines are read in order here...
            # TODO: drop this assumption?
            d['last_game_end'] = g['end_time']
            d['max_runes'] = max(d['max_runes'], g['urune'])
Example #4
0
    def update(self, g):
        if is_junk_game(g):
            return

        # Grab just the date portion.
        edate = g['end_time'][:8]
        winc = game_is_win(g) and 1 or 0
        player = g['name']

        if not self.per_day_stats.has_key(edate):
            self.per_day_stats[edate] = [1, winc]
        else:
            self.per_day_stats[edate][0] += 1
            self.per_day_stats[edate][1] += winc

        if not self.date_players.has_key((edate, player)):
            self.date_players[(edate, player)] = [1, winc]
        else:
            self.date_players[(edate, player)][0] += 1
            self.date_players[(edate, player)][1] += winc

        # do the flush here because we are already working with the dates...
        # don't query these values until insert() has been called.
        # TODO: does it even make sense for these to be memoized?
        count_players_per_day.flush_key(edate)
        if winc:
            winners_for_day.flush_key(edate)
Example #5
0
def update_per_day_stats(c, g):
    if is_junk_game(g):
        return

    # Grab just the date portion.
    edate = g['end_time'][:8]
    winc = game_is_win(g) and 1 or 0

    count_players_per_day.flush_key(edate)
    if winc:
        winners_for_day.flush_key(edate)

    query_do(
        c, '''INSERT INTO per_day_stats (which_day, games_ended,
                                            games_won)
                                    VALUES (%s, %s, %s)
                        ON DUPLICATE KEY UPDATE
                                     games_ended = games_ended + 1,
                                     games_won = games_won + %s''', edate, 1,
        winc, winc)

    player = g['name']
    query_do(
        c, '''INSERT INTO date_players (which_day, which_month, player,
                                           games, wins)
                                   VALUES (%s, %s, %s, %s, %s)
                        ON DUPLICATE KEY UPDATE
                                        games = games + 1,
                                        wins = wins + %s''', edate, edate[:6],
        player, 1, winc, winc)
Example #6
0
def update_player_stats(c, g):
  winc = game_is_win(g) and 1 or 0

  if winc:
    dirty_page('best-players-total-score')
    dirty_page('all-players')
    dirty_player(g['name'])
  else:
    if g['sc'] > 0:
      factor = int(g['sc'] / 40000) + 1
      dirty_page('best-players-total-score', factor)
      dirty_page('all-players', factor)
      dirty_player(g['name'], factor)
    else:
      dirty_player(g['name'], 1)

  query_do(c, '''INSERT INTO players
                             (name, games_played, games_won,
                              total_score, best_score, best_xl,
                              first_game_start, last_game_end, max_runes)
                      VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)
                 ON DUPLICATE KEY UPDATE
                             games_played = games_played + 1,
                             games_won = games_won + %s,
                             total_score = total_score + %s,
                             best_score =
                                   CASE WHEN best_score < %s
                                        THEN %s
                                        ELSE best_score
                                        END,
                             best_xl =
                                   CASE WHEN best_xl < %s
                                        THEN %s
                                        ELSE best_xl
                                        END,
                             max_runes = CASE WHEN max_runes < %s
                                              THEN %s ELSE max_runes END,
                             last_game_end = %s,
                             current_combo = NULL''',
           g['name'], 1, winc, g['sc'], g['sc'], g['xl'], g['start_time'],
           g['end_time'], g['urune'],
           winc, g['sc'], g['sc'], g['sc'], g['xl'], g['xl'],
           g['urune'], g['urune'], g['end_time'])

  # Must be first!
  update_player_streak(c, g)

  update_player_best_games(c, g)
  update_player_char_stats(c, g)
  update_player_recent_games(c, g)
  update_all_recent_games(c, g)
  update_player_first_game(c, g)
  update_player_last_game(c, g)
  update_wins_table(c, g)
Example #7
0
def update_player_stats(c, g):
    winc = game_is_win(g) and 1 or 0

    if winc:
        dirty_page('best-players-total-score')
        dirty_page('all-players')
        dirty_player(g['name'])
    else:
        if g['sc'] > 0:
            factor = int(g['sc'] / 40000) + 1
            dirty_page('best-players-total-score', factor)
            dirty_page('all-players', factor)
            dirty_player(g['name'], factor)
        else:
            dirty_player(g['name'], 1)

    query_do(
        c, '''INSERT INTO players
                             (name, games_played, games_won,
                              total_score, best_score, best_xl,
                              first_game_start, last_game_end, max_runes)
                      VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)
                 ON DUPLICATE KEY UPDATE
                             games_played = games_played + 1,
                             games_won = games_won + %s,
                             total_score = total_score + %s,
                             best_score =
                                   CASE WHEN best_score < %s
                                        THEN %s
                                        ELSE best_score
                                        END,
                             best_xl =
                                   CASE WHEN best_xl < %s
                                        THEN %s
                                        ELSE best_xl
                                        END,
                             max_runes = CASE WHEN max_runes < %s
                                              THEN %s ELSE max_runes END,
                             last_game_end = %s,
                             current_combo = NULL''', g['name'], 1, winc,
        g['sc'], g['sc'], g['xl'], g['start_time'], g['end_time'], g['urune'],
        winc, g['sc'], g['sc'], g['sc'], g['xl'], g['xl'], g['urune'],
        g['urune'], g['end_time'])

    # Must be first!
    update_player_streak(c, g)

    update_player_best_games(c, g)
    update_player_char_stats(c, g)
    update_player_recent_games(c, g)
    update_all_recent_games(c, g)
    update_player_first_game(c, g)
    update_player_last_game(c, g)
    update_wins_table(c, g)
Example #8
0
def update_player_char_stats(c, g):
  winc = game_is_win(g) and 1 or 0
  query_do(c, '''INSERT INTO player_char_stats
                             (name, charabbr, games_played, best_xl, wins)
                      VALUES (%s, %s, %s, %s, %s)
                 ON DUPLICATE KEY UPDATE games_played = games_played + 1,
                                         best_xl = CASE WHEN best_xl < %s
                                                        THEN %s
                                                        ELSE best_xl END,
                                         wins = wins + %s''',
           g['name'], g['charabbr'], 1, g['xl'], winc,
           g['xl'], g['xl'], winc)
Example #9
0
def update_player_char_stats(c, g):
    winc = game_is_win(g) and 1 or 0
    query_do(
        c, '''INSERT INTO player_char_stats
                             (name, charabbr, games_played, best_xl, wins)
                      VALUES (%s, %s, %s, %s, %s)
                 ON DUPLICATE KEY UPDATE games_played = games_played + 1,
                                         best_xl = CASE WHEN best_xl < %s
                                                        THEN %s
                                                        ELSE best_xl END,
                                         wins = wins + %s''', g['name'],
        g['charabbr'], 1, g['xl'], winc, g['xl'], g['xl'], winc)
Example #10
0
def update_player_streak(c, g):
  player = g['name']
  win = game_is_win(g)
  if not win:
    if player_streak_is_active(c, player):
      player_break_streak(c, player, g)
      player_streak_is_active.flush_key(player)
      dirty_pages('streaks', 'overview')
      dirty_player(player)
  else:
    if player_streak_is_active(c, player):
      player_extend_streak(c, player, g)
      dirty_pages('streaks', 'overview')
    elif player_won_last_game(c, player):
      player_create_streak(c, player, g)
      dirty_pages('streaks', 'overview')
      player_streak_is_active.flush_key(player)
Example #11
0
def update_player_streak(c, g):
    player = g['name']
    win = game_is_win(g)
    if not win:
        if player_streak_is_active(c, player):
            player_break_streak(c, player, g)
            player_streak_is_active.flush_key(player)
            dirty_pages('streaks', 'overview')
            dirty_player(player)
    else:
        if player_streak_is_active(c, player):
            player_extend_streak(c, player, g)
            dirty_pages('streaks', 'overview')
        elif player_won_last_game(c, player):
            player_create_streak(c, player, g)
            dirty_pages('streaks', 'overview')
            player_streak_is_active.flush_key(player)
Example #12
0
    def update(self, g):
        if game_is_buggy(g):
            return
        # at this point we treat 1-game win sequences as potential streaks, and
        # create a streak entry for them. When inserting into the db, we will
        # actually check whether they follow a win. # TODO: this could be better
        lname = g['name'].lower()
        if game_is_win(g) or self.ongoing_streak(lname):
            streak = self.streak_to_continue(lname)
            if streak.add_game(g):  # active streak
                self.cached_streaks[lname] = streak
                #info("    Adding %s to active streak %s, length %d", g['game_key'], repr(streak.db_id), len(streak.games))
            else:  # inactivate streak
                if self.cached_streaks.has_key(lname):
                    del self.cached_streaks[lname]
                if streak.min_known_len() > 1 or not streak.follows_known_loss:
                    #info("Closing streak for %s", g['name'])
                    self.cached_closed_streaks.append(streak)
                    self.cached_closed_streak_players.add(lname)
                #else:
                #  info("Dropping 1-streak for %s", g['name'])

        self.last_games[lname] = g
Example #13
0
def update_wins_table(c, g):
    if game_is_win(g):
        dirty_pages('winners', 'fastest-wins-turns', 'fastest-wins-time',
                    'overview')
        insert_game(c, g, 'wins')
Example #14
0
def update_wins_table(c, g):
  if game_is_win(g):
    dirty_pages('winners', 'fastest-wins-turns', 'fastest-wins-time',
                'overview')
    insert_game(c, g, 'wins')
Example #15
0
def player_top_thing_scores(c, player, table, label):
  return [(linked_text(g, morgue_link, g[label])
           + (game_is_win(g) and '*' or ''),
           g['sc'])
          for g in
          find_games(c, table, name=player, sort_max='sc')]
Example #16
0
def player_top_thing_scores(c, player, table, label):
    return [(linked_text(g, morgue_link, g[label]) +
             (game_is_win(g) and '*' or ''), g['sc'])
            for g in find_games(c, table, name=player, sort_max='sc')]
Example #17
0
 def _db_continue_streak(self, c, player, g, sid):
     if game_is_win(g):
         self._player_extend_streak(c, player, g)
     else:
         self._player_break_streak(c, player, g, sid)
Example #18
0
 def add_game(self, g):
     self.games.append(g)
     if not game_is_win(g):
         self.active = False
     return self.active
Example #19
0
 def update(self, g):
     if not game_is_win(g) or game_is_buggy(g):
         return
     dirty_pages('winners', 'fastest-wins-turns', 'fastest-wins-time',
                 'overview')
     self.games.append(g)