<commit_before>class PracticeQuestion < Quill::ActivityModel
  attributes :rule_position

  def rule_position_text= string
    array = string.flatten if string.is_a? Array

    array ||= JSON.parse(string).map do |item|
      if item.respond_to?(:strip)
        item.strip
      else
        item
      end
    end

    self.rule_position = array
  end

  def rule_position_text
    rule_position.to_json
  end

  def practice_rules
    ids = if rule_position.first.is_a?(Array)
      rule_position.map(&:first)
    else
      rule_position
    end

    ids.map{ |id| Rule.find(id) }
  end

  def question_quantity_for_rule rule
    rule_position.each do |pair|
      id, count = pair
      return (count.presence.try(:to_i) || 3) if id.to_i == rule.id
    end

    raise "couldn't find rule id #{rule.id} for question set #{id}"
  end
end<commit_msg>show id<commit_after>class PracticeQuestion < Quill::ActivityModel
  attributes :rule_position

  def rule_position_text= string
    array = string.flatten if string.is_a? Array

    array ||= JSON.parse(string).map do |item|
      if item.respond_to?(:strip)
        item.strip
      else
        item
      end
    end

    self.rule_position = array
  end

  def rule_position_text
    rule_position.to_json
  end


  def practice_rules
    if rule_position.nil?
      raise id.inspect
    end

    ids = if rule_position.first.is_a?(Array)
      rule_position.map(&:first)
    else
      rule_position
    end

    ids.map{ |id| Rule.find(id) }
  end

  def question_quantity_for_rule rule
    rule_position.each do |pair|
      id, count = pair
      return (count.presence.try(:to_i) || 3) if id.to_i == rule.id
    end

    raise "couldn't find rule id #{rule.id} for question set #{id}"
  end
end
{'fraction_non_alphanumeric': 0.08945868945868946, 'fraction_numerical': 0.0011396011396011395, 'mean_word_length': 2.6057494866529773, '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': '3079966', 'n_tokens_mistral': 599, 'n_tokens_neox': 576, 'n_words': 149}