Skip to content

Instantly share code, notes, and snippets.

@grahamb
Last active December 17, 2015 03:29
Show Gist options
  • Select an option

  • Save grahamb/5543976 to your computer and use it in GitHub Desktop.

Select an option

Save grahamb/5543976 to your computer and use it in GitHub Desktop.
courses = Course.all(:conditions => "root_account_id = 2 AND enrollment_term_id = 5 AND workflow_state != 'deleted'")
types = ['StudentEnrollment', 'TeacherEnrollment', 'TaEnrollment', 'DesignerEnrollment', 'ObserverEnrollment', 'StudentViewEnrollment']
total_enrollments = {}
types.each do |t|
total_enrollments[t] = 0
end
courses.each do |c|
enrollments = c.enrollments.count(:distinct => true, :group => 'enrollments.type', :select => 'users.id', :conditions => 'enrollments.role_name IS NULL')
puts "#{c.id} #{enrollments}"
enrollments.each do |type, num|
total_enrollments[type] = (total_enrollments[type] + num)
end
end
# results
{"StudentEnrollment"=>7060, "TeacherEnrollment"=>339, "TaEnrollment"=>64, "DesignerEnrollment"=>182, "ObserverEnrollment"=>8, "StudentViewEnrollment"=>66}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment