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/app/jobs/end_exercise_calculate_job.rb

35 lines
1.2 KiB

class EndExerciseCalculateJob < ApplicationJob
include ExercisesHelper
include GitHelper
queue_as :default
def perform(ex_user_ids,exercise_id,end_time,work_time,commit_method)
exercise = Exercise.find_by(id: exercise_id)
return if exercise.blank?
exercise_users = ExerciseUser.where(id: ex_user_ids)
exercise_users.each do |user|
if user.commit_status == 0 && user.start_at.present?
end_at = work_time ? end_time : Time.at(user.start_at + exercise.time * 60)
objective_score = calculate_student_score(exercise,user.user,end_time.to_time)[:total_score]
user_sub_score = user.subjective_score
subjective_score = user_sub_score < 0.0 ? 0.0 : user_sub_score
total_score = objective_score + subjective_score
commit_option = {
:status => 1,
:commit_status => 1,
:end_at => end_at,
:objective_score => objective_score,
:score => total_score,
:subjective_score => user_sub_score,
:commit_method => user&.commit_method.to_i > 0 ? user&.commit_method.to_i : commit_method
}
user.update_attributes(commit_option)
end
end
end
end