小程序签到只显示最近十次签到

PCqiandao
cxt 5 years ago
parent 759ad9bdb8
commit d588229832

@ -37,8 +37,14 @@ class Weapps::AttendancesController < ApplicationController
@all_member_attendances = @all_member_attendances.joins(:course_member).where(course_members: {course_group_id: params[:group_id]})
end
@history_attendances = all_attendances.order("id asc")
@all_history_count = @history_attendances.size
all_attendances = all_attendances.order("attendance_date desc, start_time desc")
data = AttendanceStatisticsService.call all_attendances, @all_member_attendances
@all_history_count = data[:all_history_count]
@history_attendances = data[:history_attendances]
@avg_normal_rate = data[:avg_normal_rate]
@avg_absence_rate = data[:avg_absence_rate]
@avg_leave_rate = data[:avg_leave_rate]
end
def student_attendances

@ -5,25 +5,12 @@ json.current_attendance @current_attendance do |attendance|
json.end_time attendance.end_time.strftime("%H:%M")
end
all_normal_rate = []
all_absence_rate = []
all_leave_rate = []
json.history_attendances @history_attendances.each_with_index.to_a do |attendance, index|
normal_count = history_member_count(@all_member_attendances, "NORMAL", attendance.id)
absence_count = history_member_count(@all_member_attendances, "ABSENCE", attendance.id)
leave_count = history_member_count(@all_member_attendances, "LEAVE", attendance.id)
all_count = @all_member_attendances.select{|member_attendance| member_attendance.course_attendance_id == attendance.id}.size
json.index index + 1
json.normal_rate cal_rate(normal_count, all_count)
all_normal_rate << cal_rate(normal_count, all_count)
json.absence_rate cal_rate(absence_count, all_count)
all_absence_rate << cal_rate(absence_count, all_count)
json.leave_rate cal_rate(leave_count, all_count)
all_leave_rate << cal_rate(leave_count, all_count)
json.(attendance, :name, :attendance_date, :start_time, :end_time, :normal_rate, :absence_rate, :leave_rate)
json.index "签到#{index + 1}"
end
json.all_history_count @all_history_count
json.avg_normal_rate @all_history_count == 0 ? 0 : all_normal_rate.sum / @all_history_count
json.avg_absence_rate @all_history_count == 0 ? 0 : all_absence_rate.sum / @all_history_count
json.avg_leave_rate @all_history_count == 0 ? 0 : all_leave_rate.sum / @all_history_count
json.avg_normal_rate @avg_normal_rate
json.avg_absence_rate @avg_absence_rate
json.avg_leave_rate @avg_leave_rate

Loading…
Cancel
Save