|
|
@ -353,121 +353,127 @@ module ExercisesHelper
|
|
|
|
score5 = 0.0 #实训题
|
|
|
|
score5 = 0.0 #实训题
|
|
|
|
ques_stand = [] #问题是否正确
|
|
|
|
ques_stand = [] #问题是否正确
|
|
|
|
exercise_questions = exercise.exercise_questions.includes(:exercise_answers,:exercise_shixun_answers,:exercise_standard_answers,:exercise_shixun_challenges)
|
|
|
|
exercise_questions = exercise.exercise_questions.includes(:exercise_answers,:exercise_shixun_answers,:exercise_standard_answers,:exercise_shixun_challenges)
|
|
|
|
exercise_questions.each do |q|
|
|
|
|
exercise_questions&.each do |q|
|
|
|
|
if q.question_type != 5
|
|
|
|
begin
|
|
|
|
answers_content = q.exercise_answers.search_answer_users("user_id",user.id) #学生的答案
|
|
|
|
if q.question_type != 5
|
|
|
|
else
|
|
|
|
answers_content = q.exercise_answers.where(user_id: user.id) #学生的答案
|
|
|
|
answers_content = q.exercise_shixun_answers.search_shixun_answers("user_id",user.id) #学生的答案
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
if q.question_type <= 2 #为选择题或判断题时
|
|
|
|
|
|
|
|
if answers_content.present? #学生有回答时
|
|
|
|
|
|
|
|
answer_choice_array = []
|
|
|
|
|
|
|
|
answers_content.each do |a|
|
|
|
|
|
|
|
|
answer_choice_array.push(a.exercise_choice.choice_position) #学生答案的位置
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
user_answer_content = answer_choice_array.sort
|
|
|
|
|
|
|
|
standard_answer = q.exercise_standard_answers.pluck(:exercise_choice_id).sort #该问题的标准答案,可能有多个
|
|
|
|
|
|
|
|
if user_answer_content == standard_answer #答案一致,多选或单选才给分,答案不对不给分
|
|
|
|
|
|
|
|
if standard_answer.count > 0
|
|
|
|
|
|
|
|
q_score_1 = (q.question_score / standard_answer.count) #当多选答案正确时,每个answer的分数均摊。
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
q_score_1 = 0.0
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
answers_content.update_all(:score => q_score_1)
|
|
|
|
|
|
|
|
score1 = score1 + q.question_score
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
else
|
|
|
|
else
|
|
|
|
score1 += 0.0
|
|
|
|
answers_content = q.exercise_shixun_answers.where(user_id: user.id) #学生的答案
|
|
|
|
end
|
|
|
|
end
|
|
|
|
elsif q.question_type == 3 #填空题
|
|
|
|
if q.question_type <= 2 #为选择题或判断题时
|
|
|
|
if answers_content.present?
|
|
|
|
if answers_content.present? #学生有回答时
|
|
|
|
null_standard_answer = q.exercise_standard_answers
|
|
|
|
answer_choice_array = []
|
|
|
|
standard_answer_array = null_standard_answer.select(:exercise_choice_id,:answer_text)
|
|
|
|
answers_content.each do |a|
|
|
|
|
standard_answer_ids = standard_answer_array.pluck(:exercise_choice_id).reject(&:blank?).uniq #标准答案的exercise_choice_id数组
|
|
|
|
answer_choice_array.push(a.exercise_choice.choice_position) #学生答案的位置
|
|
|
|
standard_answer_count = standard_answer_ids.count
|
|
|
|
end
|
|
|
|
if standard_answer_count > 0 #存在标准答案时才有分数
|
|
|
|
user_answer_content = answer_choice_array.sort
|
|
|
|
q_score_2 = (q.question_score.to_f / standard_answer_count) #每一空的得分
|
|
|
|
standard_answer = q.exercise_standard_answers.pluck(:exercise_choice_id).sort #该问题的标准答案,可能有多个
|
|
|
|
else
|
|
|
|
if user_answer_content == standard_answer #答案一致,多选或单选才给分,答案不对不给分
|
|
|
|
q_score_2 = 0.0
|
|
|
|
if standard_answer.count > 0
|
|
|
|
end
|
|
|
|
q_score_1 = (q.question_score.to_f / standard_answer.count) #当多选答案正确时,每个answer的分数均摊。
|
|
|
|
if q.is_ordered
|
|
|
|
else
|
|
|
|
answers_content.each do |u|
|
|
|
|
q_score_1 = 0.0
|
|
|
|
i_standard_answer = standard_answer_array.where(exercise_choice_id:u.exercise_choice_id).pluck(:answer_text).reject(&:blank?).map!(&:downcase) #该选项的全部标准答案
|
|
|
|
|
|
|
|
if i_standard_answer.include?(u.answer_text.downcase) #该空的标准答案包含用户的答案才有分数
|
|
|
|
|
|
|
|
u.update_column('score',q_score_2)
|
|
|
|
|
|
|
|
score2 = score2 + q_score_2
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
answers_content.update_all(:score => q_score_1)
|
|
|
|
|
|
|
|
score1 = score1 + q.question_score
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
else
|
|
|
|
st_answer_text = standard_answer_array.pluck(:answer_text).reject(&:blank?).map!(&:downcase)
|
|
|
|
score1 += 0.0
|
|
|
|
answers_content.each do |u|
|
|
|
|
end
|
|
|
|
u_answer_text = u.answer_text.downcase
|
|
|
|
elsif q.question_type == 3 #填空题
|
|
|
|
if st_answer_text.include?(u_answer_text) #只要标准答案包含用户的答案,就有分数。同时,下一次循环时,就会删除该标准答案。防止用户的相同答案获分
|
|
|
|
if answers_content.present?
|
|
|
|
u.update_column("score",q_score_2)
|
|
|
|
null_standard_answer = q.exercise_standard_answers
|
|
|
|
score2 = score2 + q_score_2
|
|
|
|
standard_answer_array = null_standard_answer.select(:exercise_choice_id,:answer_text)
|
|
|
|
st_answer_text.delete(u_answer_text)
|
|
|
|
standard_answer_ids = standard_answer_array.pluck(:exercise_choice_id).reject(&:blank?).uniq #标准答案的exercise_choice_id数组
|
|
|
|
|
|
|
|
standard_answer_count = standard_answer_ids.count
|
|
|
|
|
|
|
|
if standard_answer_count > 0 #存在标准答案时才有分数
|
|
|
|
|
|
|
|
q_score_2 = (q.question_score.to_f / standard_answer_count) #每一空的得分
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
q_score_2 = 0.0
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
if q.is_ordered
|
|
|
|
|
|
|
|
answers_content.each do |u|
|
|
|
|
|
|
|
|
i_standard_answer = standard_answer_array.where(exercise_choice_id:u.exercise_choice_id).pluck(:answer_text).reject(&:blank?).map!(&:downcase) #该选项的全部标准答案
|
|
|
|
|
|
|
|
if i_standard_answer.include?(u.answer_text.downcase) #该空的标准答案包含用户的答案才有分数
|
|
|
|
|
|
|
|
u.update_column('score',q_score_2)
|
|
|
|
|
|
|
|
score2 = score2 + q_score_2
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
st_answer_text = standard_answer_array.pluck(:answer_text).reject(&:blank?).map!(&:downcase)
|
|
|
|
|
|
|
|
answers_content.each do |u|
|
|
|
|
|
|
|
|
u_answer_text = u.answer_text.downcase
|
|
|
|
|
|
|
|
if st_answer_text.include?(u_answer_text) #只要标准答案包含用户的答案,就有分数。同时,下一次循环时,就会删除该标准答案。防止用户的相同答案获分
|
|
|
|
|
|
|
|
u.update_column("score",q_score_2)
|
|
|
|
|
|
|
|
score2 = score2 + q_score_2
|
|
|
|
|
|
|
|
st_answer_text.delete(u_answer_text)
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
score2 += 0.0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
elsif q.question_type == 5 #实训题时,主观题这里不评分
|
|
|
|
score2 += 0.0
|
|
|
|
q.exercise_shixun_challenges&.each do |exercise_cha|
|
|
|
|
end
|
|
|
|
game = Game.user_games(user.id,exercise_cha.challenge_id)&.first #当前用户的关卡
|
|
|
|
elsif q.question_type == 5 #实训题时,主观题这里不评分
|
|
|
|
if game.present?
|
|
|
|
q.exercise_shixun_challenges.each do |exercise_cha|
|
|
|
|
exercise_cha_score = 0.0
|
|
|
|
game = Game.user_games(user.id,exercise_cha.challenge_id)&.first #当前用户的关卡
|
|
|
|
answer_status = 0
|
|
|
|
if game.present?
|
|
|
|
if game.status == 2 && game.final_score >= 0
|
|
|
|
exercise_cha_score = 0.0
|
|
|
|
exercise_cha_score = exercise_cha.question_score #每一关卡的得分
|
|
|
|
answer_status = 0
|
|
|
|
answer_status = 1
|
|
|
|
if game.status == 2 && game.final_score >= 0
|
|
|
|
end
|
|
|
|
exercise_cha_score = exercise_cha.question_score #每一关卡的得分
|
|
|
|
ex_shixun_answer_content = answers_content&.where(exercise_shixun_challenge_id: exercise_cha.id)
|
|
|
|
answer_status = 1
|
|
|
|
if ex_shixun_answer_content.blank? #把关卡的答案存入试卷的实训里
|
|
|
|
end
|
|
|
|
cha_path = challenge_path(exercise_cha.challenge&.path)
|
|
|
|
ex_shixun_answer_content = answers_content&.where(exercise_shixun_challenge_id: exercise_cha.id)
|
|
|
|
game_challenge = game.game_codes.search_challenge_path(cha_path)&.first
|
|
|
|
if ex_shixun_answer_content.blank? #把关卡的答案存入试卷的实训里
|
|
|
|
if game_challenge.present?
|
|
|
|
cha_path = challenge_path exercise_cha.challenge&.path
|
|
|
|
game_code = game_challenge
|
|
|
|
game_challenge = game.game_codes.search_challenge_path(cha_path)&.first
|
|
|
|
code = game_code.try(:new_code)
|
|
|
|
if game_challenge.present?
|
|
|
|
else
|
|
|
|
game_code = game_challenge
|
|
|
|
code = git_fle_content(exercise_cha.shixun&.repo_path,cha_path)
|
|
|
|
code = game_code.try(:new_code)
|
|
|
|
end
|
|
|
|
|
|
|
|
sx_option = {
|
|
|
|
|
|
|
|
:exercise_question_id => q.id,
|
|
|
|
|
|
|
|
:exercise_shixun_challenge_id => exercise_cha.id,
|
|
|
|
|
|
|
|
:user_id => user.id,
|
|
|
|
|
|
|
|
:score => exercise_cha_score,
|
|
|
|
|
|
|
|
:answer_text => code,
|
|
|
|
|
|
|
|
:status => answer_status
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ExerciseShixunAnswer.create(sx_option)
|
|
|
|
else
|
|
|
|
else
|
|
|
|
code = git_fle_content(exercise_cha.shixun&.repo_path,cha_path)
|
|
|
|
ex_shixun_answer_content.first.update_column('score',exercise_cha_score)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
sx_option = {
|
|
|
|
score5 += exercise_cha_score
|
|
|
|
:exercise_question_id => q.id,
|
|
|
|
|
|
|
|
:exercise_shixun_challenge_id => exercise_cha.id,
|
|
|
|
|
|
|
|
:user_id => user.id,
|
|
|
|
|
|
|
|
:score => exercise_cha_score,
|
|
|
|
|
|
|
|
:answer_text => code,
|
|
|
|
|
|
|
|
:status => answer_status
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ExerciseShixunAnswer.create(sx_option)
|
|
|
|
|
|
|
|
else
|
|
|
|
else
|
|
|
|
ex_shixun_answer_content.first.update_column('score',exercise_cha_score)
|
|
|
|
score5 += 0.0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
score5 += exercise_cha_score
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
score5 += 0.0
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
user_scores = answers_content.blank? ? 0.0 : answers_content.score_reviewed.pluck(:score).sum
|
|
|
|
|
|
|
|
if user_scores > 0.0
|
|
|
|
|
|
|
|
stand_answer = 1
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
stand_answer = 0
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
ques_option = {
|
|
|
|
|
|
|
|
"q_id":q.id, #该问题的id
|
|
|
|
|
|
|
|
"q_type":q.question_type,
|
|
|
|
|
|
|
|
"q_position":q.question_number, #该问题的位置
|
|
|
|
|
|
|
|
"stand_status":stand_answer, #该问题是否正确,1为正确,0为错误
|
|
|
|
|
|
|
|
"user_score":user_scores.round(1) #每个问题的总得分
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ques_stand.push(ques_option)
|
|
|
|
|
|
|
|
rescue Exception => e
|
|
|
|
|
|
|
|
Rails.logger.info("calcuclate_score_have_error____________________________#{e}")
|
|
|
|
|
|
|
|
next
|
|
|
|
end
|
|
|
|
end
|
|
|
|
user_scores = answers_content.present? ? answers_content.score_reviewed.pluck(:score).sum : 0.0
|
|
|
|
|
|
|
|
if user_scores > 0.0
|
|
|
|
|
|
|
|
stand_answer = 1
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
stand_answer = 0
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
ques_option = {
|
|
|
|
|
|
|
|
"q_id":q.id, #该问题的id
|
|
|
|
|
|
|
|
"q_type":q.question_type,
|
|
|
|
|
|
|
|
"q_position":q.question_number, #该问题的位置
|
|
|
|
|
|
|
|
"stand_status":stand_answer, #该问题是否正确,1为正确,0为错误
|
|
|
|
|
|
|
|
"user_score":user_scores #每个问题的总得分
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ques_stand.push(ques_option)
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
total_score = score1 + score2 + score5
|
|
|
|
total_score = score1 + score2 + score5
|
|
|
|
{
|
|
|
|
{
|
|
|
|
"total_score":total_score,
|
|
|
|
"total_score":total_score.round(1),
|
|
|
|
"stand_status":ques_stand
|
|
|
|
"stand_status":ques_stand
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -687,7 +693,7 @@ module ExercisesHelper
|
|
|
|
exercise_user = exercise.exercise_users.find_by(user_id:user.id)
|
|
|
|
exercise_user = exercise.exercise_users.find_by(user_id:user.id)
|
|
|
|
time_mill = ex_time * 60 #转为秒
|
|
|
|
time_mill = ex_time * 60 #转为秒
|
|
|
|
exercise_end_time = exercise.end_time.present? ? exercise.end_time.to_i : 0
|
|
|
|
exercise_end_time = exercise.end_time.present? ? exercise.end_time.to_i : 0
|
|
|
|
exercise_user_start = exercise_user.present? ? exercise_user.start_at.to_i : 0
|
|
|
|
exercise_user_start = exercise_user&.start_at.present? ? exercise_user.start_at.to_i : 0
|
|
|
|
#用户未开始答题时,即exercise_user_start为0
|
|
|
|
#用户未开始答题时,即exercise_user_start为0
|
|
|
|
if exercise_user_start == 0
|
|
|
|
if exercise_user_start == 0
|
|
|
|
if (exercise_end_time - time_now_i) > time_mill
|
|
|
|
if (exercise_end_time - time_now_i) > time_mill
|
|
|
|