<commit_before>class SignatureSheet < ActiveRecord::Base
  belongs_to :signable, polymorphic: true
  belongs_to :author, class_name: 'User', foreign_key: 'author_id'

  VALID_SIGNABLES = %w( Proposal SpendingProposal )

  has_many :signatures

  validates :author, presence: true
  validates :signable_type, inclusion: {in: VALID_SIGNABLES}
  validates :document_numbers, presence: true
  validates :signable, presence: true
  validate  :signable_found

  def name
    "#{signable_name} #{signable_id}"
  end

  def signable_name
    I18n.t("activerecord.models.#{signable_type.underscore}", count: 1)
  end

  def verify_signatures
    parsed_document_numbers.each do |document_number|
      signature = signatures.create(document_number: document_number)
      signature.verify
    end
    update(processed: true)
  end

  def parsed_document_numbers
    document_numbers.split(/\r\n|\n|[,]/).collect {|d| d.gsub(/\s+/, '') }
  end

  def signable_found
    errors.add(:signable_id, :not_found) if errors.messages[:signable].present?
  end
end<commit_msg>find or create signatures in case of a timeout<commit_after>class SignatureSheet < ActiveRecord::Base
  belongs_to :signable, polymorphic: true
  belongs_to :author, class_name: 'User', foreign_key: 'author_id'

  VALID_SIGNABLES = %w( Proposal SpendingProposal )

  has_many :signatures

  validates :author, presence: true
  validates :signable_type, inclusion: {in: VALID_SIGNABLES}
  validates :document_numbers, presence: true
  validates :signable, presence: true
  validate  :signable_found

  def name
    "#{signable_name} #{signable_id}"
  end

  def signable_name
    I18n.t("activerecord.models.#{signable_type.underscore}", count: 1)
  end

  def verify_signatures
    parsed_document_numbers.each do |document_number|
      signature = self.signatures.where(document_number: document_number).first_or_create
      signature.verify
    end
    update(processed: true)
  end

  def parsed_document_numbers
    document_numbers.split(/\r\n|\n|[,]/).collect {|d| d.gsub(/\s+/, '') }
  end

  def signable_found
    errors.add(:signable_id, :not_found) if errors.messages[:signable].present?
  end
end
{'fraction_non_alphanumeric': 0.10429164743885556, 'fraction_numerical': 0.0027688047992616522, 'mean_word_length': 4.573264781491003, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '5603042', 'n_tokens_mistral': 747, 'n_tokens_neox': 710, 'n_words': 159}