<commit_before>class User < ActiveRecord::Base
	validates_presence_of :company
	before_save :update_empty_fields

	def self.company_info
		company_info = []
		Rails.cache.read('users_info').map do |company, users|
			company_info << [company, users.count, users.max_by(&:updated_at).updated_at.localtime]
		end
		company_info.sort_by{ |name| name[0] }
	end

	def self.metadata(company)
		metadata = {}
		metadata[:common_os] = Rails.cache.read('users_info')[company].group_by(&:operating_system).max_by{ |c,u| u.count }[0]
		metadata[:common_browser] = Rails.cache.read('users_info')[company].group_by(&:browser).max_by{ |c,u| u.count }[0]
		metadata
	end

	def show_plugins
		return plugins.split('; ').inject([]) { |all_plugins, p| all_plugins << p.split(": ") } if plugins
		[]
	end

	def show_proxy
		case proxy
		when '0'
			'No proxy detected'
		when 'tor'
			'Client is behind Tor'
		when 'public'
			'Client is using a public proxy'
		else
			'ERROR'
		end
	end

	private

	def update_empty_fields
		self.operating_system = "N/A" if self.operating_system == ""
		self.browser = "N/A" if self.browser == ""
	end
end<commit_msg>Refactor update_empty_fields<commit_after>class User < ActiveRecord::Base
	validates_presence_of :company
	before_save :update_empty_fields

	def self.company_info
		company_info = []
		Rails.cache.read('users_info').map do |company, users|
			company_info << [company, users.count, users.max_by(&:updated_at).updated_at.localtime]
		end
		company_info.sort_by{ |name| name[0] }
	end

	def self.metadata(company)
		metadata = {}
		metadata[:common_os] = Rails.cache.read('users_info')[company].group_by(&:operating_system).max_by{ |c,u| u.count }[0]
		metadata[:common_browser] = Rails.cache.read('users_info')[company].group_by(&:browser).max_by{ |c,u| u.count }[0]
		metadata
	end

	def show_plugins
		return plugins.split('; ').inject([]) { |all_plugins, p| all_plugins << p.split(": ") } if plugins
		[]
	end

	def show_proxy
		case proxy
		when '0'
			'No proxy detected'
		when 'tor'
			'Client is behind Tor'
		when 'public'
			'Client is using a public proxy'
		else
			'ERROR'
		end
	end

	private

	def update_empty_fields
		self.attributes.each do |name, value|
			self.update_attributes(name => "N/A") if value == ""
		end
	end
end
{'fraction_non_alphanumeric': 0.14009661835748793, 'fraction_numerical': 0.003513394817742644, 'mean_word_length': 4.462829736211031, 'pattern_counts': {'":': 2, '<': 13, '<?xml version=': 0, '>': 4, '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': '871927', 'n_tokens_mistral': 894, 'n_tokens_neox': 819, 'n_words': 181}