|
|
|
@ -352,7 +352,7 @@ module ExercisesHelper
|
|
|
|
|
score2 = 0.0 #填空题
|
|
|
|
|
score5 = 0.0 #实训题
|
|
|
|
|
ques_stand = [] #问题是否正确
|
|
|
|
|
exercise_questions = exercise.exercise_questions
|
|
|
|
|
exercise_questions = exercise.exercise_questions.includes(:exercise_answers,:exercise_shixun_answers,:exercise_standard_answers,:exercise_shixun_challenges)
|
|
|
|
|
exercise_questions.each do |q|
|
|
|
|
|
if q.question_type != 5
|
|
|
|
|
answers_content = q.exercise_answers.search_answer_users("user_id",user.id) #学生的答案
|
|
|
|
@ -360,84 +360,99 @@ module ExercisesHelper
|
|
|
|
|
answers_content = q.exercise_shixun_answers.search_shixun_answers("user_id",user.id) #学生的答案
|
|
|
|
|
end
|
|
|
|
|
if q.question_type <= 2 #为选择题或判断题时
|
|
|
|
|
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
|
|
|
|
|
multi_each_score = (q.question_score / standard_answer.count) #当多选答案正确时,每个answer的分数均摊。
|
|
|
|
|
else
|
|
|
|
|
multi_each_score = 0.0
|
|
|
|
|
if answers_content.present? #学生有回答时
|
|
|
|
|
answer_choice_array = []
|
|
|
|
|
answers_content.each do |a|
|
|
|
|
|
answer_choice_array.push(a.exercise_choice.choice_position) #学生答案的位置
|
|
|
|
|
end
|
|
|
|
|
answers_content.update_all(:score => multi_each_score)
|
|
|
|
|
score1 = score1 + q.question_score
|
|
|
|
|
end
|
|
|
|
|
elsif q.question_type == 3 #填空题
|
|
|
|
|
null_standard_answer = q.exercise_standard_answers
|
|
|
|
|
standard_answer_array = null_standard_answer.select(:exercise_choice_id,: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 #存在标准答案时才有分数
|
|
|
|
|
each_standard_score = (q.question_score.to_f / standard_answer_count).round(1) #每一空的得分
|
|
|
|
|
else
|
|
|
|
|
each_standard_score = 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_attribute("score",each_standard_score)
|
|
|
|
|
score2 = score2 + each_standard_score
|
|
|
|
|
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
|
|
|
|
|
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_attribute("score",each_standard_score)
|
|
|
|
|
score2 = score2 + each_standard_score
|
|
|
|
|
st_answer_text.delete(u_answer_text)
|
|
|
|
|
score1 += 0.0
|
|
|
|
|
end
|
|
|
|
|
elsif q.question_type == 3 #填空题
|
|
|
|
|
if answers_content.present?
|
|
|
|
|
null_standard_answer = q.exercise_standard_answers
|
|
|
|
|
standard_answer_array = null_standard_answer.select(:exercise_choice_id,: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
|
|
|
|
|
else
|
|
|
|
|
score2 += 0.0
|
|
|
|
|
end
|
|
|
|
|
elsif q.question_type == 5 #实训题时,主观题这里不评分
|
|
|
|
|
q.exercise_shixun_challenges.each do |exercise_cha|
|
|
|
|
|
game = Game.user_games(user.id,exercise_cha.challenge_id).first #当前用户的关卡
|
|
|
|
|
if game.present?
|
|
|
|
|
exercise_cha_score = 0
|
|
|
|
|
answer_status = 0
|
|
|
|
|
cha_path = challenge_path exercise_cha.challenge.path
|
|
|
|
|
if game.status == 2 && game.final_score >= 0
|
|
|
|
|
exercise_cha_score = game.real_score exercise_cha.question_score #每一关卡的得分
|
|
|
|
|
answer_status = 1
|
|
|
|
|
end
|
|
|
|
|
if exercise_cha.exercise_shixun_answers.search_shixun_answers("user_id",user.id).blank? #把关卡的答案存入试卷的实训里
|
|
|
|
|
game_challenge = game.game_codes.search_challenge_path(cha_path).first
|
|
|
|
|
if game_challenge.present?
|
|
|
|
|
game_code = game_challenge
|
|
|
|
|
code = game_code.try(:new_code)
|
|
|
|
|
if answers_content.present?
|
|
|
|
|
q.exercise_shixun_challenges.each do |exercise_cha|
|
|
|
|
|
game = Game.user_games(user.id,exercise_cha.challenge_id).first #当前用户的关卡
|
|
|
|
|
if game.present?
|
|
|
|
|
exercise_cha_score = 0.0
|
|
|
|
|
answer_status = 0
|
|
|
|
|
cha_path = challenge_path exercise_cha.challenge.path
|
|
|
|
|
if game.status == 2 && game.final_score >= 0
|
|
|
|
|
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)
|
|
|
|
|
if ex_shixun_answer_content.blank? #把关卡的答案存入试卷的实训里
|
|
|
|
|
game_challenge = game.game_codes.search_challenge_path(cha_path).first
|
|
|
|
|
if game_challenge.present?
|
|
|
|
|
game_code = game_challenge
|
|
|
|
|
code = game_code.try(:new_code)
|
|
|
|
|
else
|
|
|
|
|
code = git_fle_content(exercise_cha.shixun.repo_path,cha_path)
|
|
|
|
|
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
|
|
|
|
|
code = git_fle_content(exercise_cha.shixun.repo_path,cha_path)
|
|
|
|
|
ex_shixun_answer_content.first.update_column('score',exercise_cha_score)
|
|
|
|
|
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)
|
|
|
|
|
score5 += exercise_cha_score
|
|
|
|
|
end
|
|
|
|
|
score5 += exercise_cha_score
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
score5 += 0.0
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
user_scores = answers_content.score_reviewed.pluck(:score).sum
|
|
|
|
|
user_scores = answers_content.present? ? answers_content.score_reviewed.pluck(:score).sum : 0.0
|
|
|
|
|
if user_scores > 0
|
|
|
|
|
stand_answer = 1
|
|
|
|
|
else
|
|
|
|
|