Quiz Stats - Maintain ERB compatibility
This patch makes it so that if you want to get the new stats from the back-end, you'll have to explicitly pass a "legacy=false" parameter to the report generator routine. Old code will use the old output, new code will use the CanvasQuizStatistics gem for stats. Closes CNVS-13198 TEST PLAN ---- ---- - create a quiz with a bunch of questions and take it by multiple students - visit the ERB stats page at /courses/:course_id/quizzes/:quiz_id/statistics - verify that the page renders and looks just like how it was before the work on its ember counterpart - visit the ember stats page at /courses/:course_id/quizzes/fabulous_quizzes#:quiz_id/statistics - verify the ember page is still functional Change-Id: I0a9e8d69eacc64a8727f238fc0c2e2acd44c0451 Reviewed-on: https://gerrit.instructure.com/35167 Tested-by: Jenkins <jenkins@instructure.com> QA-Review: Caleb Guanzon <cguanzon@instructure.com> Reviewed-by: Derek DeVries <ddevries@instructure.com> Product-Review: Ahmad Amireh <ahmad@instructure.com>
This commit is contained in:
parent
ab6f85b024
commit
82b1e74f16
|
@ -26,4 +26,17 @@ class Quizzes::QuizQuestion::EssayQuestion < Quizzes::QuizQuestion::Base
|
|||
user_answer.answer_details[:text] = Sanitize.clean(user_answer.answer_text, config) || ""
|
||||
nil
|
||||
end
|
||||
|
||||
def stats(responses)
|
||||
stats = {:essay_responses => []}
|
||||
|
||||
responses.each do |response|
|
||||
stats[:essay_responses] << {
|
||||
:user_id => response[:user_id],
|
||||
:text => response[:text].to_s.strip
|
||||
}
|
||||
end
|
||||
|
||||
@question_data.merge stats
|
||||
end
|
||||
end
|
||||
|
|
|
@ -34,7 +34,7 @@ class Quizzes::QuizStatistics::ItemAnalysis < Quizzes::QuizStatistics::Report
|
|||
|
||||
MIN_STATS_FOR_ALPHA = 15
|
||||
|
||||
def generate
|
||||
def generate(legacy=true)
|
||||
stats = summary_stats_for_quiz
|
||||
stats.map do |item|
|
||||
question_item_analysis = {
|
||||
|
|
|
@ -45,7 +45,7 @@ class Quizzes::QuizStatistics::StudentAnalysis < Quizzes::QuizStatistics::Report
|
|||
# :submission_correct_count_average=>1,
|
||||
# :questions=>
|
||||
# [output of stats_for_question for every question in submission_data]
|
||||
def generate
|
||||
def generate(legacy=true)
|
||||
submissions = submissions_for_statistics
|
||||
# questions: questions from quiz#quiz_data
|
||||
#{1022=>
|
||||
|
@ -144,7 +144,7 @@ class Quizzes::QuizStatistics::StudentAnalysis < Quizzes::QuizStatistics::Report
|
|||
end
|
||||
end
|
||||
if obj[:answers] && obj[:question_type] != 'text_only_question'
|
||||
stat = stats_for_question(obj, responses_for_question[obj[:id]])
|
||||
stat = stats_for_question(obj, responses_for_question[obj[:id]], legacy)
|
||||
stats[:questions] << ['question', stat]
|
||||
end
|
||||
end
|
||||
|
@ -358,8 +358,8 @@ class Quizzes::QuizStatistics::StudentAnalysis < Quizzes::QuizStatistics::Report
|
|||
# "unexpected_response_values"=>[],
|
||||
# "user_ids"=>[1,2,3],
|
||||
# "multiple_responses"=>false}],
|
||||
def stats_for_question(question, responses)
|
||||
if CQS.can_analyze?(question)
|
||||
def stats_for_question(question, responses, legacy=true)
|
||||
if !legacy && CQS.can_analyze?(question)
|
||||
# the gem expects all hash keys to be symbols:
|
||||
question = CQS::Util.deep_symbolize_keys(question)
|
||||
responses = responses.map(&CQS::Util.method(:deep_symbolize_keys))
|
||||
|
|
|
@ -125,11 +125,11 @@ module Quizzes
|
|||
private
|
||||
|
||||
def student_analysis_report
|
||||
@student_analysis_report ||= object[:student_analysis].report.generate
|
||||
@student_analysis_report ||= object[:student_analysis].report.generate(false)
|
||||
end
|
||||
|
||||
def item_analysis_report
|
||||
@item_analysis_report ||= object[:item_analysis].report.generate
|
||||
@item_analysis_report ||= object[:item_analysis].report.generate(false)
|
||||
end
|
||||
|
||||
def remove_unwanted_fields(question)
|
||||
|
|
|
@ -328,11 +328,22 @@ describe Quizzes::QuizStatistics::StudentAnalysis do
|
|||
with(question_data, responses).
|
||||
returns({ some_metric: 5 })
|
||||
|
||||
output = subject.send(:stats_for_question, question_data, responses)
|
||||
output = subject.send(:stats_for_question, question_data, responses, false)
|
||||
output.should == {
|
||||
question_type: 'essay_question',
|
||||
some_metric: 5
|
||||
}.with_indifferent_access
|
||||
end
|
||||
|
||||
it "shouldn't proxy if the legacy flag is on" do
|
||||
question_data = {
|
||||
question_type: 'essay_question',
|
||||
answers: []
|
||||
}
|
||||
|
||||
CanvasQuizStatistics.expects(:analyze).never
|
||||
|
||||
subject.send(:stats_for_question, question_data, [])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue