<commit_before>class WSplitParser < BabelBridge::Parser
  rule :wsplit_file, :title_line, :attempts_line, :offset_line, :size_line, many?(:splits), :icons_line

  rule :title_line,    'Title=',     :title,    :newline
  rule :attempts_line, 'Attempts=',  :attempts, :newline
  rule :offset_line,   'Offset=',    :offset,   :newline
  rule :size_line,     'Size=',      :size,     :newline
  rule :splits,        :title,       ',',       :old_time, ',', :run_time, ',', :best_time, :newline
  rule :icons_line,    'Icons=',     /(.*)/,    :newline?

  rule :title,    /([^,\r\n]*)/
  rule :attempts, /(\d+)/
  rule :offset,   /(\d*\.?\d*)/
  rule :size,     /([^\r\n]*)/

  rule :old_time,  :time
  rule :run_time,  :time
  rule :best_time, :time

  rule :time,    /([\d\.]+)/

  rule :newline,         :windows_newline
  rule :newline,         :unix_newline
  rule :windows_newline, "\r\n"
  rule :unix_newline,    "\n"

  def parse(file)
    splits = super(file)
    return nil unless splits
    run = {}
    run[:game] = nil
    run[:name] = splits.title.to_s
    run[:attempts] = splits.attempts.to_s.to_i
    run[:offset] = splits.offset.to_f
    run[:splits] = []
    run[:time] = 0
    splits.splits.each do |segment|
      split = {}
      split[:best] = {}
      split[:name] = segment.title
      split[:duration] = segment.run_time.to_s.to_f - run[:time]
      split[:finish_time] = segment.run_time.to_s.to_f
      split[:best][:duration] = segment.best_time.to_s.to_f
      run[:time] += split[:duration]
      run[:splits] << split
    end
    run
  rescue
    nil
  end
end<commit_msg>Fix a 500 for WSplit files rendered in json<commit_after>class WSplitParser < BabelBridge::Parser
  rule :wsplit_file, :title_line, :attempts_line, :offset_line, :size_line, many?(:splits), :icons_line

  rule :title_line,    'Title=',     :title,    :newline
  rule :attempts_line, 'Attempts=',  :attempts, :newline
  rule :offset_line,   'Offset=',    :offset,   :newline
  rule :size_line,     'Size=',      :size,     :newline
  rule :splits,        :title,       ',',       :old_time, ',', :run_time, ',', :best_time, :newline
  rule :icons_line,    'Icons=',     /(.*)/,    :newline?

  rule :title,    /([^,\r\n]*)/
  rule :attempts, /(\d+)/
  rule :offset,   /(\d*\.?\d*)/
  rule :size,     /([^\r\n]*)/

  rule :old_time,  :time
  rule :run_time,  :time
  rule :best_time, :time

  rule :time,    /([\d\.]+)/

  rule :newline,         :windows_newline
  rule :newline,         :unix_newline
  rule :windows_newline, "\r\n"
  rule :unix_newline,    "\n"

  def parse(file)
    splits = super(file)
    return nil unless splits
    run = {}
    run[:game] = nil
    run[:name] = splits.title.to_s
    run[:attempts] = splits.attempts.to_s.to_i
    run[:offset] = splits.offset.to_f
    run[:splits] = []
    run[:time] = 0
    splits.splits.each do |segment|
      split = {}
      split[:best] = {}
      split[:name] = segment.title.to_s
      split[:duration] = segment.run_time.to_s.to_f - run[:time]
      split[:finish_time] = segment.run_time.to_s.to_f
      split[:best][:duration] = segment.best_time.to_s.to_f
      run[:time] += split[:duration]
      run[:splits] << split
    end
    run
  rescue
    nil
  end
end
{'fraction_non_alphanumeric': 0.1735230436127436, 'fraction_numerical': 0.001546551190844417, 'mean_word_length': 2.650112866817156, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, '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': '6846482', 'n_tokens_mistral': 1279, 'n_tokens_neox': 1229, 'n_words': 251}