<commit_before>class TimeSplitTrackerParser < BabelBridge::Parser
  rule :timesplittracker_file, :first_line, :title_line, many?(:splits)

  rule :first_line,  :attempts, :tab, /([^\t\r\n]*)/, :tab, :newline
  rule :title_line,  :title, :tab, /([^\t\r\n]*)/, :newline
  rule :splits,      :title, :tab, :duration, :newline, :image_path, :tab, :newline

  rule :attempts,   /([^\t\r\n]*)/
  rule :title,      /([^\t]*)/
  rule :duration,   :time
  rule :image_path, /([^\t\r\n]*)/

  rule :time,       /(\d*\.\d*)/

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

  def parse(file)
    run = super(file)
    return nil if run.nil?
    {
      name: run.title.to_s,
      attempts: run.attempts.to_s.to_i,
      offset: run.offset.to_f,
      splits: parse_splits(run.splits)
    }
  end

  private

  def parse_splits(splits)
    splits.map.with_index do |split, index|
      parse_split(split, index == 0 ? 0 : splits.slice(0, index).map { |s| s.duration.to_s.to_f }.sum)
    end
  end

  def parse_split(split, run_duration_so_far)
    {
      best: {},
      name: split.title,
      duration: split.duration.to_s.to_f,
      finish_time: run_duration_so_far + split.duration.to_s.to_f<commit_msg>Fix a bug that caused Time Split Tracker runs to error<commit_after>class TimeSplitTrackerParser < BabelBridge::Parser
  rule :timesplittracker_file, :first_line, :title_line, many?(:splits)

  rule :first_line,  :attempts, :tab, /([^\t\r\n]*)/, :tab, :newline
  rule :title_line,  :title, :tab, /([^\t\r\n]*)/, :newline
  rule :splits,      :title, :tab, :duration, :newline, :image_path, :tab, :newline

  rule :attempts,   /([^\t\r\n]*)/
  rule :title,      /([^\t]*)/
  rule :duration,   :time
  rule :image_path, /([^\t\r\n]*)/

  rule :time,       /(\d*\.\d*)/

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

  def parse(file)
    run = super(file)
    return nil if run.nil?
    {
      name: run.title.to_s,
      attempts: run.attempts.to_s.to_i,
      offset: run.offset.to_f,
      splits: parse_splits(run.splits)
    }
  end

  private

  def parse_splits(splits)
    splits.map.with_index do |split, index|
      parse_split(split, index == 0 ? 0 : splits.slice(0, index).map { |s| s.duration.to_s.to_f }.sum)
    end
  end

  def parse_split(split, run_duration_so_far)
    {
      best: {},
      name: split.title.to_s,
      duration: split.duration.to_s.to_f,
      finish_time: run_duration_so_far + split.duration.to_s.to_f
{'fraction_non_alphanumeric': 0.16283382789317508, 'fraction_numerical': 0.002225519287833828, 'mean_word_length': 2.7251381215469612, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1664057', 'n_tokens_mistral': 1091, 'n_tokens_neox': 1057, 'n_words': 221}