Class: CanvasQtiToLearnosityConverter::MultipleChoiceQuestion
- Inherits:
-
QuizQuestion
- Object
- QuizQuestion
- CanvasQtiToLearnosityConverter::MultipleChoiceQuestion
show all
- Defined in:
- lib/canvas_qti_to_learnosity_converter/questions/multiple_choice.rb
Instance Method Summary
collapse
#convert, #dynamic_content_data, #extract_feedback, #extract_mattext, #extract_points_possible, #extract_stimulus, for, #initialize, #make_identifier, #process_assets!
Instance Method Details
#add_learnosity_assets(assets, path, learnosity) ⇒ Object
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
# File 'lib/canvas_qti_to_learnosity_converter/questions/multiple_choice.rb', line 94
def add_learnosity_assets(assets, path, learnosity)
process_assets!(
assets,
path,
learnosity[:stimulus]
)
learnosity[:options].each.with_index do |option, index|
process_assets!(
assets,
path,
option["label"]
)
end
learnosity
end
|
5
6
7
8
9
10
11
12
13
14
|
# File 'lib/canvas_qti_to_learnosity_converter/questions/multiple_choice.rb', line 5
def ()
choices = @xml.css("item > presentation > response_lid > render_choice > response_label")
choices.map do |choice|
ident = choice.attribute("ident").value
{
"value" => ident,
"label" => (choice.css("material > mattext").first),
}
end
end
|
16
17
18
|
# File 'lib/canvas_qti_to_learnosity_converter/questions/multiple_choice.rb', line 16
def ()
@xml.css("item > presentation > response_lid").attribute("ident").value
end
|
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/canvas_qti_to_learnosity_converter/questions/multiple_choice.rb', line 20
def ()
resp_conditions = @xml.css("item > resprocessing > respcondition")
scored_conditions = resp_conditions.filter_map do |condition|
setvar = condition.css("setvar").first
next unless setvar
score = setvar.text.to_f
next if score <= 0
answer_value = condition.css("varequal").text
next if answer_value.empty?
{
value: answer_value,
score: score
}
end.sort_by { |c| -c[:score] }
return nil if scored_conditions.empty?
best_answer = scored_conditions.first
points_possible =
scale_score = ->(score) { points_possible * (score / 100.0) }
if scored_conditions.length == 1
{
"scoring_type" => "exactMatch",
"valid_response" => {
"value" => [best_answer[:value]],
"score" => scale_score.call(best_answer[:score]),
},
}
else
validation = {
"scoring_type" => "partialMatch",
"valid_response" => {
"value" => [best_answer[:value]],
"score" => scale_score.call(best_answer[:score]),
},
}
alt_responses = scored_conditions[1..].map do |condition|
{
"value" => [condition[:value]],
"score" => scale_score.call(condition[:score]),
}
end
validation["alt_responses"] = alt_responses if alt_responses.any?
validation
end
end
|
#to_learnosity ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/canvas_qti_to_learnosity_converter/questions/multiple_choice.rb', line 81
def to_learnosity
shuffle = @xml.css("item > presentation > response_lid > render_choice").first&.attribute("shuffle")&.value
{
stimulus: (),
options: (),
multiple_responses: false,
shuffle_options: shuffle == "Yes",
response_id: (),
type: "mcq",
validation: (),
}
end
|