diff --git a/app/controllers/managements/schools_controller.rb b/app/controllers/managements/schools_controller.rb index a5c789ff..4e9b41ed 100644 --- a/app/controllers/managements/schools_controller.rb +++ b/app/controllers/managements/schools_controller.rb @@ -78,5 +78,7 @@ class Managements::SchoolsController < Managements::BaseController @active_course_total = Course.where(is_end: false).count @shixun_homework_total = HomeworkCommon.where(homework_type: 4).count @other_homework_total = HomeworkCommon.where(homework_type: [1, 3]).count + @shixun_total = Shixun.count + @shixun_evaluate_total = Game.sum(:evaluate_count) end end diff --git a/app/services/games_service.rb b/app/services/games_service.rb index 937e4ecd..08f4516e 100644 --- a/app/services/games_service.rb +++ b/app/services/games_service.rb @@ -528,11 +528,12 @@ class GamesService # 三类实训只取基础部分数据 game = Game.select([:myshixun_id, :status, :challenge_id, :id, :evaluate_count]).find_by_identifier(params[:identifier]) myshixun = Myshixun.select([:updated_at, :gpid, :id, :shixun_id]).find(game.myshixun_id) - shixun = Shixun.select([:id, :evaluate_script, :webssh, :exec_time, :sigle_training, :identifier, :status]).find(myshixun.shixun_id) + shixun = Shixun.select([:id, :evaluate_script, :webssh, :exec_time, :sigle_training, :identifier, :status, :evaluate_count]).find(myshixun.shixun_id) game_challenge = Challenge.select([:id, :position, :picture_path]).find(game.challenge_id) # 更新评测次数 game.update_column(:evaluate_count, (game.evaluate_count.to_i + 1)) + shixun.increment!(:evaluate_count) # 清空代码评测信息 msg = game.run_code_message msg.update_attributes(:status => 0, :message => nil) if msg.present? @@ -693,6 +694,7 @@ class GamesService :evaluate_count]).find_by_identifier(params[:identifier]) # 更新评测次数 game.update_column(:evaluate_count, (game.evaluate_count.to_i + 1)) + game.challenge.shixun.increment!(:evaluate_count) # 选择题如果通关了,则不让再评测 if game.status == 2 diff --git a/app/services/management/school_report_service.rb b/app/services/management/school_report_service.rb index 2b18950d..b102c01a 100644 --- a/app/services/management/school_report_service.rb +++ b/app/services/management/school_report_service.rb @@ -4,7 +4,7 @@ class Management::SchoolReportService attr_reader :params sort_columns :student_count, :teacher_count, :homework_count, :other_homework_count, - :course_count, :active_course_count, :nearly_course_time, + :course_count, :active_course_count, :nearly_course_time, :shixun_count, :shixun_evaluate_count, default_by: :teacher_count, default_direction: :desc def initialize(params) @@ -47,6 +47,11 @@ class Management::SchoolReportService nearly_course_time_map = courses.joins(:course_activities).maximum('course_activities.updated_at') active_course_map = courses.where(is_end: false).count + shixun_map = Shixun.joins(creator: :user_extensions).where(user_extensions: { identity: User::TEACHER, school_id: ids }) + .group('school_id').count + evaluate_count_map = Shixun.joins(creator: :user_extensions).where(user_extensions: { identity: User::TEACHER, school_id: ids }) + .group('school_id').sum(:evaluate_count) + schools.map do |school| { id: school.id, @@ -58,6 +63,8 @@ class Management::SchoolReportService course_count: course_map[school.id], nearly_course_time: nearly_course_time_map[school.id], active_course_count: active_course_map[school.id], + shixun_count: shixun_map.fetch(school.id, 0), + shixun_evaluate_count: evaluate_count_map.fetch(school.id, 0) } end end @@ -78,6 +85,12 @@ class Management::SchoolReportService when 'course_count' then schools.joins('LEFT JOIN courses cs ON cs.school_id = schools.id AND cs.is_delete = 0') .select("#{base_query_column}, COUNT(*) course_count") + when 'shixun_count' then + schools.joins(teacher_extensions: :user).joins('INNER JOIN shixuns sx ON sx.user_id = users.id') + .select("#{base_query_column}, COUNT(*) shixun_count") + when 'shixun_evaluate_count' then + schools.joins(teacher_extensions: :user).joins('INNER JOIN shixuns sx ON sx.user_id = users.id') + .select("#{base_query_column}, SUM(sx.evaluate_count) shixun_evaluate_count") when 'nearly_course_time' then schools.joins('LEFT JOIN courses cs ON cs.school_id = schools.id AND cs.is_delete = 0') .joins('LEFT JOIN course_activities acs ON acs.course_id = cs.id') diff --git a/app/views/managements/schools/_contrast_search_form.html.erb b/app/views/managements/schools/_contrast_search_form.html.erb index 9597a9c7..b77f2dbb 100644 --- a/app/views/managements/schools/_contrast_search_form.html.erb +++ b/app/views/managements/schools/_contrast_search_form.html.erb @@ -12,7 +12,7 @@
<%= text_field_tag :grow_date_input, params[:grow_date_input], - class: 'grow-date-input winput-220-30', placeholder: '请选择时间段', + class: 'grow-date-input winput-220-30', placeholder: '请选择时间段(具体从当日5:00开始计算)', style: 'width: 400px;' %>
diff --git a/app/views/managements/schools/_statistics_list.html.erb b/app/views/managements/schools/_statistics_list.html.erb index 53c13ed8..0a0cb75d 100644 --- a/app/views/managements/schools/_statistics_list.html.erb +++ b/app/views/managements/schools/_statistics_list.html.erb @@ -9,6 +9,8 @@ <%= sort_tag('学生总人数', name: 'student_count', path: school_report_managements_path) %> <%= sort_tag('课堂总数', name: 'course_count', path: school_report_managements_path) %> <%= sort_tag('正在进行课堂数', name: 'active_course_count', path: school_report_managements_path) %> + <%= sort_tag('创建实训数', name: 'shixun_count', path: school_report_managements_path) %> + <%= sort_tag('评测次数', name: 'shixun_evaluate_count', path: school_report_managements_path) %> <%= sort_tag('实训作业总数', name: 'homework_count', path: school_report_managements_path) %> <%= sort_tag('其它作业总数', name: 'other_homework_count', path: school_report_managements_path) %> <%= sort_tag('动态时间', name: 'nearly_course_time', path: school_report_managements_path) %> @@ -24,6 +26,8 @@ <%= school[:student_count].to_i %> <%= school[:course_count].to_i %> <%= school[:active_course_count].to_i %> + <%= school[:shixun_count].to_i %> + <%= school[:shixun_evaluate_count].to_i %> <%= school[:homework_count].to_i %> <%= school[:other_homework_count].to_i %> <%= format_time school[:nearly_course_time] %> diff --git a/app/views/managements/schools/statistics.html.erb b/app/views/managements/schools/statistics.html.erb index 3aba8ab1..d4eff134 100644 --- a/app/views/managements/schools/statistics.html.erb +++ b/app/views/managements/schools/statistics.html.erb @@ -21,6 +21,8 @@ 学生总人数<%= @student_total %>人, 课堂总数<%= @course_total %>个, 正在进行课堂总数<%= @active_course_total %>个, + 创建实训数<%= @shixun_total %>个, + 评测次数<%= @shixun_evaluate_total %>个, 实训作业总数<%= @shixun_homework_total %>个, 其它作业总数<%= @other_homework_total %>个,
diff --git a/db/migrate/20190530055732_add_evaluate_count_to_shixuns.rb b/db/migrate/20190530055732_add_evaluate_count_to_shixuns.rb new file mode 100644 index 00000000..9389afd0 --- /dev/null +++ b/db/migrate/20190530055732_add_evaluate_count_to_shixuns.rb @@ -0,0 +1,24 @@ +class AddEvaluateCountToShixuns < ActiveRecord::Migration + def up + add_column :shixuns, :evaluate_count, :integer, default: 0 + + limit = 100 + total = Shixun.count + + ((total / 100) + 1).times do |index| + shixun_ids = Shixun.order(:id).limit(limit).offset(index * limit).pluck(:id) + return if shixun_ids.blank? + + count_map = Game.joins(:challenge).where(challenges: { shixun_id: shixun_ids }).group('shixun_id').sum(:evaluate_count) + + id_str = count_map.keys.join(',') + str = count_map.map { |shixun_id, count| "WHEN #{shixun_id} THEN #{count}" }.join(' ') + + execute "UPDATE shixuns SET evaluate_count = CASE id #{str} END WHERE id IN (#{id_str})" + end + end + + def down + remove_column :shixuns, :evaluate_count + end +end