Skip to content

Instantly share code, notes, and snippets.

@fivetanley
Forked from cmatheson/big-gradebook-generator.rb
Last active December 24, 2015 12:49
Show Gist options
  • Save fivetanley/6800515 to your computer and use it in GitHub Desktop.
Save fivetanley/6800515 to your computer and use it in GitHub Desktop.
N_ASSIGNMENTS=100
N_USERS=500
def grade_submission_sql_inserts(assignment,student,grade)
"(#{assignment.id}, #{student.id}, #{grade}, true, 'graded', '#{Time.zone.now.iso8601}')"
end
def grade_submission_sql(assignments,students)
students_sql = assignments.map do |assignment|
students.map do |student|
unless rand > 0.9
grade_submission_sql_inserts(assignment, student, rand(assignment.points_possible))
end
end.compact
end.flatten
"INSERT INTO submissions (assignment_id, user_id, score, grade_matches_current_submission, workflow_state, graded_at) VALUES #{students_sql.join(',')}"
end
begin
account = Account.default
account.transaction do
course = account.courses.create! name: "Big Gradebook"
e = course.enroll_teacher(User.find(1))
assignments = N_ASSIGNMENTS.times.map do |i|
printf "\rmaking assignment... %3d/%d", i+1, N_ASSIGNMENTS
course.assignments.create! name: "Assignment #{i+1}",
submission_types: "online_text_entry",
points_possible: rand(100)
end
puts
students = 500.times.map do |i|
printf "\rmaking student... %3d/%d", i+1, N_USERS
u = User.create! :name => "student #{i + 1}"
end
section_id = course.course_sections.first.id
inserts = students.map do |student|
"(#{student.id}, 'StudentEnrollment', #{course.id}, 'active', #{section_id}, #{account.id})"
end
inserts = inserts.join ','
Course.connection.execute "INSERT INTO enrollments (user_id, type, course_id, workflow_state, course_section_id, root_account_id) VALUES #{inserts}"
puts "enrolled students\n"
# grade the students
Course.connection.execute grade_submission_sql(assignments, course.students)
puts "graded students\n"
exit 0
end
rescue => e
puts e
ensure
puts
exit 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment