<commit_before>module TimeSplitTracker
  def self.to_s
    "Time Split Tracker"
  end

  def self.to_sym
    :timesplittracker
  end

  def self.file_extension
    'timesplittracker'
  end

  def self.website
    'https://dunnius.itch.io/time-split-tracker-windows'
  end

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

    rule :first_line,  :attempts, :tab, /([^\t\r\n]*)/, :optional_tab, :game_name, :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 :game_name,       /([^\r\n]*)/
    rule :duration,   :time
    rule :image_path, /([^\t\r\n]*)/

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

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

    def parse(file, options = {})
      return unless file.ascii_only?

      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),
        history: [],
        indexed_history: {}
      }
    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| duration_in_seconds_of(s.duration.to_s) }.sum)
      end
    end

    def parse_split(segment, run_duration_so_far)
      Split.new.tap do |split|
        split.name = segment.title.to_s<commit_msg>Fix a TimeSplitTracker parsing issue<commit_after>module TimeSplitTracker
  def self.to_s
    "Time Split Tracker"
  end

  def self.to_sym
    :timesplittracker
  end

  def self.file_extension
    'timesplittracker'
  end

  def self.website
    'https://dunnius.itch.io/time-split-tracker-windows'
  end

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

    rule :first_line,  :attempts, :tab, /([^\t\r\n]*)/, :optional_tab, :game_name, :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 :game_name,       /([^\r\n]*)/
    rule :duration,   :time
    rule :image_path, /([^\t\r\n]*)/

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

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

    def parse(file, options = {})
      if file.nil? || file.ascii_only?
        return nil
      end

      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),
        history: [],
        indexed_history: {}
      }
    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| duration_in_seconds_of(s.duration.to_s) }.sum)
      end
    end

    def parse_split(segment, run_duration_so_far)
      Split.new.tap do |split|
        split.name = segment.title.to_s
{'fraction_non_alphanumeric': 0.15127919911012236, 'fraction_numerical': 0.0016685205784204673, 'mean_word_length': 2.3060661764705883, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '7200266', 'n_tokens_mistral': 1383, 'n_tokens_neox': 1327, 'n_words': 278}