<commit_before># -*- encoding : utf-8 -*-
class Campaign < ActiveRecord::Base
	attr_accessible :description, :name, :records, :record_type_id
	has_and_belongs_to_many :records
	has_and_belongs_to_many :sp_container, class_name:"Record", join_table: :sp_records
	has_and_belongs_to_many :cn_container, class_name:"Record", join_table: :cn_records

	def to_csv
		CSV.generate do |csv|
			self.records.each do |record|
				record.attributes.each do |atrb|
					csv << atrb
				end
			end
		end
	end
	
	def bal_aligment <commit_msg>Editing not properly generated csv db backup<commit_after># -*- encoding : utf-8 -*-
class Campaign < ActiveRecord::Base
	attr_accessible :description, :name, :records, :record_type_id
	has_and_belongs_to_many :records
	has_and_belongs_to_many :sp_container, class_name:"Record", join_table: :sp_records
	has_and_belongs_to_many :cn_container, class_name:"Record", join_table: :cn_records

	def to_csv
		csv = CSV.generate( :quote_char => "\0") do |csv|
			array = ""
			
			records.first.attributes.each_key do |key|
				array << key + "," unless key =~ /properties/
			end

			records.first.attributes["properties"].each_key do |key|
				array << key + ","	
			end

			array = array[0..array.length-2].chomp
			
			csv << [array.strip]

			self.records.each do |record|
				array = ""
				record.attributes.each do |key, value|
					array << value.to_s + "," unless key =~ /properties/
				end
				record.attributes["properties"].each do |key,value|
					array << value.to_s + ","
				end

				array = array[0..array.length-2].chomp
			
				csv << [array]
			end
		end
		csv.gsub!(/\0/, '')
	end
	
	def bal_aligment 
{'fraction_non_alphanumeric': 0.1275820170109356, 'fraction_numerical': 0.004860267314702308, 'mean_word_length': 3.6657223796033995, 'pattern_counts': {'":': 0, '<': 19, '<?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': '1034245', 'n_tokens_mistral': 658, 'n_tokens_neox': 562, 'n_words': 129}