From 51014fa2583b2cbebed264729924c971d38680a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=98=8E?= <775174143@qq.com> Date: Thu, 12 Mar 2020 16:45:59 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/react/src/modules/paths/PathDetail/DetailTop.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/public/react/src/modules/paths/PathDetail/DetailTop.js b/public/react/src/modules/paths/PathDetail/DetailTop.js index 1509b2b43..bf43c0759 100644 --- a/public/react/src/modules/paths/PathDetail/DetailTop.js +++ b/public/react/src/modules/paths/PathDetail/DetailTop.js @@ -116,9 +116,9 @@ class DetailTop extends Component{ this.setState({ loadtype:true, Modalstype: true, - Modalstopval:` 课程需经过平台审核方可公开使用,公开的课程将对平台所`, - modalsMidval:"有人公开可见,若仅本人教学使用则无需申请公开,直接发", - Modalsbottomval:"送到课堂即可。", + Modalstopval:`课程发布后即可发送课堂使用`, + // modalsMidval:"有人公开可见,若仅本人教学使用则无需申请公开,直接发", + // Modalsbottomval:"送到课堂即可。", applyissuePaths:true }) From 759ad9bdb8321e2b7669ef85ee20b8d7139311b7 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 12 Mar 2020 18:12:51 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E7=AC=91=E5=88=B0=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/attendances_controller.rb | 26 +++++---- app/services/attendance_statistics_service.rb | 54 +++++++++++++++++++ .../attendances/statistics.json.jbuilder | 10 ++++ config/routes.rb | 2 +- 4 files changed, 81 insertions(+), 11 deletions(-) create mode 100644 app/services/attendance_statistics_service.rb create mode 100644 app/views/attendances/statistics.json.jbuilder diff --git a/app/controllers/attendances_controller.rb b/app/controllers/attendances_controller.rb index e920eaa8a..dc30df7e3 100644 --- a/app/controllers/attendances_controller.rb +++ b/app/controllers/attendances_controller.rb @@ -1,7 +1,7 @@ class AttendancesController < ApplicationController + before_action :require_login - before_action :find_course, only: [:index, :student_attendances, :history_attendances] - before_action :find_attendance, except: [:index, :student_attendances, :history_attendances] + before_action :find_course, only: [:index, :statistics] before_action :user_course_identity def index @@ -32,17 +32,23 @@ class AttendancesController < ApplicationController end def statistics - - end - - def history_attendances current_date = Date.current current_end_time = Time.current.strftime("%H:%M:%S") + history_attendances = @course.course_attendances.where("attendance_date < '#{current_date}' or + (attendance_date = '#{current_date}' and end_time < '#{current_end_time}')") + all_member_attendances = CourseMemberAttendance.where(course_attendance_id: history_attendances) + if params[:group_id].present? + history_attendances = history_attendances.joins(:course_attendance_groups).where(course_attendance_groups: {course_group_id: [params[:group_id], 0]}) + all_member_attendances = all_member_attendances.joins(:course_member).where(course_members: {course_group_id: params[:group_id]}) + end - @history_attendances = @course.course_attendances.where("attendance_date < '#{current_date}' or - (attendance_date = '#{current_date}' and end_time < '#{current_end_time}')").order("id desc") - @all_history_count = @history_attendances.size - @history_attendances = paginate @history_attendances.includes(:course_member_attendances) + history_attendances = history_attendances.order("attendance_date desc, start_time desc") + data = AttendanceStatisticsService.call history_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 private diff --git a/app/services/attendance_statistics_service.rb b/app/services/attendance_statistics_service.rb new file mode 100644 index 000000000..e31049b22 --- /dev/null +++ b/app/services/attendance_statistics_service.rb @@ -0,0 +1,54 @@ +class AttendanceStatisticsService < ApplicationService + + attr_reader :attendances, :member_attendances + + def initialize(attendances, member_attendances) + @attendances = attendances + @member_attendances = member_attendances + end + + def call + all_normal_rate = [] + all_absence_rate = [] + all_leave_rate = [] + + history_attendances = [] + + attendances.each do |attendance| + normal_count = history_member_count(member_attendances, "NORMAL", attendance.id) + absence_count = history_member_count(member_attendances, "ABSENCE", attendance.id) + leave_count = history_member_count(member_attendances, "LEAVE", attendance.id) + all_count = member_attendances.select{|member_attendance| member_attendance.course_attendance_id == attendance.id}.size + + normal_rate = cal_rate(normal_count, all_count) + all_normal_rate << normal_rate + absence_rate = cal_rate(absence_count, all_count) + all_absence_rate << absence_rate + leave_rate = cal_rate(leave_count, all_count) + all_leave_rate << leave_rate + + history_attendances << {name: attendance.name, attendance_date: attendance.attendance_date.strftime("%Y-%m-%d"), + start_time: attendance.start_time.strftime("%H:%M"), end_time: attendance.end_time.strftime("%H:%M"), + normal_rate: normal_rate, absence_rate: absence_rate, leave_rate: leave_rate} + end + + all_history_count = history_attendances.size + history_attendances = history_attendances[0..9].reverse + avg_normal_rate = cal_rate(all_normal_rate.sum, all_history_count) + avg_absence_rate = cal_rate(all_absence_rate.sum, all_history_count) + avg_leave_rate = cal_rate(all_leave_rate.sum, all_history_count) + + {all_history_count: all_history_count, history_attendances: history_attendances, avg_normal_rate: avg_normal_rate, + avg_absence_rate: avg_absence_rate, avg_leave_rate: avg_leave_rate} + end + + private + + 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 \ No newline at end of file diff --git a/app/views/attendances/statistics.json.jbuilder b/app/views/attendances/statistics.json.jbuilder new file mode 100644 index 000000000..d07f234d6 --- /dev/null +++ b/app/views/attendances/statistics.json.jbuilder @@ -0,0 +1,10 @@ + +json.history_attendances @history_attendances.each_with_index.to_a do |attendance, index| + 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 @avg_normal_rate +json.avg_absence_rate @avg_absence_rate +json.avg_leave_rate @avg_leave_rate \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 0f1bc5ba4..6c3efcfe8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -551,7 +551,7 @@ Rails.application.routes.draw do end resources :attendances, shallow: true do - + get :statistics, on: :collection end resources :polls, only:[:index,:new,:create] do From d588229832fb9c6bbbb0b8ff6e5e61ee3c597961 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 12 Mar 2020 18:18:35 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E7=AD=BE?= =?UTF-8?q?=E5=88=B0=E5=8F=AA=E6=98=BE=E7=A4=BA=E6=9C=80=E8=BF=91=E5=8D=81?= =?UTF-8?q?=E6=AC=A1=E7=AD=BE=E5=88=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weapps/attendances_controller.rb | 10 ++++++-- .../weapps/attendances/index.json.jbuilder | 23 ++++--------------- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/app/controllers/weapps/attendances_controller.rb b/app/controllers/weapps/attendances_controller.rb index 2ec4180a1..da22aa300 100644 --- a/app/controllers/weapps/attendances_controller.rb +++ b/app/controllers/weapps/attendances_controller.rb @@ -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 diff --git a/app/views/weapps/attendances/index.json.jbuilder b/app/views/weapps/attendances/index.json.jbuilder index da8be3c8d..4326880ef 100644 --- a/app/views/weapps/attendances/index.json.jbuilder +++ b/app/views/weapps/attendances/index.json.jbuilder @@ -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