canvas_qti_to_learnosity_converter 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '052911e6b4ed78bd22f6f6f99af67f56e5aa42bb84f327cfe9da5090900ff3f8'
4
- data.tar.gz: 8927eb57c5e1b4a75dd00b49775e9479573295c7b7ce1bb48565bf0763852ea7
3
+ metadata.gz: 2e102ffcbd4d59f3fb3e466bdfada0f614ed1ae8438e2e63322454d1585203f7
4
+ data.tar.gz: 8f52c78fc0e604827e947095e4ca12ed2a1da248a2d97fa9ca18721da255e0c7
5
5
  SHA512:
6
- metadata.gz: 9e435bae6d96255228cd1ccc74b1b98e96208f5962b860db9629d07d3de668539065cc5795a13f09bff7ace2b6b84f938ae449b5d0268788a0cf17b1a4a08646
7
- data.tar.gz: ece35a13ae4485a6eb0518e472530426c121215720759058ebcda7ce0c2283ac9d94e72944dc392ee78987caaab85035d8b5f8173a10ee5453605ced1fda1e21
6
+ metadata.gz: 96621e2221a06448c6a351cee7f460ef5067c470cc84102b9b2e37bab8d8d6e77c9ee81ca006d7336cffb42ac4d1972b3a957eb2e31f8f7f8fd2b3125ffc8d70
7
+ data.tar.gz: e184a67f1c709ed6189bb2d7fe8aee3484d03a2f0a8ee25747fed902c3fbe78f62634f4f2aa878976624e70c5f97eef551e49dc7300981f4ba19a4b7b982ec69
@@ -13,6 +13,7 @@ require "canvas_qti_to_learnosity_converter/questions/essay"
13
13
  require "canvas_qti_to_learnosity_converter/questions/file_upload"
14
14
  require "canvas_qti_to_learnosity_converter/questions/text_only"
15
15
  require "canvas_qti_to_learnosity_converter/questions/numerical"
16
+ require "canvas_qti_to_learnosity_converter/questions/calculated"
16
17
 
17
18
  module CanvasQtiToLearnosityConverter
18
19
  FEATURE_TYPES = [ :text_only_question ]
@@ -28,6 +29,21 @@ module CanvasQtiToLearnosityConverter
28
29
  :file_upload_question,
29
30
  ]
30
31
 
32
+ TYPE_MAP = {
33
+ multiple_choice_question: MultipleChoiceQuestion,
34
+ true_false_question: MultipleChoiceQuestion,
35
+ multiple_answers_question: MultipleAnswersQuestion,
36
+ short_answer_question: ShortAnswerQuestion,
37
+ fill_in_multiple_blanks_question: FillTheBlanksQuestion,
38
+ multiple_dropdowns_question: MultipleDropdownsQuestion,
39
+ matching_question: MatchingQuestion,
40
+ essay_question: EssayQuestion,
41
+ file_upload_question: FileUploadQuestion,
42
+ text_only_question: TextOnlyQuestion,
43
+ numerical_question: NumericalQuestion,
44
+ calculated_question: CalculatedQuestion,
45
+ }
46
+
31
47
  class CanvasQuestionTypeNotSupportedError < RuntimeError
32
48
  end
33
49
 
@@ -85,29 +101,10 @@ module CanvasQtiToLearnosityConverter
85
101
  learnosity_type = "question"
86
102
  end
87
103
 
88
- question = case type
89
- when :multiple_choice_question
90
- MultipleChoiceQuestion.new(xml)
91
- when :true_false_question
92
- MultipleChoiceQuestion.new(xml)
93
- when :multiple_answers_question
94
- MultipleAnswersQuestion.new(xml)
95
- when :short_answer_question
96
- ShortAnswerQuestion.new(xml)
97
- when :fill_in_multiple_blanks_question
98
- FillTheBlanksQuestion.new(xml)
99
- when :multiple_dropdowns_question
100
- MultipleDropdownsQuestion.new(xml)
101
- when :matching_question
102
- MatchingQuestion.new(xml)
103
- when :essay_question
104
- EssayQuestion.new(xml)
105
- when :file_upload_question
106
- FileUploadQuestion.new(xml)
107
- when :text_only_question
108
- TextOnlyQuestion.new(xml)
109
- when :numerical_question
110
- NumericalQuestion.new(xml)
104
+ question_class = TYPE_MAP[type]
105
+
106
+ if question_class
107
+ question = question_class.new(xml)
111
108
  else
112
109
  raise CanvasQuestionTypeNotSupportedError
113
110
  end
@@ -131,7 +128,13 @@ module CanvasQtiToLearnosityConverter
131
128
  begin
132
129
  learnosity_type, quiz_item = convert_item(qti_string: item.to_html)
133
130
 
134
- items.push({type: learnosity_type, data: quiz_item.to_learnosity})
131
+ item = {
132
+ type: learnosity_type,
133
+ data: quiz_item.to_learnosity,
134
+ dynamic_content_data: quiz_item.dynamic_content_data()
135
+ }
136
+
137
+ items.push(item)
135
138
  path = [items.count - 1, :data]
136
139
 
137
140
  quiz_item.add_learnosity_assets(assets[ident], path)
@@ -0,0 +1,75 @@
1
+ require "canvas_qti_to_learnosity_converter/questions/template_question"
2
+
3
+ module CanvasQtiToLearnosityConverter
4
+ class CalculatedQuestion < TemplateQuestion
5
+ def to_learnosity
6
+ {
7
+ type: "clozeformula",
8
+ is_math: true,
9
+ stimulus: extract_stimulus(),
10
+ template: "{{response}}",
11
+ validation: extract_validation(),
12
+ }
13
+ end
14
+
15
+ def extract_stimulus()
16
+ template = get_template()
17
+ extract_template_values(template).each.with_index do |var_name, index|
18
+ template.sub!("[#{var_name}]", "{{var:val#{index}}}")
19
+ end
20
+
21
+ template
22
+ end
23
+
24
+ def extract_validation()
25
+ pm = @xml.css("item > itemproc_extension > calculated > answer_tolerance")
26
+ .first.text
27
+
28
+ {
29
+ "scoring_type" => "exactMatch",
30
+ "valid_response" => {
31
+ "value" => [[{
32
+ "method" => "equivValue",
33
+ "value" => "{{var:answer}}\\pm#{pm}"
34
+ }]]
35
+ }
36
+ }
37
+ end
38
+
39
+ def add_learnosity_assets(assets, path)
40
+ learnosity = to_learnosity
41
+ CanvasQtiToLearnosityConverter.add_files_to_assets(
42
+ assets,
43
+ path + [:stimulus],
44
+ learnosity[:stimulus]
45
+ )
46
+ end
47
+
48
+ def dynamic_content_data()
49
+ values = extract_dynamic_content_data()
50
+
51
+ columns = (0...(values.first.count - 1)).map{ |x| "val#{x}" }
52
+ columns.push("answer")
53
+
54
+ rows = Hash[values.map.with_index do |row, index|
55
+ [make_identifier(), { values: row, index: index }]
56
+ end]
57
+
58
+ { cols: columns, rows: rows }
59
+ end
60
+
61
+ def extract_dynamic_content_data()
62
+ template = get_template()
63
+ vars = extract_template_values(template).map do |var_name|
64
+ @xml.css(%{item > itemproc_extension > calculated > var_sets >
65
+ var_set > var[name="#{var_name}"]}).map { |node| node.text }
66
+ end
67
+
68
+ answers = @xml.css("item > itemproc_extension var_sets answer").map do |node|
69
+ node.text
70
+ end
71
+
72
+ vars.push(answers).transpose
73
+ end
74
+ end
75
+ end
@@ -24,7 +24,6 @@ module CanvasQtiToLearnosityConverter
24
24
  end
25
25
 
26
26
  answer_bounds = response_mins.zip(response_maxs).map do |bounds|
27
- puts bounds.inspect
28
27
  # Get the precision by counting the number of places after the decimal
29
28
  precision = [
30
29
  bounds.first.split(".").last.length,
@@ -1,3 +1,5 @@
1
+ require "securerandom"
2
+
1
3
  module CanvasQtiToLearnosityConverter
2
4
  class QuizQuestion
3
5
  extend Forwardable
@@ -15,5 +17,13 @@ module CanvasQtiToLearnosityConverter
15
17
  def extract_mattext(mattext_node)
16
18
  mattext_node.content
17
19
  end
20
+
21
+ def make_identifier()
22
+ SecureRandom.uuid
23
+ end
24
+
25
+ def dynamic_content_data()
26
+ {}
27
+ end
18
28
  end
19
29
  end
@@ -1,3 +1,3 @@
1
1
  module CanvasQtiToLearnosityConverter
2
- VERSION = "2.1.0"
2
+ VERSION = "2.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: canvas_qti_to_learnosity_converter
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Atomic Jolt
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-08-10 00:00:00.000000000 Z
12
+ date: 2018-08-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -115,6 +115,7 @@ files:
115
115
  - canvas_qti_to_learnosity_converter.gemspec
116
116
  - lib/canvas_qti_to_learnosity_converter.rb
117
117
  - lib/canvas_qti_to_learnosity_converter/convert.rb
118
+ - lib/canvas_qti_to_learnosity_converter/questions/calculated.rb
118
119
  - lib/canvas_qti_to_learnosity_converter/questions/essay.rb
119
120
  - lib/canvas_qti_to_learnosity_converter/questions/file_upload.rb
120
121
  - lib/canvas_qti_to_learnosity_converter/questions/fill_the_blanks.rb