|
|
|
@ -67,41 +67,75 @@ class ExercisePublishTask
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def end
|
|
|
|
|
exercises = Exercise.where("end_time <=? and exercise_status = 2",Time.now)
|
|
|
|
|
exercises = Exercise.where("end_time <= ? and exercise_status = ?",Time.now,2)
|
|
|
|
|
exercises.each do |exercise|
|
|
|
|
|
course = exercise.course
|
|
|
|
|
exercise.update_column('exercise_status', 3)
|
|
|
|
|
|
|
|
|
|
ex_type = exercise.exercise_questions.pluck(:question_type).uniq
|
|
|
|
|
exercise.update_attribute('exercise_status', 3)
|
|
|
|
|
exercise.exercise_users.each do |exercise_user|
|
|
|
|
|
if exercise_user.commit_status == 0 && !exercise_user.start_at.nil?
|
|
|
|
|
exercise_user.update_attributes(:commit_status => 1, :end_at => Time.now, :status => true)
|
|
|
|
|
|
|
|
|
|
# exercise_user.update_attributes(:commit_status => 1, :end_at => Time.now, :status => true)
|
|
|
|
|
s_score = calculate_student_score(exercise, exercise_user.user)[:total_score]
|
|
|
|
|
exercise_user.update_attributes(:objective_score => s_score, :score => (s_score + (exercise_user.subjective_score && exercise_user.subjective_score > 0 ? exercise_user.subjective_score : 0)))
|
|
|
|
|
if exercise_user.user.exercise_answers.where(:exercise_question_id => exercise.exercise_questions.where(:question_type => 4).map(&:id)).empty?
|
|
|
|
|
exercise_user.update_attributes(:subjective_score => 0)
|
|
|
|
|
end
|
|
|
|
|
if ex_type.include?(4) #是否包含主观题
|
|
|
|
|
subjective_score = exercise_user.subjective_score
|
|
|
|
|
else
|
|
|
|
|
subjective_score = -1.0
|
|
|
|
|
end
|
|
|
|
|
# subjective_score = exercise_user.subjective_score
|
|
|
|
|
total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score
|
|
|
|
|
total_score = s_score + total_score_subjective_score
|
|
|
|
|
commit_option = {
|
|
|
|
|
:status => 1,
|
|
|
|
|
:commit_status => 1,
|
|
|
|
|
:end_at => Time.now,
|
|
|
|
|
:objective_score => s_score,
|
|
|
|
|
:score => total_score,
|
|
|
|
|
:subjective_score => subjective_score
|
|
|
|
|
}
|
|
|
|
|
exercise_user.update_attributes(commit_option)
|
|
|
|
|
# if exercise_user.user.exercise_answers.where(:exercise_question_id => exercise.exercise_questions.where(:question_type => 4).map(&:id)).empty?
|
|
|
|
|
# exercise_user.update_attributes(:subjective_score => 0)
|
|
|
|
|
# end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
all_exercises = Exercise.where("end_time > ? and exercise_status = 2",Time.now)
|
|
|
|
|
all_exercises = Exercise.where("end_time > ? and exercise_status = ?",Time.now,2)
|
|
|
|
|
exercise_ids = all_exercises.blank? ? "(-1)" : "(" + all_exercises.map(&:id).join(",") + ")"
|
|
|
|
|
ExerciseGroupSetting.where("end_time <= '#{Time.now}' and exercise_id in #{exercise_ids}").each do |exercise_setting|
|
|
|
|
|
ex_group_settings = ExerciseGroupSetting.where("end_time <= '#{Time.now}' and exercise_id in #{exercise_ids}")
|
|
|
|
|
ex_group_settings.each do |exercise_setting|
|
|
|
|
|
exercise = exercise_setting.exercise
|
|
|
|
|
|
|
|
|
|
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.map(&:user_id))
|
|
|
|
|
|
|
|
|
|
exercise_users.each do |exercise_user|
|
|
|
|
|
if exercise_user.commit_status == 0 && !exercise_user.start_at.nil?
|
|
|
|
|
exercise_user.update_attributes(:commit_status => 1, :end_at => Time.now, :status => true)
|
|
|
|
|
|
|
|
|
|
s_score = calculate_student_score(exercise, exercise_user.user)[:total_score]
|
|
|
|
|
exercise_user.update_attributes(:objective_score => s_score, :score => (s_score + (exercise_user.subjective_score && exercise_user.subjective_score > 0 ? exercise_user.subjective_score : 0)))
|
|
|
|
|
if exercise_user.user.exercise_answers.where(:exercise_question_id => exercise.exercise_questions.where(:question_type => 4).map(&:id)).empty?
|
|
|
|
|
exercise_user.update_attributes(:subjective_score => 0)
|
|
|
|
|
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]
|
|
|
|
|
# subjective_score = exercise_user.subjective_score
|
|
|
|
|
total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score
|
|
|
|
|
total_score = s_score + total_score_subjective_score
|
|
|
|
|
commit_option = {
|
|
|
|
|
:status => 1,
|
|
|
|
|
:commit_status => 1,
|
|
|
|
|
:end_at => Time.now,
|
|
|
|
|
:objective_score => s_score,
|
|
|
|
|
:score => total_score,
|
|
|
|
|
:subjective_score => subjective_score
|
|
|
|
|
}
|
|
|
|
|
exercise_user.update_attributes(commit_option)
|
|
|
|
|
# exercise_user.update_attributes(:commit_status => 1, :end_at => Time.now, :status => true)
|
|
|
|
|
|
|
|
|
|
# s_score = calculate_student_score(exercise, exercise_user.user)[:total_score]
|
|
|
|
|
# exercise_user.update_attributes(:objective_score => s_score, :score => (s_score + (exercise_user.subjective_score && exercise_user.subjective_score > 0 ? exercise_user.subjective_score : 0)))
|
|
|
|
|
# if exercise_user.user.exercise_answers.where(:exercise_question_id => exercise.exercise_questions.where(:question_type => 4).map(&:id)).empty?
|
|
|
|
|
# exercise_user.update_attributes(:subjective_score => 0.0)
|
|
|
|
|
# end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|