<commit_before>class InstrumentVersion
  attr_accessor :instrument, :version

  def method_missing(method, *args, &block)
    if Instrument.method_defined?(method) 
      if @version
        @version.reify.send(method, *args, &block)
      else
        @instrument.send(method, *args, &block)
      end
    else
      super
    end
  end

  def self.build(params = {})
    instrument = Instrument.find(params[:instrument_id])
    version_number = params[:version_number].to_i
    instrument_version = InstrumentVersion.new
    instrument_version.instrument = instrument
    if instrument.current_version_number > version_number
      instrument_version.version = Rails.cache.fetch("instrument_versions-#{version_number}", :expires_in => 1.hour) do
        instrument.versions[version_number]
      end
    end
    instrument_version
  end
  
  def questions
    return @instrument.questions unless @version
    return @questions if @questions
    questions = []
    @version.reify.questions.with_deleted.each do |question|<commit_msg>Add instrument id to cache key<commit_after>class InstrumentVersion
  attr_accessor :instrument, :version

  def method_missing(method, *args, &block)
    if Instrument.method_defined?(method) 
      if @version
        @version.reify.send(method, *args, &block)
      else
        @instrument.send(method, *args, &block)
      end
    else
      super
    end
  end

  def self.build(params = {})
    instrument = Instrument.find(params[:instrument_id])
    version_number = params[:version_number].to_i
    instrument_version = InstrumentVersion.new
    instrument_version.instrument = instrument
    if instrument.current_version_number > version_number
      instrument_version.version = Rails.cache.fetch("instrument_versions-#{instrument.id}-#{version_number}", :expires_in => 1.hour) do
        instrument.versions[version_number]
      end
    end
    instrument_version
  end
  
  def questions
    return @instrument.questions unless @version
    return @questions if @questions
    questions = []
    @version.reify.questions.with_deleted.each do |question|
{'fraction_non_alphanumeric': 0.09086584205518554, 'fraction_numerical': 0.0009514747859181732, 'mean_word_length': 3.551948051948052, 'pattern_counts': {'":': 0, '<': 3, '<?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': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2247075', 'n_tokens_mistral': 614, 'n_tokens_neox': 607, 'n_words': 128}