fix copying calculated questions that are missing formulas

test plan:
 - import a blackboard quiz containing formula questions
   (a suitable one is attached to CNVS-3468)
 - take the quiz and ensure it is graded properly
 - using Settings / Copy This Course, copy the imported Canvas
   course to a new Canvas course
 - take the quiz in the new course and ensure it is graded
   properly

fixes #CNVS-3468

Change-Id: Iedfbc4e9a2440a5f88208a10150195050ddfd3c6
Reviewed-on: https://gerrit.instructure.com/17416
Reviewed-by: Mark Severson <markse@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Adam Phillipps <adam@instructure.com>
This commit is contained in:
Jeremy Stanley 2013-02-04 11:17:20 -07:00
parent 0ad53f659c
commit 76b4da53bf
4 changed files with 74 additions and 3 deletions

View File

@ -347,7 +347,7 @@ class AssessmentQuestion < ActiveRecord::Base
end
elsif question[:question_type] == "calculated_question"
question[:formulas] = []
qdata[:formulas].sort_by(&:first).each do |key, formula|
(qdata[:formulas] || []).sort_by(&:first).each do |key, formula|
question[:formulas] << {
:formula => check_length(formula[0..1024], 'formula', min_size)
}

View File

@ -9,7 +9,8 @@ class CalculatedInteraction < AssessmentItemConverter
end
def parse_question_data
@question[:imported_formula] = CGI.unescape(@doc.at_css('calculated formula').text)
imported_formula = @doc.at_css('calculated formula')
@question[:imported_formula] = CGI.unescape(imported_formula.text) if imported_formula
get_calculated_property('answer_tolerance')
@question[:answer_tolerance] = @question[:answer_tolerance].to_f if @question[:answer_tolerance]
get_calculated_property('unit_points_percent')

View File

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Warning: qmd_itemtype now replaced by qtiMetadata.interactionType in manifest
Converting proprietary canvas metadata field points_possible = 10
Converting proprietary canvas metadata field assessment_question_identifierref = ib784da0ea554753689c41d0d58121fe8
Warning: numeric fibtype does not match enclosing <response_str>, assuming string
Warning: min/max constraint on outcome will generate additional rules in responseProcessing
Warning: titles on respconditions no longer supported, ignored "correct"
Warning: replacing <other/> with the base value true - what did you want me to do??
Warning: titles on respconditions no longer supported, ignored "incorrect"
-->
<assessmentItem xmlns="http://www.imsglobal.org/xsd/imsqti_v2p1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.imsglobal.org/xsd/imsqti_v2p1 http://www.imsglobal.org/xsd/imsqti_v2p1.xsd" identifier="if0e253c3d288b8033db6673a656539df" title="Question" adaptive="false" timeDependent="false">
<instructureMetadata>
<instructureField name="assessment_question_identifierref" value="ib784da0ea554753689c41d0d58121fe8"/>
<instructureField name="points_possible" value="10"/>
<instructureField name="bb_question_type" value="Calculated"/>
<instructureField name="question_type" value="Calculated"/>
</instructureMetadata>
<responseDeclaration identifier="response1" cardinality="single" baseType="string"/>
<outcomeDeclaration identifier="SCORE" cardinality="single" baseType="float"/>
<itemBody>
<div class="html">&lt;div&gt;Ingrid has a credit card balance of $2200 on a card that charges 22 percent interest compounded monthly. Her bill says that her minimum payment is $155.00 What is her APY? Round your answer to the nearest hundreth of a percent.&lt;/div&gt;</div>
<extendedTextInteraction responseIdentifier="response1"/>
</itemBody>
<responseProcessing>
<responseCondition>
<responseIf><baseValue baseType="boolean">true</baseValue>
<setOutcomeValue identifier="SCORE"><baseValue baseType="float">100</baseValue></setOutcomeValue>
</responseIf>
<responseElseIf><not><baseValue baseType="boolean">true</baseValue></not>
<setOutcomeValue identifier="SCORE"><baseValue baseType="float">0</baseValue></setOutcomeValue>
</responseElseIf>
</responseCondition>
<responseCondition>
<responseIf><gt><variable identifier="SCORE"/><baseValue baseType="float">100.0</baseValue></gt>
<setOutcomeValue identifier="SCORE"><baseValue baseType="float">100.0</baseValue></setOutcomeValue>
</responseIf>
</responseCondition>
</responseProcessing>
<itemproc_extension>
<calculated>
<answer_tolerance type="None">0</answer_tolerance>
<vars>
</vars>
<var_sets><var_set ident="4082">
<answer>24.36</answer>
</var_set>
</var_sets>
</calculated>
</itemproc_extension>
</assessmentItem>

View File

@ -70,6 +70,13 @@ describe "Converting Canvas QTI" do
hash[:answers].each { |a| a.delete(:id) }
hash.should == CanvasExpected::CALCULATED_SIMPLE
end
it "should convert calculated questions missing formulas (e.g., imported from blackboard)" do
manifest_node=get_manifest_node('calculated_without_formula', :question_type=>'calculated_question', :interaction_type => 'extendedTextInteraction')
hash = Qti::AssessmentItemConverter.create_instructure_question(:manifest_node=>manifest_node, :base_dir=>CANVAS_FIXTURE_DIR)
hash[:answers].each { |a| a.delete(:id) }
hash.should == CanvasExpected::CALCULATED_WITHOUT_FORMULA
end
it "should convert calculated questions (complex)" do
manifest_node=get_manifest_node('calculated', :question_type=>'calculated_question', :interaction_type => 'extendedTextInteraction')
@ -323,7 +330,19 @@ module CanvasExpected
:incorrect_comments=>"",
:formulas=>[{:formula=>"1 + x"}],
:question_name=>"Formula question"}
CALCULATED_WITHOUT_FORMULA = {:variables => [],
:incorrect_comments => "",
:correct_comments => "",
:assessment_question_migration_id => "ib784da0ea554753689c41d0d58121fe8",
:question_text => "<div>Ingrid has a credit card balance of $2200 on a card that charges 22 percent interest compounded monthly. Her bill says that her minimum payment is $155.00 What is her APY? Round your answer to the nearest hundreth of a percent.</div>",
:question_name => "Question",
:answer_tolerance => 0,
:answers => [{:variables => [], :weight => 100, :answer => 24.36}],
:formulas => [],
:migration_id => "if0e253c3d288b8033db6673a656539df",
:question_type => "calculated_question",
:points_possible => 10}
CALCULATED_COMPLEX = {:migration_id=>"i0ee13510954fd805d707623ee2c46729",
:question_type=>"calculated_question",