<commit_before>require 'time'

require_relative 'parser'
require_relative 'player'

# This is the format of one log line.
# First capture group is the time, second capture group is text.
# Only log lines said by ResistanceBot are considered.
# (For now we don't log what players said during the game)
TEXT_LINE = /^(\d{4}-\d\d-\d\d \d\d:\d\d:\d\d) <[@+]?\s+resistancebot_?> (.*)$/i

parser = Parser.new

# If it's a valid path to a file, it's a filename, else it's a player.
filenames, players = ARGV.partition { |x| File.exist?(x) }

filenames.each { |filename|
  File.open(filename, ?r).each_line.grep(TEXT_LINE) { |line|
    time = Regexp.last_match(1)
    text = Regexp.last_match(2)

    parser.parse(text, time)
  }
}

games = parser.games

puts "#{games.size} games"

#ignore reset games
games.select!(&:winning_side)
puts "#{games.size} non-reset games"
puts

longest_game = games.max_by(&:duration)
puts "Longest game: #{longest_game} with #{longest_game.duration}"
puts

longest_assassination_game = games.max_by(&:assassination_duration)
puts "Longest assassination game: #{longest_assassination_game} with #{longest_assassination_game.assassination_duration}"
puts

# Global stats
def game_stats(games)
  av_games, base_games = games.partition(&:avalon?)

  base_res_win = base_games.count { |x| x.winning_side == :resistance }
  base_spy_win = base_games.count { |x| x.winning_side == :spies }

  av_res_win = av_games.count { |x| x.winning_side == :resistance }
  av_spy_mission = av_games.count { |x| x.winning_side == :spies && !x.assassin_target }
  av_spy_assassinate = av_games.count { |x| x.winning_side == :spies && x.assassin_target }

  <<-STATS.gsub(/^  /, '')
  #{base_games.size} base games. #{base_res_win} res wins. #{base_spy_win} spy wins.<commit_msg>parse_games: Show how long the record-holding games lasted<commit_after>require 'time'

require_relative 'parser'
require_relative 'player'

# This is the format of one log line.
# First capture group is the time, second capture group is text.
# Only log lines said by ResistanceBot are considered.
# (For now we don't log what players said during the game)
TEXT_LINE = /^(\d{4}-\d\d-\d\d \d\d:\d\d:\d\d) <[@+]?\s+resistancebot_?> (.*)$/i

parser = Parser.new

# If it's a valid path to a file, it's a filename, else it's a player.
filenames, players = ARGV.partition { |x| File.exist?(x) }

filenames.each { |filename|
  File.open(filename, ?r).each_line.grep(TEXT_LINE) { |line|
    time = Regexp.last_match(1)
    text = Regexp.last_match(2)

    parser.parse(text, time)
  }
}

games = parser.games

puts "#{games.size} games"

#ignore reset games
games.select!(&:winning_side)
puts "#{games.size} non-reset games"
puts

longest_game = games.max_by(&:duration)
puts "Longest game: #{longest_game} from #{longest_game.start_time} to #{longest_game.end_time} lasting #{longest_game.duration / 60.0} mins"
puts

longest_assassination_game = games.max_by(&:assassination_duration)
puts "Longest assassination game: #{longest_assassination_game} from #{longest_assassination_game.mission_end_time} to #{longest_assassination_game.assassination_end_time} lasting #{longest_assassination_game.assassination_duration / 60.0} mins"
puts

# Global stats
def game_stats(games)
  av_games, base_games = games.partition(&:avalon?)

  base_res_win = base_games.count { |x| x.winning_side == :resistance }
  base_spy_win = base_games.count { |x| x.winning_side == :spies }

  av_res_win = av_games.count { |x| x.winning_side == :resistance }
  av_spy_mission = av_games.count { |x| x.winning_side == :spies && !x.assassin_target }
  av_spy_assassinate = av_games.count { |x| x.winning_side == :spies && x.assassin_target }

  <<-STATS.gsub(/^  /, '')
  #{base_games.size} base games. #{base_res_win} res wins. #{base_spy_win} spy wins.
{'fraction_non_alphanumeric': 0.13981603153745073, 'fraction_numerical': 0.0031537450722733244, 'mean_word_length': 4.810687022900764, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2918206', 'n_tokens_mistral': 1460, 'n_tokens_neox': 1397, 'n_words': 336}