qti options hash refactor

refs #55

Change-Id: I791f596eca1d236cef77282f8be3dcc24abd8a8b
Reviewed-on: https://gerrit.instructure.com/5088
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Brian Palmer <brianp@instructure.com>
This commit is contained in:
Bracken Mosbacker 2011-08-15 08:27:43 -06:00
parent ba585cf7d6
commit 97875c1dfb
15 changed files with 43 additions and 30 deletions

View File

@ -98,7 +98,7 @@ module CC::Importer
questions = {}
begin
manifest_file = File.join(@dest_dir_2_1, Qti::QtiExporter::MANIFEST_FILE)
questions[:assessment_questions] = Qti.convert_questions(manifest_file)
questions[:assessment_questions] = Qti.convert_questions(manifest_file, :flavor => Qti::Flavors::CANVAS)
rescue
questions[:qti_error] = "#{$!}: #{$!.backtrace.join("\n")}"
end
@ -110,7 +110,7 @@ module CC::Importer
quizzes = {}
begin
manifest_file = File.join(@dest_dir_2_1, Qti::QtiExporter::MANIFEST_FILE)
quizzes[:assessments] = Qti.convert_assessments(manifest_file, false)
quizzes[:assessments] = Qti.convert_assessments(manifest_file, :flavor => Qti::Flavors::CANVAS)
rescue
quizzes[:qti_error] = "#{$!}: #{$!.backtrace.join("\n")}"
end

View File

@ -4,6 +4,7 @@ module Qti
end
require 'canvas_migration'
require 'qti_exporter/flavors'
require 'qti_exporter/qti'
require 'qti_exporter/qti_plugin_validator'
require 'qti_exporter/qti_exporter'

View File

@ -14,7 +14,9 @@ class AssessmentItemConverter
@manifest_node = opts[:manifest_node]
@migration_type = opts[:interaction_type]
@doc = nil
@flavor = opts[:flavor]
@opts = opts
if @manifest_node
@base_dir = opts[:base_dir]
@identifier = @manifest_node['identifier']

View File

@ -5,14 +5,14 @@ class AssessmentTestConverter
attr_reader :base_dir, :identifier, :href, :interaction_type, :title, :quiz
def initialize(manifest_node, base_dir, is_webct=false, converted_questions = [])
def initialize(manifest_node, base_dir, opts={})
@log = Canvas::Migration::logger
@manifest_node = manifest_node
@base_dir = base_dir
@href = File.join(@base_dir, @manifest_node['href'])
@is_webct = is_webct
@converted_questions = converted_questions
@converted_questions = opts[:converted_questions]
@opts = opts
@quiz = {
:questions=>[],
:quiz_type=>nil,
@ -20,7 +20,7 @@ class AssessmentTestConverter
}
end
def create_instructure_quiz(converted_questions = [])
def create_instructure_quiz
begin
# Get manifest data
if md = @manifest_node.at_css("instructureMetadata")
@ -188,7 +188,7 @@ class AssessmentTestConverter
def convert_weight_to_points(weight)
begin
weight = weight.to_f
if @is_webct
if @opts[:flavor] == Qti::Flavors::WEBCT
weight = weight * 100
end
rescue

View File

@ -7,7 +7,7 @@ class AssociateInteraction < AssessmentItemConverter
@question[:matches] = []
@question[:question_type] = 'matching_question'
# to mark whether it's bb8/vista/respondus_matching if needed
@flavor = opts[:custom_type]
@custom_type = opts[:custom_type]
end
def parse_question_data
@ -18,10 +18,10 @@ class AssociateInteraction < AssessmentItemConverter
check_for_meta_matches
elsif node = @doc.at_css('matchInteraction')
get_all_match_interaction(node)
elsif @flavor == 'respondus_matching'
elsif @custom_type == 'respondus_matching'
get_respondus_answers
get_respondus_matches
elsif @flavor == 'canvas_matching'
elsif @custom_type == 'canvas_matching'
match_map = {}
get_canvas_matches(match_map)
get_canvas_answers(match_map)

View File

@ -0,0 +1,10 @@
module Qti
module Flavors
ANGEL = 'angel'
BBLEARN = 'bblearn'
CANVAS = 'canvas'
D2L = 'd2l'
RESPONDUS = 'respondus'
WEBCT = 'webct'
end
end

View File

@ -20,27 +20,27 @@ module Qti
file_name
end
def self.convert_questions(manifest_path)
def self.convert_questions(manifest_path, opts={})
questions = []
doc = Nokogiri::XML(open(manifest_path))
doc.css('manifest resources resource[type^=imsqti_item_xmlv2p]').each do |item|
q = AssessmentItemConverter::create_instructure_question(:manifest_node=>item, :base_dir=>File.dirname(manifest_path))
q = AssessmentItemConverter::create_instructure_question(opts.merge(:manifest_node=>item, :base_dir=>File.dirname(manifest_path)))
questions << q if q
end
questions
end
def self.convert_assessments(manifest_path, is_webct=false, questions = [])
def self.convert_assessments(manifest_path, opts={})
assessments = []
doc = Nokogiri::XML(open(manifest_path))
doc.css('manifest resources resource[type=imsqti_assessment_xmlv2p1]').each do |item|
a = AssessmentTestConverter.new(item, File.dirname(manifest_path), is_webct, questions).create_instructure_quiz
a = AssessmentTestConverter.new(item, File.dirname(manifest_path), opts).create_instructure_quiz
assessments << a if a
end
assessments
end
def self.convert_xml(xml)
def self.convert_xml(xml, opts={})
assessments = nil
questions = nil
Dir.mktmpdir do |dirname|
@ -54,7 +54,7 @@ module Qti
if $?.exitstatus == 0
manifest = File.join(dest_dir_2_1, "imsmanifest.xml")
questions = convert_questions(manifest)
questions = convert_questions(manifest, opts)
assessments = convert_assessments(manifest)
else
raise "Error running python qti converter"

View File

@ -32,7 +32,7 @@ class QtiExporter < Canvas::Migrator
end
@course[:assessment_questions] = convert_questions
@course[:assessments] = convert_assessments(@course[:assessment_questions])
@course[:assessments] = convert_assessments(@course[:assessment_questions][:assessment_questions])
@course[:file_map] = convert_files
if settings[:apply_respondus_settings_file]
@ -107,7 +107,7 @@ class QtiExporter < Canvas::Migrator
raise "The QTI must be converted to 2.1 before converting to JSON" unless @converted
begin
manifest_file = File.join(@dest_dir_2_1, MANIFEST_FILE)
@quizzes[:assessments] = Qti.convert_assessments(manifest_file, false, questions[:assessment_questions])
@quizzes[:assessments] = Qti.convert_assessments(manifest_file, :questions => questions)
rescue => e
message = "Error processing assessment QTI data: #{$!}: #{$!.backtrace.join("\n")}"
add_error "qti_assessments", message, @questions, e

View File

@ -30,7 +30,7 @@ describe "Converting Angel CC QTI" do
it "should convert the assessment into a quiz" do
manifest_node=get_manifest_node('assessment', :quiz_type => 'Test')
a = Qti::AssessmentTestConverter.new(manifest_node, angel_question_dir, false)
a = Qti::AssessmentTestConverter.new(manifest_node, angel_question_dir)
a.create_instructure_quiz
a.quiz.should == AngelExpected::ASSESSMENT
end

View File

@ -104,7 +104,7 @@ describe "Converting Blackboard 8 qti" do
it "should convert the assessments into quizzes" do
manifest_node=get_manifest_node('assessment', :quiz_type => 'Test')
a = Qti::AssessmentTestConverter.new(manifest_node, bb8_question_dir, false)
a = Qti::AssessmentTestConverter.new(manifest_node, bb8_question_dir)
a.create_instructure_quiz
a.quiz.should == BB8Expected::ASSESSMENT
end

View File

@ -11,7 +11,7 @@ describe "Converting a cengage QTI" do
it "should point a group to a question bank" do
manifest_node=get_manifest_node('group_to_bank', :quiz_type => 'examination')
a = Qti::AssessmentTestConverter.new(manifest_node, cengage_question_dir, true)
a = Qti::AssessmentTestConverter.new(manifest_node, cengage_question_dir)
a.create_instructure_quiz
group = a.quiz[:questions].first
group[:pick_count].should == 20

View File

@ -27,7 +27,7 @@ describe "Converting D2L QTI" do
it "should convert matching" do
#pp get_question_hash(d2l_question_dir, 'matching', false)
hash = get_question_hash(d2l_question_dir, 'matching', false)
hash = get_question_hash(d2l_question_dir, 'matching', false, :flavor => 'd2l')
matches = {}
hash[:matches].each {|m| matches[m[:match_id]] = m[:text]}
hash[:answers].each do |a|

View File

@ -82,7 +82,7 @@ describe "Converting respondus QTI" do
it "should convert the assessment into a quiz" do
manifest_node=get_manifest_node('assessment', :quiz_type => 'Test')
a = Qti::AssessmentTestConverter.new(manifest_node, respondus_question_dir, false)
a = Qti::AssessmentTestConverter.new(manifest_node, respondus_question_dir)
a.create_instructure_quiz
a.quiz.should == RespondusExpected::ASSESSMENT
end

View File

@ -73,7 +73,7 @@ describe "Converting Blackboard Vista qti" do
it "should convert the assessments into quizzes" do
manifest_node=get_manifest_node('assessment', :quiz_type => 'examination')
a = Qti::AssessmentTestConverter.new(manifest_node, vista_question_dir, true)
a = Qti::AssessmentTestConverter.new(manifest_node, vista_question_dir, :flavor=>Qti::Flavors::WEBCT)
a.create_instructure_quiz
a.quiz.should == VistaExpected::ASSESSMENT
end

View File

@ -14,15 +14,15 @@ end
require 'qti_exporter'
require 'pp'
def get_question_hash(dir, name, delete_answer_ids=true)
hash = get_quiz_data(dir, name).first.first
def get_question_hash(dir, name, delete_answer_ids=true, opts={})
hash = get_quiz_data(dir, name, opts).first.first
hash[:answers].each {|a|a.delete(:id)} if delete_answer_ids
hash
end
def get_quiz_data(dir, name)
def get_quiz_data(dir, name, opts={})
File.open(File.join(dir, '%s.xml' % name), 'r') do |file|
Qti.convert_xml(file.read)
Qti.convert_xml(file.read, opts)
end
end