qti 2.25.0 → 2.25.2

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: 658160efbc5ba67a6ba35d425c885e76f9d8ece8f6fbe9673287a04bd11b2a3b
4
- data.tar.gz: 21bec86a59792ebf56fdbaf1f4833fa41c04fce92c65919824333851b550178a
3
+ metadata.gz: 062a48a89ca4ced5ac4c33976eaa79be84d9f9f883de111d0cf8643550c1dd62
4
+ data.tar.gz: d6ec810ebbc758d650c2c081cbb777c1fd073bb1fc176b1e7b80958884cafc54
5
5
  SHA512:
6
- metadata.gz: e5d3223e5aab2d4d7f1cb2d4f8af2792e3a4c8cc37c9b2ff58d385e388cd2a6d658eae6c6eba842585445d0072e521a01b0bfbd856956373e80ee0e44b56dcd5
7
- data.tar.gz: 2f25762910192f38a8c5da3183fc9d8fc7fd3f8109990ec00ee1646f3a111de959226f00e5c74d4b52f64e7da488df95e4d27b111fcd4d1c0265814317d09be0
6
+ metadata.gz: 6abd2fda6c86e08b215c2ff3b7b1c79fdb8b5170af23de03c7f537528f2d6297981c941bf9ed19d9ee38345b9b13794abb24f68b7ab246693da55be0da1c8b18
7
+ data.tar.gz: 4140785078c7f4412d6c94e7124706e694bb5e884dc811d40db7e9c5c916ed81e0da86741378a4773c71abd5f8794e7ea8373383fe8b6f0fca808f0921ae0ac8
@@ -31,22 +31,32 @@ module Qti
31
31
  end
32
32
 
33
33
  def shape_type
34
- @shape_type ||= response_label&.attributes&.[]('rarea')&.value
34
+ @shape_type ||= extract_shape_type(response_label)
35
35
  end
36
36
 
37
37
  def coordinates
38
- @coordinates ||= begin
39
- raw_coordinates_array = raw_coordinates.split(',')
40
- return [] unless (raw_coordinates_array.length % 2).zero?
38
+ @coordinates ||= parse_coordinates(raw_coordinates)
39
+ end
41
40
 
42
- raw_coordinates_array.each_slice(2).map do |point|
43
- { x: point[0].to_f, y: point[1].to_f }
44
- end
45
- end
41
+ def scoring_data_structs
42
+ @scoring_data_structs ||= parse_scoring_data
46
43
  end
47
44
 
48
45
  private
49
46
 
47
+ def parse_scoring_data
48
+ raw_scoring_data = answer_nodes&.map do |answer|
49
+ {
50
+ id: extract_identifier(answer),
51
+ type: extract_shape_type(answer),
52
+ coordinates: parse_coordinates(answer&.text || '')
53
+ }
54
+ end
55
+ raw_scoring_data.map do |values|
56
+ Models::ScoringData.new(values, rcardinality)
57
+ end
58
+ end
59
+
50
60
  def response_label
51
61
  @response_label ||= begin
52
62
  node = @node.dup
@@ -55,10 +65,35 @@ module Qti
55
65
  end
56
66
  end
57
67
 
68
+ def answer_nodes
69
+ @answer_nodes ||= begin
70
+ node = @node.dup
71
+ presentation = node.at_xpath('.//xmlns:presentation')
72
+ presentation.xpath('.//xmlns:response_label')
73
+ end
74
+ end
75
+
58
76
  def raw_coordinates
59
77
  @raw_coordinates ||= response_label&.text || ''
60
78
  end
61
79
 
80
+ def extract_shape_type(answer)
81
+ answer&.attributes&.[]('rarea')&.value
82
+ end
83
+
84
+ def extract_identifier(answer)
85
+ answer&.attributes&.[]('ident')&.value
86
+ end
87
+
88
+ def parse_coordinates(raw_coordinates)
89
+ raw_coordinates_array = raw_coordinates.split(',')
90
+ return [] unless (raw_coordinates_array.length % 2).zero?
91
+
92
+ raw_coordinates_array.each_slice(2).map do |point|
93
+ { x: point[0].to_f, y: point[1].to_f }
94
+ end
95
+ end
96
+
62
97
  def coordinate_hash(coordinate_node)
63
98
  %w[x y].map do |axis|
64
99
  [axis.to_sym, coordinate_node&.attributes&.[](axis)&.value&.to_f]
data/lib/qti/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Qti
2
- VERSION = '2.25.0'.freeze
2
+ VERSION = '2.25.2'.freeze
3
3
  end
data/lib/qti.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'logger'
1
2
  require 'action_view'
2
3
  require 'active_support/core_ext/array/access'
3
4
  require 'active_support/core_ext/string'
@@ -39,7 +39,7 @@
39
39
  <material>
40
40
  <matimage uri="$IMS-CC-FILEBASE$/Uploaded Media/someuuid"/>
41
41
  </material>
42
- <response_label ident="response1" rarea="square">0.372,0.1376,0.616,0.4256</response_label>
42
+ <response_label ident="response1" rarea="rectangle">0.372,0.1376,0.616,0.4256</response_label>
43
43
  </render_hotspot>
44
44
  </response_xy>
45
45
  </flow>
@@ -76,7 +76,7 @@
76
76
  <material>
