2016-12-30 10:30:21 +08:00
|
|
|
#coding=utf-8
|
|
|
|
|
|
|
|
namespace :contest_work_evaluation do
|
|
|
|
desc "start and end evaluation"
|
2016-12-30 17:25:44 +08:00
|
|
|
def get_assigned_contestant_works(judges, n, index, num)
|
2016-12-30 19:35:43 +08:00
|
|
|
judges = judges + judges
|
|
|
|
first_index = (index * n) % num
|
|
|
|
last_index = (index * n + n - 1) % num < first_index ? ((index * n + n - 1) % num) + num : (index * n + n - 1) % num
|
|
|
|
judges[first_index .. last_index]
|
2016-12-30 10:30:21 +08:00
|
|
|
end
|
|
|
|
# 获取竞赛的评委人员
|
|
|
|
def contest_judges contest
|
|
|
|
contest.contest_members.select{|cm| cm.roles.to_s.include?("Judge")}
|
|
|
|
end
|
2017-01-05 19:12:31 +08:00
|
|
|
# 获取竞赛的管理人员
|
|
|
|
def contest_managers contest
|
|
|
|
contest.contest_members.select{|cm| cm.roles.to_s.include?("ContestManager")}
|
|
|
|
end
|
2016-12-30 10:30:21 +08:00
|
|
|
#自动开启匿评的任务
|
|
|
|
task :start_evaluation => :environment do
|
|
|
|
Rails.logger.info("log--------------------------------contest_work_start_evaluation start")
|
|
|
|
puts "--------------------------------contest_work_start_evaluation start"
|
|
|
|
works = Work.where(:online_evaluation => true, :work_status => [1, 2])
|
|
|
|
work_ids = works.blank? ? "(-1)" : "(" + works.map{|work| work.id}.join(",") + ")"
|
2016-12-30 17:25:44 +08:00
|
|
|
homework_detail_manuals = WorkDetailManual.where("evaluation_start <= '#{Date.today}' and work_id in #{work_ids}")
|
2016-12-30 10:30:21 +08:00
|
|
|
homework_detail_manuals.each do |homework_detail_manual|
|
|
|
|
work = homework_detail_manual.work
|
|
|
|
contestant_works = work.contestant_works.has_committed
|
2017-01-05 19:12:31 +08:00
|
|
|
judges = contest_judges work.contest
|
2016-12-30 10:30:21 +08:00
|
|
|
|
2017-01-05 19:12:31 +08:00
|
|
|
# 作品数为0||评委数为0 启动失败给管理员发消息
|
|
|
|
if contestant_works.count == 0 || judges.count == 0
|
2016-12-30 10:30:21 +08:00
|
|
|
contest = work.contest
|
2017-01-05 19:12:31 +08:00
|
|
|
contest_managers(contest).each do |m|
|
|
|
|
work.contest_messages << ContestMessage.new(:user_id => m.user_id, :contest_id => contest.id, :viewed => false, :status => 4)
|
2016-12-30 10:30:21 +08:00
|
|
|
end
|
|
|
|
else
|
2017-01-05 19:12:31 +08:00
|
|
|
#限定评审人数
|
|
|
|
if homework_detail_manual.evaluation_num != -1
|
|
|
|
# 分配作品 启动成功给评委发消息
|
|
|
|
n = homework_detail_manual.evaluation_num
|
|
|
|
n = (n < judges.size && n != -1) ? n : judges.size
|
|
|
|
contestant_works.each_with_index do |work, index|
|
|
|
|
user = work.user
|
|
|
|
assigned_judges = get_assigned_contestant_works(judges, n, index, judges.size)
|
|
|
|
assigned_judges.each do |h|
|
|
|
|
contestant_works_evaluation_distributions = ContestantWorkEvaluationDistribution.new(user_id: h.user_id, contestant_work_id: work.id)
|
|
|
|
contestant_works_evaluation_distributions.save
|
|
|
|
end
|
|
|
|
end
|
2016-12-30 10:30:21 +08:00
|
|
|
|
2017-01-05 19:12:31 +08:00
|
|
|
work.update_column('work_status', 3)
|
|
|
|
# 匿评开启消息邮件通知,# 所有人
|
|
|
|
#send_message_anonymous_comment(homework_common, 2)
|
|
|
|
contest = work.contest
|
|
|
|
contest.contest_members.each do |m|
|
|
|
|
work.contest_messages << ContestMessage.new(:user_id => m.user_id, :contest_id => contest.id, :viewed => false, :status => 2)
|
|
|
|
end
|
|
|
|
|
|
|
|
#未限定评审人数
|
|
|
|
else
|
|
|
|
work.update_column('work_status', 3)
|
|
|
|
contest = work.contest
|
|
|
|
contest.contest_members.each do |m|
|
|
|
|
work.contest_messages << ContestMessage.new(:user_id => m.user_id, :contest_id => contest.id, :viewed => false, :status => 2)
|
|
|
|
end
|
|
|
|
end
|
2016-12-30 10:30:21 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Rails.logger.info("log--------------------------------contest_work_start_evaluation end")
|
|
|
|
puts "--------------------------------contest_work_start_evaluation end"
|
|
|
|
end
|
|
|
|
|
|
|
|
#自动关闭匿评的任务
|
|
|
|
task :end_evaluation => :environment do
|
|
|
|
works = Work.where(:online_evaluation => true, :work_status => 3)
|
|
|
|
homework_detail_manuals = WorkDetailManual.where(:evaluation_end => Date.today, :work_id => works.map{|work| work.id})
|
|
|
|
homework_detail_manuals.each do |homework_detail_manual|
|
|
|
|
work = homework_detail_manual.work
|
|
|
|
work.contestant_works.has_committed.each do |student_work|
|
|
|
|
student_work.save
|
|
|
|
end
|
|
|
|
|
|
|
|
work.update_column('work_status', 4)
|
|
|
|
# 匿评关闭消息通知 给所有人发
|
|
|
|
contest = work.contest
|
|
|
|
contest.contest_members.each do |m|
|
2016-12-30 17:25:44 +08:00
|
|
|
work.contest_messages << ContestMessage.new(:user_id => m.user_id, :contest_id => contest.id, :viewed => false, :status => 3)
|
2016-12-30 10:30:21 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|