<commit_before>class ProductDatasheet < ActiveRecord::Base
  require 'spreadsheet'
  
  has_attached_file :xls, :path => ":rails_root/uploads/product_datasheets/:id/:basename.:extension"  
  
  validates_attachment_presence :xls
  validates_attachment_content_type :xls, :content_type => ['application/vnd.ms-excel','text/plain']
  
  scope :not_deleted, where("product_datasheets.deleted_at is NULL")
  scope :deleted, where("product_datasheets.deleted_at is NOT NULL")
  
  def path
    "#{Rails.root}/uploads/product_datasheets/#{self.id}/#{self.xls_file_name}"
  end
  
  def perform
    workbook = Spreadsheet.open self.path
    worksheet = workbook.worksheet(0)
    columns = [worksheet.dimensions[2], worksheet.dimensions[3]]
    headers = worksheet.row(0)
    @records_matched = 0
    @records_updated = 0
    @records_failed = 0
    @failed_queries = 0
    
    worksheet.each do |row|
      attr_hash = {}
      for i in columns[0]..columns[1]
        attr_hash[headers[i]] = row[i] unless row[i].nil?
      end
      if Product.column_names.include?(headers[0])<commit_msg>fix failed_queries count<commit_after>class ProductDatasheet < ActiveRecord::Base
  require 'spreadsheet'
  
  has_attached_file :xls, :path => ":rails_root/uploads/product_datasheets/:id/:basename.:extension"  
  
  validates_attachment_presence :xls
  validates_attachment_content_type :xls, :content_type => ['application/vnd.ms-excel','text/plain']
  
  scope :not_deleted, where("product_datasheets.deleted_at is NULL")
  scope :deleted, where("product_datasheets.deleted_at is NOT NULL")
  
  def path
    "#{Rails.root}/uploads/product_datasheets/#{self.id}/#{self.xls_file_name}"
  end
  
  def perform
    workbook = Spreadsheet.open self.path
    worksheet = workbook.worksheet(0)
    columns = [worksheet.dimensions[2], worksheet.dimensions[3]]
    headers = worksheet.row(0)
    @records_matched = 0
    @records_updated = 0
    @records_failed = 0
    @failed_queries = 0
    
    worksheet.each(1) do |row|
      attr_hash = {}
      for i in columns[0]..columns[1]
        attr_hash[headers[i]] = row[i] unless row[i].nil?
      end
      if Product.column_names.include?(headers[0])
{'fraction_non_alphanumeric': 0.12190650779101742, 'fraction_numerical': 0.010540788267644362, 'mean_word_length': 3.927765237020316, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 7, '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': '3198302', 'n_tokens_mistral': 767, 'n_tokens_neox': 748, 'n_words': 131}