Skip to content

Instantly share code, notes, and snippets.

@samuels410
Last active February 9, 2018 06:53
Show Gist options
  • Save samuels410/f68cae823f08ba9b718f5c624c8c44a7 to your computer and use it in GitHub Desktop.
Save samuels410/f68cae823f08ba9b718f5c624c8c44a7 to your computer and use it in GitHub Desktop.
Rails console get completed student details
headers = ['SIS ID','Section name','Name','Start Date','Completed Date']
document_root = "#{Rails.root}"
csv_file_name = "learners-report-2079-a.csv"
csv_document = "#{document_root}/#{csv_file_name}"
CSV.open(csv_document, "w") do |csv|
csv << headers
course = Course.find(2079)
enrollments = Enrollment.where(course_id: 2079,workflow_state: ["inactive","active"])
modules = course.context_modules.active
enrollments.each do |enrollment|
completed = false
completed_at = nil
name = enrollment.user.name
section_name = enrollment.course_section.name
sis_user_id = enrollment.user.pseudonyms.first.sis_user_id
start_at = enrollment.created_at.strftime('%m/%d/%Y')
modules_and_progressions = modules.map { |m| [m, m.evaluate_for(enrollment.user)] }
modules_and_progressions.each do |modules_and_progression|
if modules_and_progression[1].workflow_state == 'completed'
completed = true
completed_at = modules_and_progression[1].completed_at.to_date.strftime('%m/%d/%Y')
else
completed = false
end
end
if completed
puts "sis_user_id:#{sis_user_id}"
csv << [sis_user_id,section_name,name,start_at,completed_at]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment