Last active
January 21, 2018 10:39
-
-
Save itochan/08b75791a5bd63a88c864810dc361124 to your computer and use it in GitHub Desktop.
出席集計くん
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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