<commit_before>require_relative "../../lib/brest_parser/brest_stats"
require_relative "../../lib/brest_parser/brest_parser"
require_relative "../../lib/puzzle_renamer"

Sequel.migration do
  change do

    create_table :stats do
      primary_key :id
      Integer :solve_id
      String :name
      Float :time
      Float :stm
      Float :etm
      Integer :position
    end

    from(:solves).exclude(source_content: nil).each do |solve|

      begin
        RCDB::BrestParser.new(solve[:source_content]).solves[solve[:position_in_average]][:stats].each.with_index do |(name, values), position|
        time = values["Time"] 
        stm = values["STM"]
        etm = values["ETM"]
        from(:stats).insert(name: name,
                            time: time,
                            stm: stm,
                            etm: etm,
                            solve_id: solve[:id],
                            position: position,
                           )
        rescue Exception
          # If something goes wrong, this stat did not parse properly, so we'll leave it blank.
        end
      end
    end
  end

end<commit_msg>Fix migration<commit_after>require_relative "../../lib/brest_parser/brest_stats"
require_relative "../../lib/brest_parser/brest_parser"
require_relative "../../lib/puzzle_renamer"

Sequel.migration do
  change do

    create_table :stats do
      primary_key :id
      Integer :solve_id
      String :name
      Float :time
      Float :stm
      Float :etm
      Integer :position
    end

    from(:solves).exclude(source_content: nil).each do |solve|

      begin
        RCDB::BrestParser.new(solve[:source_content]).solves[solve[:position_in_average]][:stats].each.with_index do |(name, values), position|
        time = values["Time"] 
        stm = values["STM"]
        etm = values["ETM"]
        from(:stats).insert(name: name,
                            time: time,
                            stm: stm,
                            etm: etm,
                            solve_id: solve[:id],
                            position: position,
                           )
        end
      rescue
        # If something goes wrong, this stat did not parse properly, so we'll leave it blank.
      end
    end
  end

end
{'fraction_non_alphanumeric': 0.10308370044052863, 'fraction_numerical': 0.0, 'mean_word_length': 1.6686251468860165, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2213794', 'n_tokens_mistral': 653, 'n_tokens_neox': 642, 'n_words': 155}