Quiz Stats - don't count teacher previews

Exclude preview quiz submission from student analysis (item analysis was
already accounting for this) based on the "was_preview" field.

Closes CNVS-8203

TEST PLAN
---- ----

  - create a quiz
  - take it as a preview by the teacher
    - request the stats from the API (or visit ember quiz stats)
    - verify that your attempt does not show up
  - take it by a student
    - verify everything is ok
  - now preview it again as a teacher
    - verify your attempt still doesn't add to the stats

Change-Id: I62bf1dd6c0bedb26ee55d029ac0f015b2ad48e91
Reviewed-on: https://gerrit.instructure.com/35954
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Derek DeVries <ddevries@instructure.com>
QA-Review: Clare Strong <clare@instructure.com>
Product-Review: Derek DeVries <ddevries@instructure.com>
This commit is contained in:
Ahmad Amireh 2014-06-05 10:35:45 +03:00 committed by Derek DeVries
parent 6bd7c07b78
commit 8b9e82ade8
2 changed files with 21 additions and 1 deletions

View File

@ -309,7 +309,7 @@ class Quizzes::QuizStatistics::StudentAnalysis < Quizzes::QuizStatistics::Report
#submissions from users #submissions from users
for_users = quiz.context.student_ids for_users = quiz.context.student_ids
scope = quiz.quiz_submissions.where(:user_id => for_users) scope = quiz.quiz_submissions.where(:user_id => for_users)
logged_out = quiz.quiz_submissions.logged_out logged_out = quiz.quiz_submissions.logged_out.where('NOT was_preview')
all_submissions = [] all_submissions = []
all_submissions = prep_submissions scope all_submissions = prep_submissions scope

View File

@ -316,6 +316,26 @@ describe Quizzes::QuizStatistics::StudentAnalysis do
stats.last[9].should == "lolcats,lolrus" stats.last[9].should == "lolcats,lolrus"
end end
it 'should not count teacher preview submissions' do
teacher_in_course(:active_all => true)
q = @course.quizzes.create!
q.update_attribute(:published_at, Time.now)
q.quiz_questions.create!(:question_data => {:name => 'q1', :points_possible => 1, 'question_type' => 'multiple_choice_question', 'answers' => [{'answer_text' => '', 'answer_html' => '<em>zero</em>', 'answer_weight' => '100'}, {'answer_text' => "", 'answer_html' => "<p>one</p>", 'answer_weight' => '0'}]})
q.quiz_questions.create!(:question_data => {:name => 'q2', :points_possible => 1, 'question_type' => 'multiple_answers_question', 'answers' => [{'answer_text' => '', 'answer_html' => "<a href='http://example.com/caturday.gif'>lolcats</a>", 'answer_weight' => '100'}, {'answer_text' => 'lolrus', 'answer_weight' => '100'}]})
q.generate_quiz_data
q.save
qs = q.generate_submission(@teacher, true)
qs.submission_data = {
"question_#{q.quiz_data[0][:id]}" => "#{q.quiz_data[0][:answers][0][:id]}",
"question_#{q.quiz_data[1][:id]}_answer_#{q.quiz_data[1][:answers][0][:id]}" => "1",
"question_#{q.quiz_data[1][:id]}_answer_#{q.quiz_data[1][:answers][1][:id]}" => "1"
}
Quizzes::SubmissionGrader.new(qs).grade_submission
stats = q.statistics
stats[:unique_submission_count].should == 0
end
describe 'question statistics' do describe 'question statistics' do
subject { Quizzes::QuizStatistics::StudentAnalysis.new({}) } subject { Quizzes::QuizStatistics::StudentAnalysis.new({}) }