<commit_before>class Question < ActiveRecord::Base
  include Surveyor::Models::QuestionMethods

  attr_accessible :requirement, :required, :help_text_more_url, :text_as_statement, :display_on_certificate, :discussion_topic
  attr_accessor :minimum_level

  scope :excluding, lambda { |*objects| where(['questions.id NOT IN (?)', (objects.flatten.compact << 0)]) }

  before_save :cache_question_or_answer_corresponding_to_requirement
  before_save :set_default_value_for_required
  after_save :update_mandatory

  belongs_to :question_corresponding_to_requirement, :class_name => "Question"
  belongs_to :answer_corresponding_to_requirement, :class_name => "Answer"

  LEVELS = {
    'basic' => 1,
    'pilot' => 2,
    'standard' => 3,
    'exemplar' => 4
  }

  class << self
    def compute_levels(questions)
      questions.map.with_index do |question, i|
        requirements = []
        i += 1
        while questions[i] && questions[i].is_a_requirement? do
          requirements.push(questions[i])
          i += 1
        end
        question.minimum_level = get_minimum_level(requirements)
      end
    end

    def get_minimum_level(requirements)
      level = requirements.map(&:requirement_level).map{|l| LEVELS[l] }.min
      LEVELS.key(level) || (question.required? ? 'basic' : nil)
    end
  end

  # either provided text_as_statement, or fall back to text
  def statement_text
    text_as_statement || text
  end<commit_msg>Add question to get_minimum_level method<commit_after>class Question < ActiveRecord::Base
  include Surveyor::Models::QuestionMethods

  attr_accessible :requirement, :required, :help_text_more_url, :text_as_statement, :display_on_certificate, :discussion_topic
  attr_accessor :minimum_level

  scope :excluding, lambda { |*objects| where(['questions.id NOT IN (?)', (objects.flatten.compact << 0)]) }

  before_save :cache_question_or_answer_corresponding_to_requirement
  before_save :set_default_value_for_required
  after_save :update_mandatory

  belongs_to :question_corresponding_to_requirement, :class_name => "Question"
  belongs_to :answer_corresponding_to_requirement, :class_name => "Answer"

  LEVELS = {
    'basic' => 1,
    'pilot' => 2,
    'standard' => 3,
    'exemplar' => 4
  }

  class << self
    def compute_levels(questions)
      questions.map.with_index do |question, i|
        requirements = []
        i += 1
        while questions[i] && questions[i].is_a_requirement? do
          requirements.push(questions[i])
          i += 1
        end
        question.minimum_level = get_minimum_level(question, requirements)
      end
    end

    def get_minimum_level(question, requirements)
      level = requirements.map(&:requirement_level).map{|l| LEVELS[l] }.min
      LEVELS.key(level) || (question.required? ? 'basic' : nil)
    end
  end

  # either provided text_as_statement, or fall back to text
  def statement_text
    text_as_statement || text
  end
{'fraction_non_alphanumeric': 0.10364814183429935, 'fraction_numerical': 0.00477326968973747, 'mean_word_length': 3.947723440134907, 'pattern_counts': {'":': 0, '<': 13, '<?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': '7111974', 'n_tokens_mistral': 984, 'n_tokens_neox': 914, 'n_words': 193}