<commit_before>class StatusController < ApplicationController
  def index
    @commit_hash = ENV['COMMIT_HASH']
    session[:tmp] = 1
    session.delete(:tmp)
    @session_id = request.session_options[:id]
    @user_agent = request.env['HTTP_USER_AGENT']

    @can_update_session = can_update_session?

    if @can_update_session
      params.each do |p|
        key = p[0].gsub('__', ' ')
        if session.has_key?(key) then
          session[key] = convert_type(p[1], session[key].class)
        end
      end
    end
  end

  def convert_type(value, clazz)
    if clazz == FalseClass || clazz == TrueClass
      return false if value == "false"
      return true if value == "true"
    end

    return value.to_i if clazz == Fixnum
    return value if clazz == String
    raise "Conversion not yet specified for class: '#{clazz}'"
  end

  def can_update_session?
    return (params['debug_token'] == ENV['VK_DEBUG_TOKEN'])
  end
end<commit_msg>put type conversion into a map to de-if it a bit<commit_after>class StatusController < ApplicationController
  def index
    @commit_hash = ENV['COMMIT_HASH']
    session[:tmp] = 1
    session.delete(:tmp)
    @session_id = request.session_options[:id]
    @user_agent = request.env['HTTP_USER_AGENT']

    @can_update_session = can_update_session?

    if @can_update_session
      params.each do |p|
        key = p[0].gsub('__', ' ')
        if session.has_key?(key) then
          session[key] = convert_type(p[1], session[key].class)
        end
      end
    end
  end

  def convert_type(value, clazz)
    boolean_converter = ->(s){ s == "true" ? true : false}
    type_converters = {
      Fixnum => ->(s){s.to_i},
      Float => ->(s){s.to_f},
      Date => ->(s){s.to_date},
      TrueClass => boolean_converter,
      FalseClass => boolean_converter, String => ->(s){s}
    }
    tc = type_converters[clazz]
    raise "Conversion not yet specified for class: '#{clazz}'" if not tc
    tc[value]
  end

  def can_update_session?
    return (params['debug_token'] == ENV['VK_DEBUG_TOKEN'])
  end

end
{'fraction_non_alphanumeric': 0.1267605633802817, 'fraction_numerical': 0.0029140359397765905, 'mean_word_length': 3.0, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 14, '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': '1063902', 'n_tokens_mistral': 699, 'n_tokens_neox': 692, 'n_words': 164}