导出成绩实时计算实训作业成绩

dev_hjm
cxt 6 years ago
parent 97e0f411da
commit b6df2233f4

@ -1154,6 +1154,12 @@ class CoursesController < ApplicationController
#课堂的作业信息
shixun_homeworks = homeworks.search_homework_type(4) #全部实训作业
shixun_titles = shixun_homeworks.pluck(:name) + ["总得分"]
# 更新实训作业成绩
shixun_homeworks.includes(:homework_challenge_settings, :published_settings, :homework_commons_shixun).each do |homework|
homework.update_homework_work_score
end
shixun_homeworks = shixun_homeworks&.includes(score_student_works: :user)
common_homeworks = homeworks.search_homework_type(1) #全部普通作业

@ -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)

@ -264,4 +264,30 @@ class HomeworkCommon < ApplicationRecord
def challenge_score challenge_id
homework_challenge_settings.find_by(challenge_id: challenge_id)&.score.to_f
end
def update_homework_work_score
if unified_setting
works = student_works
user_ids = course.students.pluck(:user_id)
else
user_ids = course.students.where(course_group_id: published_settings.pluck(:course_group_id)).pluck(:user_id)
works = student_works.where(user_id: user_ids)
end
works = works.includes(:challenge_work_scores)
challenge_settings = homework_challenge_settings
challenge_setting_ids = challenge_settings.pluck(:challenge_id)
myshixuns = Myshixun.where(shixun_id: homework_commons_shixun&.shixun_id, user_id: user_ids).includes(:games)
myshixuns.find_each(batch_size: 100) do |myshixun|
work = 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, self, challenge_settings
end
end
HomeworksService.new.update_student_eff_score(self) if (allow_late && late_time < Time.now) ||
(!allow_late && end_time < Time.now)
update_attribute('calculation_time', Time.now)
end
end

@ -123,10 +123,10 @@ class StudentWork < ApplicationRecord
# 更新作品成绩
def set_work_score
if work_status > 0 && homework_common && homework_common.homework_detail_manual && !self.ultimate_score
if work_status > 0 && homework_common && !self.ultimate_score
case homework_common.homework_type
when "normal", "group"
if !homework_common.homework_detail_manual.final_mode
if !homework_common&.homework_detail_manual&.final_mode
tea_ass_proportion = homework_common.homework_detail_manual.ta_proportion
tea_proportion = homework_common.homework_detail_manual.te_proportion
if self.teacher_score

Loading…
Cancel
Save