114 lines
5.8 KiB
Ruby
114 lines
5.8 KiB
Ruby
#coding=utf-8
|
|
|
|
namespace :homework_publishtime do
|
|
desc "start publish homework and end homework"
|
|
def had_passed_changllenge_num_rake myshixun
|
|
if myshixun.nil?
|
|
0
|
|
else
|
|
myshixun.games.select{|game| game.status == 2}.count
|
|
end
|
|
end
|
|
|
|
def had_passed_no_ans_changllenge_num_rake myshixun
|
|
if myshixun.nil?
|
|
0
|
|
else
|
|
myshixun.games.select{|game| game.status == 2 && !game.answer_open}.count
|
|
end
|
|
end
|
|
|
|
task :publish => :environment do
|
|
Rails.logger.info("log--------------------------------homework_publish start")
|
|
homework_commons = HomeworkCommon.includes(:homework_detail_manual).where("publish_time <= '#{Time.now}' and homework_detail_manuals.comment_status = 0")
|
|
homework_commons.each do |homework|
|
|
homework_detail_manual = homework.homework_detail_manual
|
|
homework_detail_manual.update_column('comment_status', 1)
|
|
students = homework.course.student
|
|
if !homework.course.nil? && !students.empty?
|
|
name = homework.name
|
|
name_str = name + "的作品提交"
|
|
str = ""
|
|
if homework.homework_type == 4
|
|
students.each do |student|
|
|
if str != ""
|
|
str += ","
|
|
end
|
|
myshixun = Myshixun.where(:shixun_id => homework.homework_commons_shixuns.shixun_id, :user_id => student.student_id).first
|
|
if myshixun
|
|
str += "('#{name_str}',#{homework.id},#{student.student_id}, 1, #{myshixun.id}, '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')"
|
|
else
|
|
str += "('#{name_str}',#{homework.id},#{student.student_id}, 0, null, null, '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')"
|
|
end
|
|
end
|
|
sql = "insert into student_works (name, homework_common_id, user_id, work_status, myshixun_id, commit_time, created_at, updated_at) values" + str
|
|
else
|
|
students.each do |student|
|
|
if str != ""
|
|
str += ","
|
|
end
|
|
str += "('#{name_str}',#{homework.id},#{student.student_id}, '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')"
|
|
end
|
|
sql = "insert into student_works (name, homework_common_id, user_id, created_at, updated_at) values" + str
|
|
end
|
|
|
|
ActiveRecord::Base.connection.execute sql
|
|
end
|
|
|
|
#更新CourseHomeworkStatistics中每个学生的未交作品数
|
|
# homework.course.student.each do |student|
|
|
# course_statistics = CourseHomeworkStatistics.find_by_course_id_and_user_id(homework.course_id, student.student_id)
|
|
# course_statistics.update_attribute('un_commit_work_num', course_statistics.un_commit_work_num + 1) if course_statistics
|
|
# end
|
|
|
|
course = homework.course
|
|
course.members.each do |m|
|
|
homework.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => nil)
|
|
end
|
|
if homework.course_acts.size == 0
|
|
homework.course_acts << CourseActivity.new(:user_id => homework.user_id,:course_id => homework.course_id)
|
|
end
|
|
# 邮件通知
|
|
# Mailer.run.homework_added(homework)
|
|
end
|
|
Rails.logger.info("log--------------------------------homework_publish end")
|
|
end
|
|
|
|
task :end => :environment do
|
|
Rails.logger.info("log--------------------------------homework_publish_end start")
|
|
homework_commons = HomeworkCommon.includes(:homework_detail_manual).where("homework_type = 4 and end_time <= '#{Time.now}' and homework_detail_manuals.comment_status = 1")
|
|
homework_commons.each do |homework|
|
|
homework.homework_detail_manual.update_column("comment_status", 2)
|
|
shixun = homework.homework_commons_shixuns.shixun
|
|
homework.student_works.where("work_status != 0").each do |student_work|
|
|
passed_count = homework.homework_detail_manual.answer_open_evaluation ? had_passed_changllenge_num_rake(student_work.myshixun) : had_passed_no_ans_changllenge_num_rake(student_work.myshixun)
|
|
final_score =(passed_count.to_f / shixun.challenges.count) * 100
|
|
student_work.update_column("final_score", format("%.2f",final_score.to_f))
|
|
score = final_score - student_work.late_penalty
|
|
student_work.update_column("work_score", format("%.2f",(score < 0 ? 0 : score).to_f))
|
|
end
|
|
end
|
|
Rails.logger.info("log--------------------------------homework_publish_end end")
|
|
end
|
|
|
|
task :archive => :environment do
|
|
Rails.logger.info("log--------------------------------homework_archive start")
|
|
homework_commons = HomeworkCommon.includes(:homework_detail_manual).where("archive_time <= '#{Time.now}' and homework_detail_manuals.comment_status != 6")
|
|
homework_commons.each do |homework|
|
|
homework_detail_manual = homework.homework_detail_manual
|
|
homework_detail_manual.update_column('comment_status', 6)
|
|
if homework.homework_type == 4 && homework.allow_late
|
|
shixun = homework.homework_commons_shixuns.shixun
|
|
homework.student_works.where("work_status != 0").each do |student_work|
|
|
passed_count = homework.homework_detail_manual.answer_open_evaluation ? had_passed_changllenge_num_rake(student_work.myshixun) : had_passed_no_ans_changllenge_num_rake(student_work.myshixun)
|
|
final_score =(passed_count.to_f / shixun.challenges.count) * 100
|
|
student_work.update_column("final_score", format("%.2f",final_score.to_f))
|
|
score = student_work.final_score - student_work.late_penalty
|
|
student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score
|
|
student_work.update_column("work_score", format("%.2f",(score < 0 ? 0 : score).to_f))
|
|
end
|
|
end
|
|
end
|
|
Rails.logger.info("log--------------------------------homework_archive end")
|
|
end
|
|
end |