Skip to content

Instantly share code, notes, and snippets.

@itochan
Last active January 21, 2018 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itochan/08b75791a5bd63a88c864810dc361124 to your computer and use it in GitHub Desktop.
Save itochan/08b75791a5bd63a88c864810dc361124 to your computer and use it in GitHub Desktop.
出席集計くん
require 'csv'
meetings = %w[82 85 86 91 92 93 94 87 95 96 88 97 111 98]
attendances = {}
MeetingAttendance.where(meeting_id: meetings).map do |attend|
if attendances[attend.user.nickname]
attendances[attend.user.nickname][:count] += 1
else
attendances[attend.user.nickname] = {
kg: GroupUser.where(user: attend.user).first.group.name,
student_id: LdapCredential.find_by(uid: attend.user.nickname).try(:student_id),
count: 1
}
end
end
attendances = attendances.map do |attendance|
[attendance[1][:kg], attendance[0], attendance[1][:student_id], attendance[1][:count]]
end
CSV.open('/home/itochan/rg_attendance_2017f.csv', 'w') do |csv|
attendances.sort.each do |attendance|
csv << attendance
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment