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.
21 lines
915 B
21 lines
915 B
class AddExerciseUserUpdate < ActiveRecord::Migration[5.2]
|
|
include ExercisesHelper
|
|
def change
|
|
#2019,8,22添加
|
|
exs = Exercise.all.is_exercise_published.where("publish_time > ?",(Time.now - 2.months)).includes(:exercise_questions,:exercise_users)
|
|
exs.each do |ex|
|
|
ex_users = ex.exercise_users.exercise_user_committed.where("end_at is not null and end_at > ?",(Time.now - 2.months))
|
|
if ex_users.present?
|
|
ex_users.each do |ex_user|
|
|
calculate_score = calculate_student_score(ex,ex_user.user)[:total_score]
|
|
subjective_score = ex_user.subjective_score
|
|
total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score
|
|
total_score = calculate_score + total_score_subjective_score
|
|
ex_user.update_attributes(score:total_score,objective_score:calculate_score)
|
|
puts ex_user.id
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|