|
|
|
@ -255,29 +255,7 @@ class HomeworkCommonsController < ApplicationController
|
|
|
|
|
def update_score
|
|
|
|
|
tip_exception("作业还未发布,暂不能计算成绩") if @homework.publish_time.nil? || @homework.publish_time > Time.now
|
|
|
|
|
begin
|
|
|
|
|
if @homework.unified_setting
|
|
|
|
|
student_works = @homework.student_works
|
|
|
|
|
user_ids = @course.students.pluck(:user_id)
|
|
|
|
|
else
|
|
|
|
|
user_ids = @course.students.where(course_group_id: @homework.published_settings.pluck(:course_group_id)).pluck(:user_id)
|
|
|
|
|
student_works = @homework.student_works.where(user_id: user_ids)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
student_works = student_works.includes(:challenge_work_scores)
|
|
|
|
|
|
|
|
|
|
challenge_settings = @homework.homework_challenge_settings
|
|
|
|
|
challenge_setting_ids = challenge_settings.pluck(:challenge_id)
|
|
|
|
|
myshixuns = Myshixun.where(shixun_id: @homework.homework_commons_shixun&.shixun_id, user_id: user_ids).includes(:games)
|
|
|
|
|
myshixuns.find_each(batch_size: 100) do |myshixun|
|
|
|
|
|
work = student_works.select{|work| work.user_id == myshixun.user_id}.first
|
|
|
|
|
if work && myshixun
|
|
|
|
|
games = myshixun.games.select{|game| challenge_setting_ids.include?(game.challenge_id)}
|
|
|
|
|
HomeworksService.new.update_myshixun_work_score work, myshixun, games, @homework, challenge_settings
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
HomeworksService.new.update_student_eff_score @homework if (@homework.allow_late && @homework.late_time < Time.now) ||
|
|
|
|
|
(!@homework.allow_late && @homework.end_time < Time.now)
|
|
|
|
|
@homework.update_attribute('calculation_time', Time.now)
|
|
|
|
|
@homework.update_homework_work_score
|
|
|
|
|
normal_status("更新成功")
|
|
|
|
|
rescue Exception => e
|
|
|
|
|
uid_logger(e.message)
|
|
|
|
|