module Weapps::AttendancesHelper def student_attendance_status attendance, user st_attendance = attendance.course_member_attendances.find_by(user_id: user.id) st_attendance.present? ? st_attendance.attendance_status : "ABSENCE" end def group_attendance_count attendances, member_ids # course_member_ids = group.course_members.pluck(:id) attendances.select{|attendance| member_ids.include?(attendance.course_member_id) && attendance.attendance_status == "NORMAL"}.size end def history_member_count member_attendances, status, attendance_id member_attendances.select{|member_attendance| member_attendance.attendance_status == status && member_attendance.course_attendance_id == attendance_id}.size end def cal_rate base, sum sum == 0 ? 0 : (base.to_f / sum) end end