<commit_before>module Gricer
  class Request < ::ActiveRecord::Base
    set_table_name "#{::Gricer::config.table_name_prefix}requests"
    include ActiveModel::Statistics
    
    belongs_to :session, class_name: 'Gricer::Session', counter_cache: true
    belongs_to :agent, class_name: 'Gricer::Agent', counter_cache: true
    
    before_create :init_session
    
    def self.browsers
      includes("agent")
      .where("\"#{Agent.table_name}\".\"agent_class_id\" IN (?)", [0x1000, 0x2000])
    end
    
    def self.only_first_in_session
      where('is_first_in_session = ?', true)
    end
    
    def ip_address=(ip)
      @ip_address = ip
    end
    
    def agent_header=(agent_header)
      self.agent = Agent.find_or_create_by_request_header agent_header
    end
    
    def request=(request)
      logger.debug 'request='
      
      self.ip_address   = request.remote_ip
      self.agent_header = request.headers['HTTP_USER_AGENT']
      self.referer      = request.headers['HTTP_REFERER']
      
      logger.debug '(1)'
      <commit_msg>User forwarded referer if given (behind proxy mode)<commit_after>module Gricer
  class Request < ::ActiveRecord::Base
    set_table_name "#{::Gricer::config.table_name_prefix}requests"
    include ActiveModel::Statistics
    
    belongs_to :session, class_name: 'Gricer::Session', counter_cache: true
    belongs_to :agent, class_name: 'Gricer::Agent', counter_cache: true
    
    before_create :init_session
    
    def self.browsers
      includes("agent")
      .where("\"#{Agent.table_name}\".\"agent_class_id\" IN (?)", [0x1000, 0x2000])
    end
    
    def self.only_first_in_session
      where('is_first_in_session = ?', true)
    end
    
    def ip_address=(ip)
      @ip_address = ip
    end
    
    def agent_header=(agent_header)
      self.agent = Agent.find_or_create_by_request_header agent_header
    end
    
    def request=(request)
      logger.debug 'request='
      
      self.ip_address   = request.remote_ip
      self.agent_header = request.headers['HTTP_USER_AGENT']
      self.referer      = request.headers['HTTP_X_FORWARDED_REFERER'] || request.headers['HTTP_REFERER']
      
      logger.debug '(1)'
      
{'fraction_non_alphanumeric': 0.11040436165379373, 'fraction_numerical': 0.009995456610631531, 'mean_word_length': 3.025594149908592, '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': '5081377', 'n_tokens_mistral': 730, 'n_tokens_neox': 720, 'n_words': 126}