You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
educoder/lib/tasks/homework_evaluation.rake

76 lines
3.4 KiB

6 years ago
#coding=utf-8
namespace :homework_evaluation do
desc "start and end evaluation"
def get_assigned_homeworks(student_works, n, index)
student_works += student_works
student_works[index + 1..index + n]
end
#自动开启匿评的任务
task :start_evaluation => :environment do
Rails.logger.info("log--------------------------------start_evaluation start")
puts "--------------------------------start_evaluation start"
6 years ago
homework_detail_manuals = HomeworkDetailManual.includes(homework_common: :course).where("evaluation_start <= '#{Time.now}' and
6 years ago
(homework_detail_manuals.comment_status < 3)")
homework_detail_manuals.each do |homework_detail_manual|
homework_common = homework_detail_manual.homework_common
if homework_common.anonymous_comment
if homework_common.homework_group_settings.where("end_time is null or end_time > '#{Time.now}'").count == 0
if homework_common.homework_type == "group"
student_works = homework_common.student_works.where("work_status != 0").group(:group_id)
else
student_works = homework_common.student_works.has_committed
end
6 years ago
if student_works.present? && student_works.length >= 2
HomeworkEvaluationCommentAssginJob.perform_later(homework_common.id)
6 years ago
homework_detail_manual.update_column('comment_status', 3)
else
#作业数小于2启动失败, 只给老师和助教发
extra = "作品数量低于两个,无法开启匿评"
end
else
extra = "存在尚未截止的分班,无法开启匿评"
end
HomeworkEvaluationStartNotifyJob.perform_later(homework_common.id, extra)
6 years ago
if extra.present?
homework_detail_manual.update_attributes(:evaluation_start => nil, :evaluation_end => nil, :absence_penalty => 0,
:evaluation_num => 0, :appeal_time => nil, :appeal_penalty => 0)
homework_common.update_attributes(:anonymous_comment => 0, :anonymous_appeal => 0)
end
end
end
Rails.logger.info("log--------------------------------start_evaluation end")
puts "--------------------------------start_evaluation end"
end
#自动关闭匿评的任务
task :end_evaluation => :environment do
6 years ago
homework_detail_manuals = HomeworkDetailManual.includes(:homework_common).where("evaluation_end <= '#{Time.now}' and homework_detail_manuals.comment_status = 3")
6 years ago
homework_detail_manuals.each do |homework_detail_manual|
homework_common = homework_detail_manual.homework_common
if homework_common.anonymous_comment #开启匿评状态才可关闭匿评
if homework_common.anonymous_appeal
homework_detail_manual.update_column('comment_status', 4)
# 申诉开启发送消息
HomeworkAnonymousAppealStartNotifyJob.perform_later(homework_common.id)
6 years ago
else
homework_detail_manual.update_column('comment_status', 5)
end
HomeworkAbsencePenaltyCalculationJob.perform_later(homework_common.id)
6 years ago
end
end
end
#自动关闭申诉的任务
task :end_appeal => :environment do
homework_detail_manuals = HomeworkDetailManual.where("appeal_time <= '#{Time.now}' and homework_detail_manuals.comment_status = 4")
homework_detail_manuals.update_all(:comment_status => 5)
end
end