<commit_before>module Qti

class RespondusSettings

  attr_reader :doc

  def initialize(doc)
    @doc = doc
  end

  def apply(assessment)
    return unless read_setting('hasSettings') == 'true'
    apply_if_set(assessment, :description, 'instructions')
    apply_if_set(assessment, :allowed_attempts, 'attempts') { |v| v == 'unlimited' ? -1 : v.to_i }
    apply_if_set(assessment, :time_limit, 'timeLimit') { |v| v == 'unlimited' ? nil : v.to_f }
    apply_if_set(assessment, :unlock_at, 'availableFrom') { |v| readtime(v) }
    apply_if_set(assessment, :lock_at, 'availableTo') { |v| readtime(v) }
    apply_if_set(assessment, :access_code, 'password')
    apply_if_set(assessment, :ip_filter, 'ipRestriction')
    apply_if_set(assessment, :shuffle_answers, 'shuffleAnswers') { |v| v == 'true' }
    apply_if_set(assessment, :due_at, 'dueDate') { |v| readtime(v) }

    feedback = (read_setting('feedbackOptions') || "").split(",")
    if feedback.include?('showResults') || feedback.include?('all')
      if feedback.include?('lastAttemptOnly')
         assessment[:hide_results] = 'until_after_last_attempt'
      else
        assessment[:hide_results] = 'never'
      end
    elsif feedback.include?('none')
      assessment[:hide_results] = 'always'
    end

    apply_if_set(assessment, :scoring_policy, 'attemptGrading') do |v|
      case v
      when 'last'
        'keep_latest'
      when 'highest'
        'keep_highest'
      else<commit_msg>don't treat 'unlimited' placeholder value as an ip filter, refs #4238<commit_after>module Qti

class RespondusSettings

  attr_reader :doc

  def initialize(doc)
    @doc = doc
  end

  def apply(assessment)
    return unless read_setting('hasSettings') == 'true'
    apply_if_set(assessment, :description, 'instructions')
    apply_if_set(assessment, :allowed_attempts, 'attempts') { |v| v == 'unlimited' ? -1 : v.to_i }
    apply_if_set(assessment, :time_limit, 'timeLimit') { |v| v == 'unlimited' ? nil : v.to_f }
    apply_if_set(assessment, :unlock_at, 'availableFrom') { |v| readtime(v) }
    apply_if_set(assessment, :lock_at, 'availableTo') { |v| readtime(v) }
    apply_if_set(assessment, :access_code, 'password')
    apply_if_set(assessment, :ip_filter, 'ipRestriction') { |v| v == 'unlimited' ? nil : v }
    apply_if_set(assessment, :shuffle_answers, 'shuffleAnswers') { |v| v == 'true' }
    apply_if_set(assessment, :due_at, 'dueDate') { |v| readtime(v) }

    feedback = (read_setting('feedbackOptions') || "").split(",")
    if feedback.include?('showResults') || feedback.include?('all')
      if feedback.include?('lastAttemptOnly')
         assessment[:hide_results] = 'until_after_last_attempt'
      else
        assessment[:hide_results] = 'never'
      end
    elsif feedback.include?('none')
      assessment[:hide_results] = 'always'
    end

    apply_if_set(assessment, :scoring_policy, 'attemptGrading') do |v|
      case v
      when 'last'
        'keep_latest'
      when 'highest'
        'keep_highest'
      else
{'fraction_non_alphanumeric': 0.14352314352314352, 'fraction_numerical': 0.001998001998001998, 'mean_word_length': 4.015025041736227, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3872645', 'n_tokens_mistral': 1065, 'n_tokens_neox': 1031, 'n_words': 206}