scholl management add shixun count and shixun evaluate count

pre_develop
p31729568 6 years ago
parent a958f2fa3f
commit f19cbcb1c6

@ -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

@ -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

@ -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')

@ -12,7 +12,7 @@
<div class="grow-date-container" style="width: 450px;display: <%= params[:data_type] == 'grow' ? 'block' : 'none' %>">
<%= 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;' %>
</div>
<div class="contrast-date-container" style="width: 450px;display: <%= params[:data_type] == 'contrast' ? 'block' : 'none' %>">

@ -9,6 +9,8 @@
<th width="10%"><%= sort_tag('学生总人数', name: 'student_count', path: school_report_managements_path) %></th>
<th width="10%"><%= sort_tag('课堂总数', name: 'course_count', path: school_report_managements_path) %></th>
<th width="10%"><%= sort_tag('正在进行课堂数', name: 'active_course_count', path: school_report_managements_path) %></th>
<th width="10%"><%= sort_tag('创建实训数', name: 'shixun_count', path: school_report_managements_path) %></th>
<th width="10%"><%= sort_tag('评测次数', name: 'shixun_evaluate_count', path: school_report_managements_path) %></th>
<th width="10%"><%= sort_tag('实训作业总数', name: 'homework_count', path: school_report_managements_path) %></th>
<th width="10%"><%= sort_tag('其它作业总数', name: 'other_homework_count', path: school_report_managements_path) %></th>
<th width="14%"><%= sort_tag('动态时间', name: 'nearly_course_time', path: school_report_managements_path) %></th>
@ -24,6 +26,8 @@
<td><%= school[:student_count].to_i %></td>
<td><%= school[:course_count].to_i %></td>
<td><%= school[:active_course_count].to_i %></td>
<td><%= school[:shixun_count].to_i %></td>
<td><%= school[:shixun_evaluate_count].to_i %></td>
<td><%= school[:homework_count].to_i %></td>
<td><%= school[:other_homework_count].to_i %></td>
<td><%= format_time school[:nearly_course_time] %></td>

@ -21,6 +21,8 @@
学生总人数<span class="color-red"><%= @student_total %></span>人,
课堂总数<span class="color-red"><%= @course_total %></span>个,
正在进行课堂总数<span class="color-red"><%= @active_course_total %></span>个,
创建实训数<span class="color-red"><%= @shixun_total %></span>个,
评测次数<span class="color-red"><%= @shixun_evaluate_total %></span>个,
实训作业总数<span class="color-red"><%= @shixun_homework_total %></span>个,
其它作业总数<span class="color-red"><%= @other_homework_total %></span>个,
</div>

@ -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
Loading…
Cancel
Save