Skip to content

Instantly share code, notes, and snippets.

@cmatheson
Created March 13, 2013 20:53
Show Gist options
  • Save cmatheson/5156048 to your computer and use it in GitHub Desktop.
Save cmatheson/5156048 to your computer and use it in GitHub Desktop.
this is good for testing Quiz#statistics performance
COURSE_ID = 5 # replace this with id of course with many (>=500) students
# generating a large course is left as an exercise to the reader
course = Course.find(COURSE_ID)
# generate quiz
q = course.quizzes.create! :title => "Big Quiz"
eval(File.read 'quiz_questions.txt').each_with_index do |(question, as), i|
answers = as.map.with_index { |a, j|
["answer_#{i+j}", {:answer_text => a, :id => i + j, :answer_weight => 0}]
}
answers[rand answers.size][1][:answer_weight] = 100
q.quiz_questions.create! :question_data => {
:question_type => "multiple_choice_question",
:question_name => "Question #{i+1}",
:question_text => question,
:points_possible => 1,
:answers => answers
}
end
q.points_possible = q.quiz_questions.map {
|qq| qq.question_data[:points_possible]
}.sum
q.generate_quiz_data
q.published_at = Time.now
q.publish!
# generate submissions
course.students.order(:id).each do |student|
puts "generating submission for #{student.name}"
qs = q.generate_submission(student)
submission_data = {}
expected_score = rand(0.6..1)
qs.quiz_data.each do |question|
prob = rand
next if prob <= 0.1 # skipped
correct, incorrect = question[:answers].partition { |a| a[:weight] == 100 }
answer = rand < expected_score ?
correct.first :
incorrect.first
submission_data["question_#{question[:id]}"] = answer[:id].to_s
end
qs.mark_completed
qs.submission_data = submission_data
qs.grade_submission
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment