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)
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
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)
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)