修改试卷的实训题分数计算

dev_forum
SylorHuang 6 years ago
commit b40c8fd1d1

@ -539,16 +539,21 @@ class ShixunsController < ApplicationController
# 其它创建关卡等操作
challenges = @shixun.challenges
# 之所以增加user_id是为了方便统计查询性能
game_attrs = %i[challenge_id myshixun_id status user_id open_time identifier modify_time created_at updated_at]
Game.bulk_insert(*game_attrs) do |worker|
base_attr = { myshixun_id: myshixun.id, user_id: myshixun.user_id }
challenges.each_with_index do |challenge, index|
status = (index == 0 ? 0 : 3)
game_identifier = generate_identifier(Game, 12)
Game.create!(:challenge_id => challenge.id, :myshixun_id => myshixun.id, :status => status, :user_id => myshixun.user_id,
:open_time => Time.now, :identifier => game_identifier, :modify_time => challenge.modify_time)
worker.add(base_attr.merge(challenge_id: challenge.id, status: status, open_time: Time.now,
identifier: game_identifier, modify_time: challenge.modify_time))
end
end
# REDO:开启实训时更新关联作品的状态
# TODO:这个可以异步。或者放到课程里面取,不要在开启实训这边做
HomeworksService.new.update_myshixun_work_status myshixun
# HomeworksService.new.update_myshixun_work_status myshixun
UpdateMyshixunWorkStatusJob.perform_later(myshixun.id)
@current_task = myshixun.current_task
uid_logger("## shixun exec: myshixun id is #{myshixun.id}")
@ -559,9 +564,6 @@ class ShixunsController < ApplicationController
end
end
end
end
# gameID 及实训ID
# status: 0 , 1 申请过, 2实训关卡路径未填 3 实训标签未填, 4 实训未创建关卡

@ -421,8 +421,10 @@ module ExercisesHelper
if game.present?
exercise_cha_score = 0.0
answer_status = 0
if game.status == 2 && game.final_score >= 0
exercise_cha_score = exercise_cha.question_score #每一关卡的得分
# if game.status == 2 && game.final_score >= 0
if game.final_score > 0
exercise_cha_score = game.real_score(exercise_cha.question_score)
# exercise_cha_score = exercise_cha.question_score #每一关卡的得分
answer_status = 1
end
ex_shixun_answer_content = answers_content&.where(exercise_shixun_challenge_id: exercise_cha.id)
@ -439,7 +441,7 @@ module ExercisesHelper
:exercise_question_id => q.id,
:exercise_shixun_challenge_id => exercise_cha.id,
:user_id => user.id,
:score => exercise_cha_score,
:score => exercise_cha_score.round(1),
:answer_text => code,
:status => answer_status
}

@ -0,0 +1,10 @@
class UpdateMyshixunWorkStatusJob < ApplicationJob
queue_as :default
def perform(myshixun_id)
myshixun = Myshixun.find_by(id: myshixun_id)
return if myshixun.blank?
HomeworksService.new.update_myshixun_work_status myshixun
end
end
Loading…
Cancel
Save