Sha256: 55150aa9009507b6b70e3c4397078da2755f3fb755c9638f6a98d39082c377f7

Contents?: true

Size: 1.75 KB

Versions: 1

Compression:

Stored size: 1.75 KB

Contents

require "canvas_qti_to_learnosity_converter/questions/question"

module CanvasQtiToLearnosityConverter
  class NumericalQuestion < QuizQuestion
    def to_learnosity
      {
        is_math: true,
        type: "formulaV2",
        stimulus: extract_stimulus(),
        template: "{{response}}",
        validation: extract_validation(),
      }
    end

    def extract_validation()
      response_mins = @xml.css('item > resprocessing >
        respcondition[continue="No"] > conditionvar vargte').map do |node|
        node.content
      end

      response_maxs = @xml.css('item > resprocessing >
        respcondition[continue="No"] > conditionvar varlte').map do |node|
        node.content
      end

      answer_bounds = response_mins.zip(response_maxs).map do |bounds|
        # Get the precision by counting the number of places after the decimal
        precision = [
          bounds.first.split(".").last.length,
          bounds.last.split(".").last.length
        ].max

        {
          center: ((bounds.first.to_f + bounds.last.to_f) / 2.0).round(precision),
          pm: ((bounds.first.to_f - bounds.last.to_f) / 2.0).round(precision).abs,
        }
      end

      valid_answers = answer_bounds.map do |bounds|
        {
          "value" => [{
            "method" => "equivValue",
            "value" => "#{bounds[:center]}\\pm#{bounds[:pm]}",
            "score" => extract_points_possible,
          }]
        }
      end

      {
        "scoring_type" => "exactMatch",
        "valid_response" => valid_answers.shift,
        "alt_responses" => valid_answers,
      }
    end

    def add_learnosity_assets(assets, path, learnosity)
      process_assets!(
        assets,
        path,
        learnosity[:stimulus]
      )
      learnosity
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
canvas_qti_to_learnosity_converter-3.0.0 lib/canvas_qti_to_learnosity_converter/questions/numerical.rb