<commit_before>class ReportItem < ActiveRecord::Base
  belongs_to :report
  delegate :user, :to => 'report.shift'
  validates_presence_of :content, :report_id
  
  before_save :check_for_ip_address_change
  
  def content_with_formatting
    content.sanitize_and_format
  end
  
  def check_for_ip_address_change
    #if ip has changed from previous line item, note this
    previous_report_items = self.report.report_items
    self.content += " [IP Address changed to #{self.ip_address}]" if (!previous_report_items.empty? and previous_report_items.last.ip_address != self.ip_address)
  end
end<commit_msg>Added IP -> Hostname support<commit_after>require 'socket'

class ReportItem < ActiveRecord::Base
  belongs_to :report
  delegate :user, :to => 'report.shift'
  validates_presence_of :content, :report_id
  
  before_save :check_for_ip_address_change
  
  def content_with_formatting
    content.sanitize_and_format
  end
  
  def check_for_ip_address_change
    #if ip has changed from previous line item, note this
    previous_report_items = self.report.report_items
    hostname = Socket::getaddrinfo(self.ip_address, nil)[0][2]
    hostname = hostname == self.ip_address ? nil : (" (" + hostname + ") ")
    self.content += " [IP Address changed to #{self.ip_address}#{hostname}]" if (!previous_report_items.empty? and previous_report_items.last.ip_address != self.ip_address)
  end
end
{'fraction_non_alphanumeric': 0.0901932712956335, 'fraction_numerical': 0.0014316392269148174, 'mean_word_length': 4.825, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, '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': '5184110', 'n_tokens_mistral': 445, 'n_tokens_neox': 450, 'n_words': 102}