|
|
|
@ -41,20 +41,21 @@ class ExercisePublishTask
|
|
|
|
|
puts "--------------------------------exercise_publish end"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def end
|
|
|
|
|
Rails.logger.info("log--------------------------------exercise_end start")
|
|
|
|
|
puts "--------------------------------exercise_end start"
|
|
|
|
|
# 1。统一设置的试卷
|
|
|
|
|
exercises = Exercise.includes(:exercise_users,:exercise_questions).where("exercise_status = 2 AND
|
|
|
|
|
unified_setting = true AND end_time <= ?",Time.now + 900)
|
|
|
|
|
exercises&.each do |exercise|
|
|
|
|
|
exercises = Exercise.includes(:exercise_questions).where("exercise_status = 2 AND end_time <= ?",Time.now + 900)
|
|
|
|
|
exercises.each do |exercise|
|
|
|
|
|
Rails.logger.info("end_exercise_id: #{exercise.id}")
|
|
|
|
|
exercise.update_attributes!('exercise_status', 3)
|
|
|
|
|
if exercise.unified_setting
|
|
|
|
|
ex_type = exercise.exercise_questions.pluck(:question_type).uniq
|
|
|
|
|
exercise.update_column('exercise_status', 3)
|
|
|
|
|
exercise.exercise_users&.each do |exercise_user|
|
|
|
|
|
exercise.exercise_users.where("commit_status = 0 and start_at is not null").each do |exercise_user|
|
|
|
|
|
begin
|
|
|
|
|
Rails.logger.info("true: user_id:#{exercise_user.user_id}--commit_status:#{exercise_user.commit_status}")
|
|
|
|
|
if (exercise_user&.commit_status == 0) && (exercise_user&.start_at.present?)
|
|
|
|
|
s_score = calculate_student_score(exercise, exercise_user.user)[:total_score]
|
|
|
|
|
s_score = calculate_student_score(exercise, exercise_user.user, exercise.end_time)[:total_score]
|
|
|
|
|
if ex_type.include?(4) #是否包含主观题
|
|
|
|
|
subjective_score = exercise_user.subjective_score
|
|
|
|
|
else
|
|
|
|
@ -68,45 +69,37 @@ class ExercisePublishTask
|
|
|
|
|
commit_option = {
|
|
|
|
|
:status => 1,
|
|
|
|
|
:commit_status => 1,
|
|
|
|
|
:end_at => Time.now,
|
|
|
|
|
:end_at => exercise.end_time,
|
|
|
|
|
:objective_score => s_score,
|
|
|
|
|
:score => total_score,
|
|
|
|
|
:subjective_score => subjective_score,
|
|
|
|
|
:commit_method => exercise_user&.commit_method.to_i > 0 ? exercise_user&.commit_method.to_i : 3
|
|
|
|
|
}
|
|
|
|
|
exercise_user.update_attributes(commit_option)
|
|
|
|
|
end
|
|
|
|
|
rescue Exception => e
|
|
|
|
|
Rails.logger.info("rescue errors ___________________________#{e}")
|
|
|
|
|
next
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 2.非统一的试卷
|
|
|
|
|
all_exercises = Exercise.includes(:exercise_group_settings,:exercise_users,:exercise_questions).where("unified_setting = false AND exercise_status = 2 AND end_time > ?",Time.now + 900)
|
|
|
|
|
exercise_ids = all_exercises.blank? ? "(-1)" : "(" + all_exercises.map(&:id).join(",") + ")"
|
|
|
|
|
ex_group_settings = ExerciseGroupSetting.where("end_time <= '#{Time.now}' and exercise_id in #{exercise_ids}")
|
|
|
|
|
ex_group_settings&.each do |exercise_setting|
|
|
|
|
|
ExerciseGroupSetting.where("end_time < ? and end_time > ?", Time.now + 900, Time.now - 900).each do |exercise_setting|
|
|
|
|
|
exercise = exercise_setting.exercise
|
|
|
|
|
if exercise.end_time <= Time.now
|
|
|
|
|
exercise.update_column('exercise_status', 3)
|
|
|
|
|
end
|
|
|
|
|
Rails.logger.info("exercise_group_setting: exercise_id:#{exercise.id}--group_settings_id:#{exercise_setting.id}")
|
|
|
|
|
|
|
|
|
|
users = exercise.course.course_members.where(:course_group_id => exercise_setting.course_group_id)
|
|
|
|
|
exercise_users = exercise.exercise_users.where(user_id: users.pluck(:user_id)).where("commit_status = 0 and start_at is not null")
|
|
|
|
|
ex_types = exercise.exercise_questions.pluck(:question_type).uniq
|
|
|
|
|
users = exercise.course.students.where(:course_group_id => exercise_setting.course_group_id)
|
|
|
|
|
exercise_users = exercise.exercise_users.where(:user_id => users.pluck(:user_id))
|
|
|
|
|
exercise_users&.each do |exercise_user|
|
|
|
|
|
begin
|
|
|
|
|
exercise_users.each do |exercise_user|
|
|
|
|
|
Rails.logger.info("false: user_id:#{exercise_user.user_id}--commit_status:#{exercise_user.commit_status}")
|
|
|
|
|
if exercise_user.commit_status == 0 && !exercise_user.start_at.nil?
|
|
|
|
|
begin
|
|
|
|
|
if ex_types.include?(4) #是否包含主观题
|
|
|
|
|
subjective_score = exercise_user.subjective_score
|
|
|
|
|
else
|
|
|
|
|
subjective_score = -1.0
|
|
|
|
|
end
|
|
|
|
|
s_score = calculate_student_score(exercise, exercise_user.user)[:total_score]
|
|
|
|
|
s_score = calculate_student_score(exercise, exercise_user.user, exercise_setting.end_time)[:total_score]
|
|
|
|
|
total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score
|
|
|
|
|
total_score = s_score + total_score_subjective_score
|
|
|
|
|
Rails.logger.info("false: user_id:#{exercise_user.user_id}--s_score:#{s_score}")
|
|
|
|
@ -115,23 +108,20 @@ class ExercisePublishTask
|
|
|
|
|
commit_option = {
|
|
|
|
|
:status => 1,
|
|
|
|
|
:commit_status => 1,
|
|
|
|
|
:end_at => Time.now,
|
|
|
|
|
:end_at => exercise_setting.end_time,
|
|
|
|
|
:objective_score => s_score,
|
|
|
|
|
:score => total_score,
|
|
|
|
|
:subjective_score => subjective_score,
|
|
|
|
|
:commit_method => exercise_user&.commit_method.to_i > 0 ? exercise_user&.commit_method.to_i : 3
|
|
|
|
|
}
|
|
|
|
|
exercise_user.update_attributes(commit_option)
|
|
|
|
|
end
|
|
|
|
|
rescue Exception => e
|
|
|
|
|
Rails.logger.info("unified_setting_false_rescue errors ___________________________#{e}")
|
|
|
|
|
next
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
Rails.logger.info("log--------------------------------exercise_end end")
|
|
|
|
|
puts "--------------------------------exercise_end end"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|