<commit_before>class UserLog < ActiveRecord::Base

  belongs_to :user
  delegate :email, to: :user, prefix: true

  has_one :error_log, dependent: :destroy
  delegate :id, :message, to: :error_log, prefix: true

  def self.except(cname, aname)
    log_except = [
        {controller: 'user_logs', action: 'index'},
        {controller: 'error_logs', action: 'index'}
    ]
    log_except.each { |x| return false if (x[:action] == aname || aname.nil?) if (x[:controller] == cname) }
    true
  end

  def self.handle_log(request, response, cname, aname, user)

    opts = {
        remote_addr: request.remote_ip,
        session_id: request.session_options[:id],
        status: response.status,
        method: request.method,
        controller: cname,
        action: aname,
        domain: request.domain,
        request_uri: request.fullpath,
        url: request.url,
        protocol: request.protocol,
        host: request.host,
        port: request.port,
        user_params: request.params.to_json,
        user_session: request.session.to_json,
        query_string: request.query_string,
        http_accept: request.headers['HTTP_ACCEPT'],
        format: request.format.to_json,
        ssl: request.ssl?,
        xhr: !request.xhr?.nil?,
        referer: request.env['HTTP_REFERER'],
        http_user_agent: request.headers['HTTP_USER_AGENT'],
        server_software: request.headers['SERVER_SOFTWARE'],
        content_type: response.content_type
    }

    (user ?
        user.user_logs.create!(opts) :
        create!(opts)) if except(cname, aname)
  end

  def self.fetch_data(user)
    user.user_logs.all.order('id DESC').includes(:error_log)
  end

end<commit_msg>fix format<commit_after>class UserLog < ActiveRecord::Base

  belongs_to :user
  delegate :email, to: :user, prefix: true

  has_one :error_log, dependent: :destroy
  delegate :id, :message, to: :error_log, prefix: true

  def self.except(cname, aname)
    log_except = [
        {controller: 'user_logs', action: 'index'},
        {controller: 'error_logs', action: 'index'}
    ]
    log_except.each { |x| return false if (x[:action] == aname || aname.nil?) if (x[:controller] == cname) }
    true
  end

  def self.handle_log(request, response, cname, aname, user)

    opts = {
        remote_addr: request.remote_ip,
        session_id: request.session_options[:id],
        status: response.status,
        method: request.method,
        controller: cname,
        action: aname,
        domain: request.domain,
        request_uri: request.fullpath,
        url: request.url,
        protocol: request.protocol,
        host: request.host,
        port: request.port,
        user_params: request.params.to_json,
        user_session: request.session.to_json,
        query_string: request.query_string,
        http_accept: request.headers['HTTP_ACCEPT'],
        #format: request.format.to_json,
        ssl: request.ssl?,
        xhr: !request.xhr?.nil?,
        referer: request.env['HTTP_REFERER'],
        http_user_agent: request.headers['HTTP_USER_AGENT'],
        server_software: request.headers['SERVER_SOFTWARE'],
        content_type: response.content_type
    }

    (user ?
        user.user_logs.create!(opts) :
        create!(opts)) if except(cname, aname)
  end

  def self.fetch_data(user)
    user.user_logs.all.order('id DESC').includes(:error_log)
  end

end
{'fraction_non_alphanumeric': 0.12218934911242603, 'fraction_numerical': 0.0, 'mean_word_length': 2.8507972665148062, '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': '1034266', 'n_tokens_mistral': 1075, 'n_tokens_neox': 1060, 'n_words': 226}