<commit_before>module Qwester
  class AnswerStore < ActiveRecord::Base

    has_and_belongs_to_many(
      :answers,
      :join_table => :qwester_answer_stores_answers,
      :uniq => true
    )
    has_and_belongs_to_many(
      :questionnaires, 
      :join_table => :qwester_answer_stores_questionnaires,
      :uniq => true
    )

    before_save :generate_session_id
    
    def self.destroy_unpreserved
      where("updated_at < '#{1.day.ago.to_s(:db)}' AND preserved IS NULL").destroy_all
    end

    def reset
      answers.clear
      questionnaires.clear
    end

    def to_param
      session_id
    end
    
    def preserve
      make_copy({:preserved => Time.now}, :without_protection => true)
    end
    
    def restore
      make_copy if self.preserved?
    end

    private<commit_msg>Removes requirement for answer store to be preserved before it can be restored<commit_after>module Qwester
  class AnswerStore < ActiveRecord::Base

    has_and_belongs_to_many(
      :answers,
      :join_table => :qwester_answer_stores_answers,
      :uniq => true
    )
    has_and_belongs_to_many(
      :questionnaires, 
      :join_table => :qwester_answer_stores_questionnaires,
      :uniq => true
    )

    before_save :generate_session_id
    
    def self.destroy_unpreserved
      where("updated_at < '#{1.day.ago.to_s(:db)}' AND preserved IS NULL").destroy_all
    end

    def reset
      answers.clear
      questionnaires.clear
    end

    def to_param
      session_id
    end
    
    def preserve
      make_copy({:preserved => Time.now}, :without_protection => true)
    end
    
    def restore
      make_copy
    end

    private
{'fraction_non_alphanumeric': 0.07701564380264742, 'fraction_numerical': 0.0012033694344163659, 'mean_word_length': 2.5686695278969958, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, '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': '2628006', 'n_tokens_mistral': 556, 'n_tokens_neox': 539, 'n_words': 111}