77
77
  <matimage uri="$IMS-CC-FILEBASE$/Uploaded Media/someuuid"/>
78
78
  </material>
79
- <response_label ident="response1" rarea="square">0.372</response_label>
79
+ <response_label ident="response1" rarea="rectangle">0.372</response_label>
80
80
  </render_hotspot>
81
81
  </response_xy>
82
82
  </flow>
@@ -113,7 +113,46 @@
113
113
  <material>
114
114
  <matimage uri="$IMS-CC-FILEBASE$/Uploaded Media/someuuid"/>
115
115
  </material>
116
- <response_label ident="response1" rarea="square"></response_label>
116
+ <response_label ident="response1" rarea="rectangle"></response_label>
117
+ </render_hotspot>
118
+ </response_xy>
119
+ </flow>
120
+ </presentation>
121
+ </item>
122
+ <item ident="g515255148f5a3cae1832584071aa8529" title="hot-spot with multiple selections">
123
+ <itemmetadata>
124
+ <qtimetadata>
125
+ <qtimetadatafield>
126
+ <fieldlabel>question_type</fieldlabel>
127
+ <fieldentry>hot_spot_question</fieldentry>
128
+ </qtimetadatafield>
129
+ <qtimetadatafield>
130
+ <fieldlabel>points_possible</fieldlabel>
131
+ <fieldentry>1.0</fieldentry>
132
+ </qtimetadatafield>
133
+ <qtimetadatafield>
134
+ <fieldlabel>original_answer_ids</fieldlabel>
135
+ <fieldentry/>
136
+ </qtimetadatafield>
137
+ <qtimetadatafield>
138
+ <fieldlabel>assessment_question_identifierref</fieldlabel>
139
+ <fieldentry>gd6ff15355f3dd3f532816fa268230130</fieldentry>
140
+ </qtimetadatafield>
141
+ </qtimetadata>
142
+ </itemmetadata>
143
+ <presentation>
144
+ <flow>
145
+ <response_xy ident="response1" rcardinality="Multiple" rtiming="No">
146
+ <material>
147
+ <mattext texttype="text/html">&lt;p&gt;point something on the image&lt;/p&gt;</mattext>
148
+ </material>
149
+ <render_hotspot>
150
+ <material>
151
+ <matimage uri="$IMS-CC-FILEBASE$/Uploaded Media/someuuid"/>
152
+ </material>
153
+ <response_label ident="response1" rarea="rectangle">0.1,0.2,0.3,0.4</response_label>
154
+ <response_label ident="response2" rarea="ellipse">0.5,0.6,0.7,0.8</response_label>
155
+ <response_label ident="response3" rarea="bounded">0.9,0.1,0.2,0.3</response_label>
117
156
  </render_hotspot>
118
157
  </response_xy>
119
158
  </flow>
@@ -28,7 +28,7 @@ describe Qti::V1::Models::Interactions::HotSpotInteraction do
28
28
  describe '#shape_type' do
29
29
  let(:loaded_class) { described_class.new(assessment_item_refs.first, test_object) }
30
30
  it 'returns correct shape type' do
31
- expect(loaded_class.shape_type).to eq 'square'
31
+ expect(loaded_class.shape_type).to eq 'rectangle'
32
32
  end
33
33
  end
34
34
 
@@ -54,4 +54,35 @@ describe Qti::V1::Models::Interactions::HotSpotInteraction do
54
54
  end
55
55
  end
56
56
  end
57
+
58
+ describe '#scoring_data_structs' do
59
+ context 'with a single hotspot' do
60
+ let(:loaded_class) { described_class.new(assessment_item_refs.first, test_object) }
61
+
62
+ it 'returns scoring data with a single hotspot' do
63
+ scoring_data = loaded_class.scoring_data_structs
64
+ expect(scoring_data.size).to eq(1)
65
+ expect(scoring_data.first.values[:type]).to eq('rectangle')
66
+ expect(scoring_data.first.values[:coordinates]).to eq([{ x: 0.372, y: 0.1376 }, { x: 0.616, y: 0.4256 }])
67
+ end
68
+ end
69
+
70
+ context 'with multiple hotspots' do
71
+ let(:loaded_class) { described_class.new(assessment_item_refs[3], test_object) }
72
+
73
+ it 'returns scoring data with multiple hotspots' do
74
+ scoring_data = loaded_class.scoring_data_structs
75
+ expect(scoring_data.size).to eq(3)
76
+
77
+ expect(scoring_data[0].values[:type]).to eq('rectangle')
78
+ expect(scoring_data[0].values[:coordinates]).to eq([{ x: 0.1, y: 0.2 }, { x: 0.3, y: 0.4 }])
79
+
80
+ expect(scoring_data[1].values[:type]).to eq('ellipse')
81
+ expect(scoring_data[1].values[:coordinates]).to eq([{ x: 0.5, y: 0.6 }, { x: 0.7, y: 0.8 }])
82
+
83
+ expect(scoring_data[2].values[:type]).to eq('bounded')
84
+ expect(scoring_data[2].values[:coordinates]).to eq([{ x: 0.9, y: 0.1 }, { x: 0.2, y: 0.3 }])
85
+ end
86
+ end
87
+ end
57
88
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qti
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.25.0
4
+ version: 2.25.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrian Diaz
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2024-10-23 00:00:00.000000000 Z
15
+ date: 2025-01-28 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: actionview