From 0afed6624d853ccc88421d983e5ca89a359246cc Mon Sep 17 00:00:00 2001 From: cxt Date: Fri, 2 Dec 2016 10:04:11 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=9C=AA=E5=8F=82=E4=B8=8E=E5=8C=BF?= =?UTF-8?q?=E8=AF=84=E7=9A=84=E7=BC=BA=E8=AF=84=E6=89=A3=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_common_controller.rb | 37 ++++++++------- app/controllers/student_work_controller.rb | 45 ++++++++++--------- app/models/homework_detail_manual.rb | 2 +- .../_set_score_rule_non_pro.html.erb | 11 ++++- .../_set_score_rule_none_pro_anon.html.erb | 2 +- .../_set_score_rule_pro.html.erb | 11 ++++- .../_set_score_rule_pro_anon.html.erb | 2 +- ..._add_no_anon_penalty_to_homework_manual.rb | 5 +++ db/schema.rb | 38 +++++++++++----- lib/tasks/homework_evaluation.rake | 39 ++++++++-------- 10 files changed, 115 insertions(+), 77 deletions(-) create mode 100644 db/migrate/20161201083030_add_no_anon_penalty_to_homework_manual.rb diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index b9a49dbcb..7f89b0fb9 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -257,26 +257,25 @@ class HomeworkCommonController < ApplicationController def stop_anonymous_comment @homework_detail_manual.update_column('comment_status', 3) @homework_detail_manual.update_column('evaluation_end', Date.today) - #计算缺评扣分 + # 计算缺评扣分 work_ids = "(" + @homework.student_works.has_committed.map(&:id).join(",") + ")" - if @homework.homework_type != 3 - @homework.student_works.has_committed.each do |student_work| - absence_penalty_count = student_work.user.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count - student_work.user.student_works_scores.where("student_work_id IN #{work_ids} and reviewer_role = 3").count - student_work.absence_penalty = absence_penalty_count > 0 ? absence_penalty_count * @homework_detail_manual.absence_penalty : 0 - student_work.save - end - else - @homework.student_works.has_committed.each do |student_work| - absence_penalty_count = student_work.user.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count - student_work.user.student_works_scores.where("student_work_id IN #{work_ids} and reviewer_role = 3").count - student_work.absence_penalty = absence_penalty_count > 0 ? absence_penalty_count * @homework_detail_manual.absence_penalty : 0 - student_work.save - pros = student_work.student_work_projects.where("is_leader = 0") - user_ids = pros.empty? ? "(-1)" : "(" + pros.map{|stu|stu.user_id}.join(",") + ")" - student_works = @homework.student_works.where("user_id in #{user_ids}") - student_works.each do |st_work| - absence_penalty_count = st_work.user.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count - st_work.user.student_works_scores.where("student_work_id IN #{work_ids} and reviewer_role = 3").count - st_work.absence_penalty = absence_penalty_count > 0 ? absence_penalty_count * @homework_detail_manual.absence_penalty : 0 - st_work.save + + # 参与匿评的缺评计算 + @homework.student_works.where("work_status != 0").each do |student_work| + absence_penalty_count = student_work.user.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count - student_work.user.student_works_scores.where("student_work_id IN #{work_ids} and reviewer_role = 3").count + student_work.absence_penalty = absence_penalty_count > 0 ? absence_penalty_count * @homework_detail_manual.absence_penalty : 0 + student_work.save + end + + # 未参与匿评的缺评计算 + if @homework_detail_manual.no_anon_penalty == 0 + all_dis_eva = StudentWorksEvaluationDistribution.where("student_work_id IN #{work_ids}") + has_sw_count = all_dis_eva.select("distinct user_id").count + anon_count = all_dis_eva.count / has_sw_count + @homework.student_works.where("work_status != 0").each do |student_work| + if student_work.user.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count == 0 + student_work.absence_penalty = @homework_detail_manual.absence_penalty * anon_count + student_work.save end end end diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index fb99f6507..0c6b42ca5 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -982,33 +982,38 @@ class StudentWorkController < ApplicationController end end - if params[:absence_penalty] && homework_detail_manual.absence_penalty.to_s != params[:absence_penalty].to_s - homework_detail_manual.absence_penalty = params[:absence_penalty] + no_anon_penalty = params[:no_anon_penalty] ? 1 : 0 + if no_anon_penalty != homework_detail_manual.no_anon_penalty + homework_detail_manual.no_anon_penalty = no_anon_penalty if homework_detail_manual.comment_status == 3 #当前作业处于匿评结束状态,修改缺评扣分才会修改每个作品应扣分的值 work_ids = "(" + @homework.student_works.has_committed.map(&:id).join(",") + ")" - if @homework.homework_type != 3 - @homework.student_works.has_committed.each do |student_work| - absence_penalty_count = student_work.user.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count - student_work.user.student_works_scores.where("student_work_id IN #{work_ids} and reviewer_role = 3").count - student_work.absence_penalty = absence_penalty_count > 0 ? absence_penalty_count * homework_detail_manual.absence_penalty : 0 - student_work.save - end - else - @homework.student_works.has_committed.each do |student_work| - absence_penalty_count = student_work.user.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count - student_work.user.student_works_scores.where("student_work_id IN #{work_ids} and reviewer_role = 3").count - student_work.absence_penalty = absence_penalty_count > 0 ? absence_penalty_count * homework_detail_manual.absence_penalty : 0 - student_work.save - pros = student_work.student_work_projects.where("is_leader = 0") - user_ids = pros.empty? ? "(-1)" : "(" + pros.map{|stu|stu.user_id}.join(",") + ")" - student_works = @homework.student_works.where("user_id in #{user_ids}") - student_works.each do |st_work| - absence_penalty_count = st_work.user.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count - st_work.user.student_works_scores.where("student_work_id IN #{work_ids} and reviewer_role = 3").count - st_work.absence_penalty = absence_penalty_count > 0 ? absence_penalty_count * homework_detail_manual.absence_penalty : 0 - st_work.save + all_dis_eva = StudentWorksEvaluationDistribution.where("student_work_id IN #{work_ids}") + has_sw_count = all_dis_eva.select("distinct user_id").count + anon_count = all_dis_eva.count / has_sw_count + @homework.student_works.where("work_status != 0").each do |student_work| + if student_work.user.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count == 0 + if no_anon_penalty == 0 + student_work.absence_penalty = homework_detail_manual.absence_penalty * anon_count + else + student_work.absence_penalty = 0 end + student_work.save end end end + homework_detail_manual.save if homework_detail_manual + end + if (params[:absence_penalty] && homework_detail_manual.absence_penalty.to_s != params[:absence_penalty].to_s) + homework_detail_manual.absence_penalty = params[:absence_penalty] + if homework_detail_manual.comment_status == 3 #当前作业处于匿评结束状态,修改缺评扣分才会修改每个作品应扣分的值 + work_ids = "(" + @homework.student_works.has_committed.map(&:id).join(",") + ")" + @homework.student_works.where("work_status != 0").each do |student_work| + absence_penalty_count = student_work.user.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count - student_work.user.student_works_scores.where("student_work_id IN #{work_ids} and reviewer_role = 3").count + student_work.absence_penalty = absence_penalty_count > 0 ? absence_penalty_count * homework_detail_manual.absence_penalty : 0 + student_work.save + end + end homework_detail_manual.save if homework_detail_manual end diff --git a/app/models/homework_detail_manual.rb b/app/models/homework_detail_manual.rb index e0c4dcdcb..6faa84d40 100644 --- a/app/models/homework_detail_manual.rb +++ b/app/models/homework_detail_manual.rb @@ -1,7 +1,7 @@ #手动评分作业表 #comment_status: 1:未开启匿评,2:开启匿评,3:匿评结束 class HomeworkDetailManual < ActiveRecord::Base - attr_accessible :ta_proportion, :comment_status, :evaluation_start, :evaluation_end, :evaluation_num, :absence_penalty, :homework_common_id + attr_accessible :ta_proportion, :comment_status, :evaluation_start, :evaluation_end, :evaluation_num, :absence_penalty, :homework_common_id, :no_anon_penalty belongs_to :homework_common end diff --git a/app/views/homework_common/_set_score_rule_non_pro.html.erb b/app/views/homework_common/_set_score_rule_non_pro.html.erb index afa768838..98f995a60 100644 --- a/app/views/homework_common/_set_score_rule_non_pro.html.erb +++ b/app/views/homework_common/_set_score_rule_non_pro.html.erb @@ -17,6 +17,10 @@
  • + value="<%=homework.homework_detail_manual.no_anon_penalty%>"/> + +
  • +
  • @@ -38,7 +42,7 @@ -