qti 2.30.0 → 2.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a08fc96f6a77de2160651785437e8ae12448f4b727daddccd06128715c51e5a8
|
|
4
|
+
data.tar.gz: 8893790e36626b9f29c743d6f48c313b8c77f9294117686dadaec8c085755751
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: df3ce562a0617d78c4f34d12d4682743dfb06d409283d6e88a01fb46278d8f815a8820082717da308521c01ba836bf26a98ec7ab73973080ac17ec7fd8ebaa49
|
|
7
|
+
data.tar.gz: d3fe2fd6a969a72af91ebd5942a3d715075ed9439fefb157a2d791ac7923779fee38a980fdf1624cd3a83efb53cb092b86672c04f4a8b6628931908b217caaa9
|
|
@@ -76,9 +76,7 @@ module Qti
|
|
|
76
76
|
end
|
|
77
77
|
|
|
78
78
|
def answer_feedback
|
|
79
|
-
path = './/xmlns:respcondition
|
|
80
|
-
'xmlns:conditionvar/xmlns:varequal[@respident]/../../' \
|
|
81
|
-
'xmlns:displayfeedback/..'
|
|
79
|
+
path = './/xmlns:respcondition[xmlns:displayfeedback][.//xmlns:varequal[@respident]]'
|
|
82
80
|
answers = node.xpath(path).map do |entry|
|
|
83
81
|
answer_feedback_entry(entry)
|
|
84
82
|
end.compact
|
|
@@ -88,17 +86,30 @@ module Qti
|
|
|
88
86
|
private
|
|
89
87
|
|
|
90
88
|
def answer_feedback_entry(entry)
|
|
91
|
-
ve = entry.xpath('.//xmlns:varequal').first
|
|
89
|
+
ve = entry.xpath('.//xmlns:varequal[@respident]').first
|
|
90
|
+
return nil unless ve
|
|
92
91
|
refid = entry.xpath('./xmlns:displayfeedback[not (@linkrefid="correct_fb" or ' \
|
|
93
92
|
'@linkrefid="general_incorrect_fb" or @linkrefid="general_fb")]').first&.[](:linkrefid)
|
|
94
93
|
feedback = get_feedback(refid)
|
|
95
94
|
return nil unless feedback
|
|
96
|
-
{
|
|
95
|
+
answer = {
|
|
97
96
|
response_id: ve[:respident],
|
|
98
97
|
response_value: ve.text,
|
|
99
98
|
texttype: feedback&.[](:texttype),
|
|
100
99
|
feedback: feedback&.text
|
|
101
100
|
}
|
|
101
|
+
answer[:negated] = true if negated_condition?(ve)
|
|
102
|
+
answer
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# Matching is the one Canvas type whose comment is shown when the
|
|
106
|
+
# student did *not* pick that match, so its `varequal` sits inside a
|
|
107
|
+
# `not`. Report that, rather than making the consumer infer it from
|
|
108
|
+
# the question type -- third party QTI may emit either form for any
|
|
109
|
+
# type. Only set when true, so every other type keeps its old shape.
|
|
110
|
+
def negated_condition?(varequal)
|
|
111
|
+
varequal.ancestors.take_while { |a| a.name != 'respcondition' }
|
|
112
|
+
.count { |a| a.name == 'not' }.odd?
|
|
102
113
|
end
|
|
103
114
|
|
|
104
115
|
def get_feedback(ident)
|
data/lib/qti/version.rb
CHANGED
|
@@ -110,4 +110,266 @@ describe Qti::V1::Models::Interactions::BaseInteraction do
|
|
|
110
110
|
expect(Qti::V1::Models::Interactions::BaseInteraction.new_quizzes_fib?(assessment_item_refs.first)).to eq false
|
|
111
111
|
end
|
|
112
112
|
end
|
|
113
|
+
|
|
114
|
+
# The respcondition lookup in #answer_feedback is shared by every v1
|
|
115
|
+
# interaction, so relaxing it to reach matching's negated varequal has to
|
|
116
|
+
# leave the other types untouched. This fixture carries one question of each
|
|
117
|
+
# Canvas type, all of them fully commented.
|
|
118
|
+
context 'all_canvas_simple_1.2.xml' do
|
|
119
|
+
let(:file_path) { File.join('spec', 'fixtures', 'all_canvas_simple_1.2.xml') }
|
|
120
|
+
|
|
121
|
+
def answer_feedback_for(index)
|
|
122
|
+
described_class.new(assessment_item_refs[index], test_object).answer_feedback&.map do |fb|
|
|
123
|
+
[fb[:response_id], fb[:response_value], fb[:negated], fb[:feedback]]
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
it 'extracts multiple choice feedback per chosen answer' do
|
|
128
|
+
expect(answer_feedback_for(0)).to eq(
|
|
129
|
+
[
|
|
130
|
+
['response1', '2799', nil, '<p>Answer feedback for C, correct</p>'],
|
|
131
|
+
['response1', '9607', nil, '<p>Answer feedback for A, incorrect</p>'],
|
|
132
|
+
['response1', '599', nil, '<p>Answer feedback for B, incorrect</p>'],
|
|
133
|
+
['response1', '5711', nil, '<p>Answer feedback for D, incorrect</p>']
|
|
134
|
+
]
|
|
135
|
+
)
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
it 'extracts true/false feedback per chosen answer' do
|
|
139
|
+
expect(answer_feedback_for(1)).to eq(
|
|
140
|
+
[
|
|
141
|
+
['response1', '919', nil, '<p>Answer Feedback, True, Correct</p>'],
|
|
142
|
+
['response1', '2680', nil, '<p>Answer Feedback, False, Incorrect</p>']
|
|
143
|
+
]
|
|
144
|
+
)
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
it 'extracts short answer feedback per chosen answer' do
|
|
148
|
+
expect(answer_feedback_for(2)).to eq(
|
|
149
|
+
[
|
|
150
|
+
['response1', 'Blank', nil, '<p>Answer Feedback, Correct, Blank</p>'],
|
|
151
|
+
['response1', 'blank', nil, '<p>Answer Feedback, Correct, blank</p>']
|
|
152
|
+
]
|
|
153
|
+
)
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
it 'extracts fill in multiple blanks feedback per blank and chosen answer' do
|
|
157
|
+
expect(answer_feedback_for(3)).to eq(
|
|
158
|
+
[
|
|
159
|
+
['response_Multiple', '832', nil, '<p>Answer Feedback, correct, Multiple</p>'],
|
|
160
|
+
['response_Multiple', '2173', nil, '<p>Answer Feedback, correct, multiple</p>'],
|
|
161
|
+
['response_Blanks', '9226', nil, '<p>Answer Feedback, correct, Blanks</p>'],
|
|
162
|
+
['response_Blanks', '1700', nil, '<p>Answer Feedback, correct, blanks</p>']
|
|
163
|
+
]
|
|
164
|
+
)
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
it 'extracts multiple answers feedback per chosen answer' do
|
|
168
|
+
expect(answer_feedback_for(4)).to eq(
|
|
169
|
+
[
|
|
170
|
+
['response1', '4094', nil, '<p>Answer Feedback, correct, A</p>'],
|
|
171
|
+
['response1', '8128', nil, '<p>Answer Feedback, correct, B</p>'],
|
|
172
|
+
['response1', '1582', nil, '<p>Answer Feedback, correct, C</p>'],
|
|
173
|
+
['response1', '7498', nil, '<p>Answer Feedback, incorrect, D</p>'],
|
|
174
|
+
['response1', '141', nil, '<p>Answer Feedback, incorrect, E</p>'],
|
|
175
|
+
['response1', '3202', nil, '<p>Answer Feedback, incorrect, F</p>']
|
|
176
|
+
]
|
|
177
|
+
)
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
it 'extracts multiple dropdowns feedback per chosen answer' do
|
|
181
|
+
expect(answer_feedback_for(5)).to eq(
|
|
182
|
+
[
|
|
183
|
+
['response_C', '520', nil, '<p>Answer Feedback, correct, C</p>'],
|
|
184
|
+
['response_C', '9701', nil, '<p>Answer Feedback, incorrect, D</p>']
|
|
185
|
+
]
|
|
186
|
+
)
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
it 'extracts matching feedback per left hand item, marked as negated' do
|
|
190
|
+
expect(answer_feedback_for(6)).to eq(
|
|
191
|
+
[
|
|
192
|
+
['response_2030', '6823', true, '<p>Answer Feedback, A:1 Chosen</p>'],
|
|
193
|
+
['response_1293', '4469', true, '<p>Answer Feedback, B:2 Chosen</p>']
|
|
194
|
+
]
|
|
195
|
+
)
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
it 'returns nil for the types that carry no answer level feedback' do
|
|
199
|
+
expect(answer_feedback_for(8)).to be_nil
|
|
200
|
+
expect(answer_feedback_for(9)).to be_nil
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
# The flag is additive: an entry that is not negated keeps exactly the keys
|
|
204
|
+
# it had before matching was supported, so a consumer pinned to an older
|
|
205
|
+
# gem sees no change.
|
|
206
|
+
it 'only adds the negated key to the negated entries' do
|
|
207
|
+
keys_by_item = (0..7).map do |index|
|
|
208
|
+
entries = described_class.new(assessment_item_refs[index], test_object).answer_feedback || []
|
|
209
|
+
entries.map(&:keys).uniq
|
|
210
|
+
end
|
|
211
|
+
expect(keys_by_item).to eq(
|
|
212
|
+
[
|
|
213
|
+
[%i[response_id response_value texttype feedback]],
|
|
214
|
+
[%i[response_id response_value texttype feedback]],
|
|
215
|
+
[%i[response_id response_value texttype feedback]],
|
|
216
|
+
[%i[response_id response_value texttype feedback]],
|
|
217
|
+
[%i[response_id response_value texttype feedback]],
|
|
218
|
+
[%i[response_id response_value texttype feedback]],
|
|
219
|
+
[%i[response_id response_value texttype feedback negated]],
|
|
220
|
+
[%i[response_id response_value texttype feedback]]
|
|
221
|
+
]
|
|
222
|
+
)
|
|
223
|
+
end
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
# Question 4 has no question_type metadata and more than one response_lid, so
|
|
227
|
+
# it dispatches to MatchInteraction while actually being fill in multiple
|
|
228
|
+
# blanks -- and its feedback is on the chosen answer, not a wrong pairing.
|
|
229
|
+
# Deriving negated per entry rather than per question type is what keeps this
|
|
230
|
+
# one, and third party packages like it, correct.
|
|
231
|
+
context 'interaction_checks_1.2.xml' do
|
|
232
|
+
let(:file_path) { File.join('spec', 'fixtures', 'interaction_checks_1.2.xml') }
|
|
233
|
+
|
|
234
|
+
it 'does not mark a non-negated question as negated, whatever it dispatches to' do
|
|
235
|
+
item = assessment_item_refs[3]
|
|
236
|
+
expect(Qti::V1::Models::AssessmentItem.new(item).interaction_model)
|
|
237
|
+
.to be_a(Qti::V1::Models::Interactions::MatchInteraction)
|
|
238
|
+
expect(described_class.new(item, test_object).answer_feedback.map { |fb| fb[:negated] })
|
|
239
|
+
.to all(be_nil)
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
it 'still marks the genuine matching question as negated' do
|
|
243
|
+
expect(described_class.new(assessment_item_refs[6], test_object).answer_feedback.map { |fb| fb[:negated] })
|
|
244
|
+
.to all(be true)
|
|
245
|
+
end
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
# NumericInteraction overrides #answer_feedback entirely (it pairs answers by
|
|
249
|
+
# setvar SCORE, not by varequal), so it never reaches the negated flag. Its
|
|
250
|
+
# entries are keyed on response_index and carry no negated key at all, which
|
|
251
|
+
# reads the same as not negated.
|
|
252
|
+
context 'numeric_answer_feedback.xml' do
|
|
253
|
+
let(:file_path) { File.join(fixtures_path, 'numeric_answer_feedback.xml') }
|
|
254
|
+
|
|
255
|
+
it 'does not report negated for numeric, which pairs answers differently' do
|
|
256
|
+
entries = Qti::V1::Models::AssessmentItem.new(assessment_item_refs.first).answer_feedback
|
|
257
|
+
expect(entries.map(&:keys).uniq).to eq([%i[response_index texttype feedback]])
|
|
258
|
+
expect(entries.map { |fb| fb[:negated] }).to all(be_nil)
|
|
259
|
+
end
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
# Ordering emits one respcondition holding a varequal per position, with a
|
|
263
|
+
# single comment for the whole correct sequence. It has always been reported
|
|
264
|
+
# through the first varequal and no spec covered it, so the relaxed xpath
|
|
265
|
+
# could have changed it unnoticed.
|
|
266
|
+
context 'ordering.xml' do
|
|
267
|
+
let(:file_path) { File.join(fixtures_path, 'ordering.xml') }
|
|
268
|
+
|
|
269
|
+
it 'keeps reporting the comment on the correct sequence through its first position' do
|
|
270
|
+
expect(loaded_class.answer_feedback).to eq(
|
|
271
|
+
[{ response_id: 'OB01', response_value: 'A',
|
|
272
|
+
texttype: nil, feedback: 'Yes, the correct order.' }]
|
|
273
|
+
)
|
|
274
|
+
end
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
# Codifies the corpus wide check behind the xpath relaxation: matching is the
|
|
278
|
+
# only shape in the whole fixture corpus that yields a negated entry. Guards
|
|
279
|
+
# against a future xpath change quietly pulling in another type.
|
|
280
|
+
context 'the whole fixture corpus' do
|
|
281
|
+
it 'only ever reports negated entries for matching questions' do
|
|
282
|
+
negated = Dir.glob(File.join('spec', 'fixtures', '**', '*.xml')).sort.filter_map do |path|
|
|
283
|
+
assessment = begin
|
|
284
|
+
Qti::V1::Models::Assessment.from_path!(path)
|
|
285
|
+
rescue StandardError
|
|
286
|
+
next
|
|
287
|
+
end
|
|
288
|
+
items = assessment.assessment_items
|
|
289
|
+
next if items.nil?
|
|
290
|
+
|
|
291
|
+
found = items.each_with_index.select do |item, _index|
|
|
292
|
+
entries = begin
|
|
293
|
+
described_class.new(item, assessment).answer_feedback
|
|
294
|
+
rescue StandardError
|
|
295
|
+
nil
|
|
296
|
+
end
|
|
297
|
+
entries&.any? { |fb| fb[:negated] }
|
|
298
|
+
end
|
|
299
|
+
next if found.empty?
|
|
300
|
+
|
|
301
|
+
[path.sub("spec#{File::SEPARATOR}fixtures#{File::SEPARATOR}", ''), found.map(&:last)]
|
|
302
|
+
end
|
|
303
|
+
|
|
304
|
+
expect(negated.to_h).to eq(
|
|
305
|
+
'all_canvas_simple_1.2.xml' => [6],
|
|
306
|
+
'interaction_checks_1.2.xml' => [6],
|
|
307
|
+
"items_1.2#{File::SEPARATOR}matching_feedback.xml" => [0]
|
|
308
|
+
)
|
|
309
|
+
end
|
|
310
|
+
end
|
|
311
|
+
|
|
312
|
+
# Shapes the relaxed xpath newly reaches. None occur in a Canvas export, but
|
|
313
|
+
# third party QTI 1.2 imports through the same code path.
|
|
314
|
+
context 'unusual respcondition shapes' do
|
|
315
|
+
let(:assessment) { double(path: 'dummy/blah', package_root: 'dummy') }
|
|
316
|
+
|
|
317
|
+
def interaction_for(conditionvar)
|
|
318
|
+
item = <<~XML
|
|
319
|
+
<questestinterop xmlns="http://www.imsglobal.org/xsd/ims_qtiasiv1p2">
|
|
320
|
+
<item ident="i1" title="Question">
|
|
321
|
+
<resprocessing>
|
|
322
|
+
<respcondition>
|
|
323
|
+
<conditionvar>#{conditionvar}</conditionvar>
|
|
324
|
+
<displayfeedback feedbacktype="Response" linkrefid="99_fb"/>
|
|
325
|
+
</respcondition>
|
|
326
|
+
</resprocessing>
|
|
327
|
+
<itemfeedback ident="99_fb">
|
|
328
|
+
<flow_mat>
|
|
329
|
+
<material><mattext texttype="text/html"><p>Comment</p></mattext></material>
|
|
330
|
+
</flow_mat>
|
|
331
|
+
</itemfeedback>
|
|
332
|
+
</item>
|
|
333
|
+
</questestinterop>
|
|
334
|
+
XML
|
|
335
|
+
described_class.new(Nokogiri.XML(item, &:noblanks).at_xpath('//xmlns:item'), assessment)
|
|
336
|
+
end
|
|
337
|
+
|
|
338
|
+
# A compound condition is reported through its first answer only. That is
|
|
339
|
+
# pre-existing behaviour -- ordering questions comment a whole correct
|
|
340
|
+
# sequence this way -- so it is pinned here rather than changed, and the
|
|
341
|
+
# negated flag follows the same first varequal.
|
|
342
|
+
it 'reports a compound condition through its first answer' do
|
|
343
|
+
interaction = interaction_for(
|
|
344
|
+
'<and><varequal respident="response1">111</varequal>' \
|
|
345
|
+
'<not><varequal respident="response1">222</varequal></not></and>'
|
|
346
|
+
)
|
|
347
|
+
expect(interaction.answer_feedback).to eq(
|
|
348
|
+
[{ response_id: 'response1', response_value: '111',
|
|
349
|
+
texttype: 'text/html', feedback: '<p>Comment</p>' }]
|
|
350
|
+
)
|
|
351
|
+
end
|
|
352
|
+
|
|
353
|
+
it 'ignores a varequal without a respident when picking the answer' do
|
|
354
|
+
interaction = interaction_for(
|
|
355
|
+
'<or><varequal>raw</varequal><varequal respident="response1">111</varequal></or>'
|
|
356
|
+
)
|
|
357
|
+
expect(interaction.answer_feedback).to eq(
|
|
358
|
+
[{ response_id: 'response1', response_value: '111',
|
|
359
|
+
texttype: 'text/html', feedback: '<p>Comment</p>' }]
|
|
360
|
+
)
|
|
361
|
+
end
|
|
362
|
+
|
|
363
|
+
it 'treats a doubly negated condition as not negated' do
|
|
364
|
+
interaction = interaction_for(
|
|
365
|
+
'<not><not><varequal respident="response1">111</varequal></not></not>'
|
|
366
|
+
)
|
|
367
|
+
expect(interaction.answer_feedback.first).not_to have_key(:negated)
|
|
368
|
+
end
|
|
369
|
+
|
|
370
|
+
it 'marks a singly negated condition as negated' do
|
|
371
|
+
interaction = interaction_for('<not><varequal respident="response1">111</varequal></not>')
|
|
372
|
+
expect(interaction.answer_feedback.first[:negated]).to be true
|
|
373
|
+
end
|
|
374
|
+
end
|
|
113
375
|
end
|
|
@@ -96,5 +96,45 @@ describe Qti::V1::Models::Interactions::MatchInteraction do
|
|
|
96
96
|
it 'does not have any scoring algorithm' do
|
|
97
97
|
expect(subject.scoring_algorithm).to eq nil
|
|
98
98
|
end
|
|
99
|
+
|
|
100
|
+
describe '#answer_feedback' do
|
|
101
|
+
it 'returns one entry per commented left hand item, keyed on its response id' do
|
|
102
|
+
expect(subject.answer_feedback).to eq(
|
|
103
|
+
[
|
|
104
|
+
{ response_id: 'response_6831', response_value: '6753', negated: true,
|
|
105
|
+
texttype: 'text/html', feedback: '<p>A:1</p>' },
|
|
106
|
+
{ response_id: 'response_6259', response_value: '7138', negated: true,
|
|
107
|
+
texttype: 'text/html', feedback: '<p>B:2</p>' }
|
|
108
|
+
]
|
|
109
|
+
)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
it 'marks the entries as negated, since Classic shows them on a wrong pairing' do
|
|
113
|
+
expect(subject.answer_feedback.map { |fb| fb[:negated] }).to all(be true)
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
it 'keys every entry on a question that exists' do
|
|
117
|
+
expect(subject.answer_feedback.map { |fb| fb[:response_id] })
|
|
118
|
+
.to all(be_in(subject.questions.map { |q| q[:id] }))
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
it 'skips the left hand items without a comment' do
|
|
122
|
+
expect(subject.answer_feedback.map { |fb| fb[:response_id] })
|
|
123
|
+
.not_to include('response_743', 'response_1943')
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
it 'ignores the item level feedback' do
|
|
127
|
+
expect(subject.answer_feedback.map { |fb| fb[:feedback] })
|
|
128
|
+
.not_to include('<p>Neutral</p>', '<p>Correct</p>', '<p>Incorrect</p>')
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
context 'matching.xml without answer feedback' do
|
|
134
|
+
let(:file) { File.join(path, 'matching.xml') }
|
|
135
|
+
|
|
136
|
+
it 'returns nil' do
|
|
137
|
+
expect(subject.answer_feedback).to be_nil
|
|
138
|
+
end
|
|
99
139
|
end
|
|
100
140
|
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.
|
|
4
|
+
version: 2.31.0
|
|
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: 2026-09-
|
|
15
|
+
date: 2026-09-08 00:00:00.000000000 Z
|
|
16
16
|
dependencies:
|
|
17
17
|
- !ruby/object:Gem::Dependency
|
|
18
18
|
name: actionview
|