From 17f347552fa745517b982e77c4542f4d444a132e Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 18 Mar 2020 16:43:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E9=87=8D=E5=81=9A=E7=8A=B6?= =?UTF-8?q?=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../competitions/competition_teams_controller.rb | 6 +++--- app/controllers/myshixuns_controller.rb | 2 +- app/helpers/export_helper.rb | 4 +++- app/helpers/homework_commons_helper.rb | 8 +++++++- app/services/homeworks_service.rb | 6 +++--- lib/tasks/competition_extra_course_statistic.rake | 8 ++++---- 6 files changed, 21 insertions(+), 13 deletions(-) diff --git a/app/controllers/competitions/competition_teams_controller.rb b/app/controllers/competitions/competition_teams_controller.rb index 3abb0b70a..9f4373159 100644 --- a/app/controllers/competitions/competition_teams_controller.rb +++ b/app/controllers/competitions/competition_teams_controller.rb @@ -38,7 +38,7 @@ class Competitions::CompetitionTeamsController < Competitions::BaseController student_count_subquery = CourseMember.where('course_id = courses.id AND role = 4').select('count(*)').to_sql subquery = StudentWork.where('homework_common_id = hcs.id') - .select('sum(compelete_status !=0 ) as finish, count(*) as total') + .select('sum(compelete_status >0 ) as finish, count(*) as total') .having('total != 0 and finish >= (total / 2)').to_sql course_ids = Course.where('courses.created_at > ?', start_time) .where('courses.created_at <= ?', end_time) @@ -149,7 +149,7 @@ class Competitions::CompetitionTeamsController < Competitions::BaseController def get_valid_course_count(ids) percentage_sql = StudentWork.where('homework_common_id = homework_commons.id and homework_commons.publish_time is not null and homework_commons.publish_time < NOW()') - .select('sum(compelete_status !=0 ) as finish, count(*) as total') + .select('sum(compelete_status >0 ) as finish, count(*) as total') .having('total != 0 and finish >= (total / 2)').to_sql Course.joins(practice_homeworks: :homework_commons_shixun) @@ -160,7 +160,7 @@ class Competitions::CompetitionTeamsController < Competitions::BaseController def get_valid_shixun_count(ids) percentage_sql = StudentWork.where('homework_common_id = homework_commons.id and homework_commons.publish_time is not null and homework_commons.publish_time < NOW()') - .select('sum(compelete_status !=0 ) as finish, count(*) as total') + .select('sum(compelete_status >0 ) as finish, count(*) as total') .having('total != 0 and finish >= (total / 2)').to_sql Shixun.joins(homework_commons_shixuns: :homework_common) .where(homework_commons: { homework_type: 4 }) diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index e816ab667..a96a2a79f 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -28,7 +28,7 @@ class MyshixunsController < ApplicationController StudentWork.where(:myshixun_id => @myshixun.id) .update_all(myshixun_id: 0, work_status: 0, work_score: nil, - final_score: nil, efficiency: 0, eff_score: 0, calculation_time: nil, cost_time: 0, compelete_status: 0) + final_score: nil, efficiency: 0, eff_score: 0, calculation_time: nil, cost_time: 0, compelete_status: -1) end # 删除版本库 GitService.delete_repository(repo_path: @repo_path) unless @shixun.is_choice_type? diff --git a/app/helpers/export_helper.rb b/app/helpers/export_helper.rb index 6d0ae2422..1fd8616c5 100644 --- a/app/helpers/export_helper.rb +++ b/app/helpers/export_helper.rb @@ -457,7 +457,9 @@ module ExportHelper course_name = course.students.find_by(user_id: w.user_id).try(:course_group_name) w_5 = course_name.present? ? course_name : "--" #0: 未提交, 1 按时提交, 2 延迟提交 - if w.compelete_status == 0 + if w.compelete_status == -1 + w_6 = "重做中" + elsif w.compelete_status == 0 w_6 = "未开启" elsif w.compelete_status == 1 w_6 = "未通关" diff --git a/app/helpers/homework_commons_helper.rb b/app/helpers/homework_commons_helper.rb index 534abea6f..96dd471b5 100644 --- a/app/helpers/homework_commons_helper.rb +++ b/app/helpers/homework_commons_helper.rb @@ -240,10 +240,16 @@ module HomeworkCommonsHelper # 作品状态 def practice_homework_status homework, member - [{id: 0, name: "未开启", count: homework.compelete_status_count(member, 0)}, + status_arr = [{id: 0, name: "未开启", count: homework.compelete_status_count(member, 0)}, {id: 1, name: "未通关", count: homework.compelete_status_count(member, 1)}, {id: 2, name: "按时通关", count: homework.compelete_status_count(member, 2)}, {id: 3, name: "迟交通关", count: homework.compelete_status_count(member, 3)}] + + redo_count = homework.compelete_status_count(member, -1) + if redo_count > 0 + status_arr.insert(1, {id: -1, name: "重做中", count: homework.compelete_status_count(member, -1)}) + end + status_arr end # 作品状态 diff --git a/app/services/homeworks_service.rb b/app/services/homeworks_service.rb index 5483eed83..b161be991 100644 --- a/app/services/homeworks_service.rb +++ b/app/services/homeworks_service.rb @@ -133,9 +133,9 @@ class HomeworksService # 计算实训作品学生的效率分 def update_student_eff_score homework if homework.work_efficiency && homework.max_efficiency != 0 - max_efficiency = homework.student_works.where("compelete_status != 0").pluck(:efficiency).max + max_efficiency = homework.student_works.where("compelete_status > 0").pluck(:efficiency).max homework.update_column("max_efficiency", max_efficiency) - homework.student_works.where("compelete_status != 0").each do |student_work| + homework.student_works.where("compelete_status > 0").each do |student_work| eff_score = student_work.efficiency / max_efficiency * homework.eff_score student_work.eff_score = format("%.2f", eff_score) student_work.late_penalty = student_work.work_status == 1 ? 0 : homework.late_penalty @@ -146,7 +146,7 @@ class HomeworksService student_work.save! end else - homework.student_works.where("compelete_status != 0").each do |student_work| + homework.student_works.where("compelete_status > 0").each do |student_work| student_work.eff_score = 0 student_work.late_penalty = student_work.work_status == 1 ? 0 : homework.late_penalty unless student_work.ultimate_score diff --git a/lib/tasks/competition_extra_course_statistic.rake b/lib/tasks/competition_extra_course_statistic.rake index a3e4f4f91..3ef6bcd18 100644 --- a/lib/tasks/competition_extra_course_statistic.rake +++ b/lib/tasks/competition_extra_course_statistic.rake @@ -12,7 +12,7 @@ namespace :competition do student_count_subquery = CourseMember.where('course_id = courses.id AND role = 4').select('count(*)').to_sql subquery = StudentWork.where('homework_common_id = hcs.id') - .select('sum(compelete_status !=0 ) as finish, count(*) as total') + .select('sum(compelete_status >0 ) as finish, count(*) as total') .having('total != 0 and finish >= (total / 2)').to_sql shixun_user_ids = Shixun.where.not(user_id: old_competition_user_ids).where(status: 2).where('shixuns.created_at > ? && shixuns.created_at <= ?', start_time, end_time).pluck(:user_id).uniq course_user_ids = Course.where.not(tea_id: old_competition_user_ids).where('courses.created_at > ?', start_time) @@ -109,7 +109,7 @@ namespace :competition do # =========== Course =========== student_count_subquery = CourseMember.where('course_id = courses.id AND role = 4').select('count(*)').to_sql subquery = StudentWork.where('homework_common_id = hcs.id') - .select('sum(compelete_status !=0 ) as finish, count(*) as total') + .select('sum(compelete_status >0 ) as finish, count(*) as total') .having('total != 0 and finish >= (total / 2)').to_sql course_ids = Course.where('courses.created_at > ?', start_time) .where('courses.created_at <= ?', end_time) @@ -173,7 +173,7 @@ namespace :competition do def get_valid_course_count(ids, end_time) percentage_sql = StudentWork.where('homework_common_id = homework_commons.id and homework_commons.publish_time is not null and homework_commons.publish_time < ?', end_time) - .select('sum(compelete_status !=0 ) as finish, count(*) as total') + .select('sum(compelete_status >0 ) as finish, count(*) as total') .having('total != 0 and finish >= (total / 2)').to_sql Course.joins(practice_homeworks: :homework_commons_shixun) @@ -184,7 +184,7 @@ namespace :competition do def get_valid_shixun_count(ids, end_time) percentage_sql = StudentWork.where('homework_common_id = homework_commons.id and homework_commons.publish_time is not null and homework_commons.publish_time < ?', end_time) - .select('sum(compelete_status !=0 ) as finish, count(*) as total') + .select('sum(compelete_status >0 ) as finish, count(*) as total') .having('total != 0 and finish >= (total / 2)').to_sql Shixun.joins(homework_commons_shixuns: :homework_common) .where(homework_commons: { homework_type: 4 })