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

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#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"
homework_detail_manuals = HomeworkDetailManual.includes(homework_common: :course).where("evaluation_start <= '#{Time.now}' and
(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
if student_works.size >= 2
HomeworkEvaluationCommentAssginJob.perform_later(homework_common.id)
homework_detail_manual.update_column('comment_status', 3)
else
#作业数小于2启动失败, 只给老师和助教发
extra = "作品数量低于两个,无法开启匿评"
end
else
extra = "存在尚未截止的分班,无法开启匿评"
end
HomeworkEvaluationStartNotifyJob.perform_later(homework_common.id, extra)
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
homework_detail_manuals = HomeworkDetailManual.includes(:homework_common).where("evaluation_end <= '#{Time.now}' and 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.anonymous_appeal
homework_detail_manual.update_column('comment_status', 4)
# 申诉开启发送消息
HomeworkAnonymousAppealStartNotifyJob.perform_later(homework_common.id)
else
homework_detail_manual.update_column('comment_status', 5)
end
HomeworkAbsencePenaltyCalculationJob.perform_later(homework_common.id)
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