<commit_before>class Spree::ProductDatasheet < ActiveRecord::Base
  belongs_to :user
  
  attr_accessor :queries_failed, :records_failed, :records_matched, :records_updated, :touched_product_ids
  alias_method :products_touched, :touched_product_ids
  attr_accessible :xls_file_name, :xls, :deleted_at
  serialize :product_errors
  
  after_initialize do
    self.product_errors ||= []
  end
  
  before_save :update_statistics
  
  after_find :setup_statistics
  after_initialize :setup_statistics
  
  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', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.oasis.opendocument.spreadsheet', 'text/plain']
  
  scope :not_deleted, where("spree_product_datasheets.deleted_at is NULL")
  scope :deleted, where("spree_product_datasheets.deleted_at is NOT NULL")
  
  def path
    "#{Rails.root}/uploads/product_datasheets/#{self.id}/#{self.xls_file_name}"
  end
  
  ####################
  # Main logic of extension
  # Uses the spreadsheet to define the bounds for iteration (from first used column <inclusive> to first unused column <exclusive>)
  # Sets up statistic variables and separates the headers row from the rest of the spreadsheet
  # Iterates row-by-row to populate a hash of { :attribute => :value } pairs, uses this hash to create or update records accordingly
  ####################
  def perform
    workbook =
    begin
      SpreadsheetDocument.load(self.xls.path)
    rescue
      puts 'Failed to open xls attachment for processing'
      return false
    end
    columns_range = workbook.first_column..workbook.last_column
    header_row = workbook.row(workbook.first_row)
    
    headers = []
    
    header_row.each do |key|
      method = "#{key}="
<commit_msg>Opening the attachment from an absolute path<commit_after>class Spree::ProductDatasheet < ActiveRecord::Base
  belongs_to :user
  
  attr_accessor :queries_failed, :records_failed, :records_matched, :records_updated, :touched_product_ids
  alias_method :products_touched, :touched_product_ids
  attr_accessible :xls_file_name, :xls, :deleted_at
  serialize :product_errors
  
  after_initialize do
    self.product_errors ||= []
  end
  
  before_save :update_statistics
  
  after_find :setup_statistics
  after_initialize :setup_statistics
  
  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', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.oasis.opendocument.spreadsheet', 'text/plain']
  
  scope :not_deleted, where("spree_product_datasheets.deleted_at is NULL")
  scope :deleted, where("spree_product_datasheets.deleted_at is NOT NULL")
  
  def path
    "#{Rails.root}/uploads/product_datasheets/#{self.id}/#{self.xls_file_name}"
  end
  
  ####################
  # Main logic of extension
  # Uses the spreadsheet to define the bounds for iteration (from first used column <inclusive> to first unused column <exclusive>)
  # Sets up statistic variables and separates the headers row from the rest of the spreadsheet
  # Iterates row-by-row to populate a hash of { :attribute => :value } pairs, uses this hash to create or update records accordingly
  ####################
  def perform
    workbook =
    begin
      SpreadsheetDocument.load(self.xls.to_s)
    rescue
      puts 'Failed to open xls attachment for processing'
      return false
    end
    columns_range = workbook.first_column..workbook.last_column
    header_row = workbook.row(workbook.first_row)
    
    headers = []
    
    header_row.each do |key|
      method = "#{key}="

{'fraction_non_alphanumeric': 0.1051288594029089, 'fraction_numerical': 0.0, 'mean_word_length': 4.497896213183731, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '6703139', 'n_tokens_mistral': 1246, 'n_tokens_neox': 1213, 'n_words': 290}