|
|
|
@ -83,12 +83,13 @@ module ExercisesHelper
|
|
|
|
|
@ex_sub_array = @ex_sub_array.sort_by {|k| k[:q_position]}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#试卷的统计结果页面计算各题的
|
|
|
|
|
#试卷的统计结果页面计算各题的。选择题和判断题原来是按:已回答了本题的人数来计算的。现需要按已提交试卷的人数来计算。2019-8-23
|
|
|
|
|
def exercise_commit_result(questions,user_ids)
|
|
|
|
|
question_infos = []
|
|
|
|
|
# percent = 0.0
|
|
|
|
|
percent = 0.0
|
|
|
|
|
commit_user_ids = user_ids.size
|
|
|
|
|
questions.includes(:exercise_choices).each do |ex|
|
|
|
|
|
ex_total_score = user_ids.count * ex&.question_score.to_f #该试卷的已回答的总分
|
|
|
|
|
ex_total_score = commit_user_ids * ex&.question_score.to_f #该试卷的已回答的总分
|
|
|
|
|
# ex_answers = ex.exercise_answers
|
|
|
|
|
if ex.question_type != Exercise::PRACTICAL
|
|
|
|
|
ques_title = ex.question_title
|
|
|
|
@ -104,41 +105,30 @@ module ExercisesHelper
|
|
|
|
|
|
|
|
|
|
effictive_users_count = effictive_users.size #有效回答数,可能有重复的用户id,这里仅统计是否回答这个问题的全部人数
|
|
|
|
|
#
|
|
|
|
|
# if ex.question_type > Exercise::COMPLETION #当为主观题和实训题时,
|
|
|
|
|
# ex_answered_scores = effictive_users.score_reviewed.pluck(:score).sum #该问题的全部得分
|
|
|
|
|
# percent = (ex_total_score == 0.0 ? 0.0 : (ex_answered_scores / ex_total_score.to_f).round(3) * 100) #正确率
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
|
|
#全部题型按已提交学生的分数来计算
|
|
|
|
|
ex_answered_scores = effictive_users.score_reviewed.pluck(:score).sum #该问题的全部得分
|
|
|
|
|
percent = (ex_total_score == 0.0 ? 0.0 : (ex_answered_scores / ex_total_score.to_f).round(3) * 100) #正确率
|
|
|
|
|
if ex.question_type > Exercise::COMPLETION #当为主观题和实训题时,
|
|
|
|
|
ex_answered_scores = effictive_users.score_reviewed.pluck(:score).sum #该问题的全部得分
|
|
|
|
|
percent = (ex_total_score == 0.0 ? 0.0 : (ex_answered_scores / ex_total_score.to_f).round(3) * 100) #正确率
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
question_answer_infos = []
|
|
|
|
|
if ex.question_type <= Exercise::JUDGMENT #选择题和判断题
|
|
|
|
|
ex_choices = ex.exercise_choices
|
|
|
|
|
standard_answer = ex.exercise_standard_answers.pluck(:exercise_choice_id).sort #标准答案的位置
|
|
|
|
|
# right_users_count = 0
|
|
|
|
|
#该问题的正确率
|
|
|
|
|
# if ex.question_type == Exercise::MULTIPLE #多选题
|
|
|
|
|
# right_user_ids = user_ids
|
|
|
|
|
# standard_answer.each do |choice_position|
|
|
|
|
|
# standard_answer_choice_id = ex_choices.select{|ec| ec.choice_position == choice_position}.first&.id
|
|
|
|
|
# right_user_ids = right_user_ids & effictive_users.select{|answer| answer.exercise_choice_id == standard_answer_choice_id}.pluck(:user_id)
|
|
|
|
|
# end
|
|
|
|
|
# right_users_count = right_user_ids.size
|
|
|
|
|
# # user_ids.each do |user_id|
|
|
|
|
|
# # ex_choice_ids = effictive_users.map{|e| e.exercise_choice_id if e.user_id == user_id}.reject(&:blank?).uniq
|
|
|
|
|
# # answer_choice_array = ex_choices.map{|a| a.choice_position if ex_choice_ids.include?(a.id)}.reject(&:blank?).uniq
|
|
|
|
|
# # if answer_choice_array.sort == standard_answer
|
|
|
|
|
# # right_users_count += 1
|
|
|
|
|
# # end
|
|
|
|
|
# # end
|
|
|
|
|
# else #单选题和判断题
|
|
|
|
|
# standard_answer_choice_id = ex_choices.select{|ec| ec.choice_position == standard_answer.first}.first&.id
|
|
|
|
|
# right_users_count = effictive_users.select{|answer| answer.exercise_choice_id == standard_answer_choice_id}.size
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
|
|
# percent = effictive_users_count > 0 ? (right_users_count / effictive_users_count.to_f).round(3)*100 : 0.0
|
|
|
|
|
# 该问题的正确率
|
|
|
|
|
if ex.question_type == Exercise::MULTIPLE #多选题
|
|
|
|
|
right_user_ids = user_ids
|
|
|
|
|
standard_answer.each do |choice_position|
|
|
|
|
|
standard_answer_choice_id = ex_choices.select{|ec| ec.choice_position == choice_position}.first&.id
|
|
|
|
|
right_user_ids = right_user_ids & effictive_users.select{|answer| answer.exercise_choice_id == standard_answer_choice_id}.pluck(:user_id)
|
|
|
|
|
end
|
|
|
|
|
right_users_count = right_user_ids.size
|
|
|
|
|
else #单选题和判断题
|
|
|
|
|
standard_answer_choice_id = ex_choices.select{|ec| ec.choice_position == standard_answer.first}.first&.id
|
|
|
|
|
right_users_count = effictive_users.select{|answer| answer.exercise_choice_id == standard_answer_choice_id}.size
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
percent = commit_user_ids > 0 ? (right_users_count / commit_user_ids.to_f).round(3)*100 : 0.0
|
|
|
|
|
|
|
|
|
|
#每个选项的正确率
|
|
|
|
|
ex_choices.each do |c|
|
|
|
|
@ -184,7 +174,8 @@ module ExercisesHelper
|
|
|
|
|
all_user_count += user_count
|
|
|
|
|
standard_answer_count += 1
|
|
|
|
|
end
|
|
|
|
|
# percent = effictive_users_count > 0 ? (all_user_count / effictive_users_count.to_f).round(3)*100 : 0.0
|
|
|
|
|
percent = commit_user_ids > 0 ? (all_user_count / commit_user_ids.to_f).round(3)*100 : 0.0
|
|
|
|
|
|
|
|
|
|
user_wrong_count = (effictive_users_count - all_user_count )
|
|
|
|
|
|
|
|
|
|
if effictive_users_count > 0 && user_wrong_count >= 0
|
|
|
|
@ -470,45 +461,50 @@ module ExercisesHelper
|
|
|
|
|
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.0
|
|
|
|
|
answer_status = 0
|
|
|
|
|
# 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)
|
|
|
|
|
code = nil
|
|
|
|
|
if exercise_cha.challenge&.path.present?
|
|
|
|
|
cha_path = challenge_path(exercise_cha.challenge&.path)
|
|
|
|
|
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)
|
|
|
|
|
user_shixun_score = exercise_cha&.exercise_shixun_answers&.where(user_id:user.id,exercise_question_id:q.id)
|
|
|
|
|
if user_shixun_score.present?
|
|
|
|
|
score5 += user_shixun_score&.first.score
|
|
|
|
|
else
|
|
|
|
|
game = Game.user_games(user.id,exercise_cha.challenge_id)&.first #当前用户的关卡
|
|
|
|
|
if game.present?
|
|
|
|
|
exercise_cha_score = 0.0
|
|
|
|
|
answer_status = 0
|
|
|
|
|
# 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)
|
|
|
|
|
code = nil
|
|
|
|
|
if exercise_cha.challenge&.path.present?
|
|
|
|
|
cha_path = challenge_path(exercise_cha.challenge&.path)
|
|
|
|
|
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(game.myshixun.repo_path,cha_path)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
if ex_shixun_answer_content.blank? #把关卡的答案存入试卷的实训里
|
|
|
|
|
### Todo 实训题的_shixun_details里的代码是不是直接从这里取出就可以了?涉及到code的多个版本库的修改
|
|
|
|
|
sx_option = {
|
|
|
|
|
:exercise_question_id => q.id,
|
|
|
|
|
:exercise_shixun_challenge_id => exercise_cha.id,
|
|
|
|
|
:user_id => user.id,
|
|
|
|
|
:score => exercise_cha_score.round(1),
|
|
|
|
|
:answer_text => code,
|
|
|
|
|
:status => answer_status
|
|
|
|
|
}
|
|
|
|
|
ExerciseShixunAnswer.create(sx_option)
|
|
|
|
|
else
|
|
|
|
|
code = git_fle_content(game.myshixun.repo_path,cha_path)
|
|
|
|
|
ex_shixun_answer_content.first.update_attributes(score:exercise_cha_score.round(1),answer_text:code)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
if ex_shixun_answer_content.blank? #把关卡的答案存入试卷的实训里
|
|
|
|
|
### Todo 实训题的_shixun_details里的代码是不是直接从这里取出就可以了?涉及到code的多个版本库的修改
|
|
|
|
|
sx_option = {
|
|
|
|
|
:exercise_question_id => q.id,
|
|
|
|
|
:exercise_shixun_challenge_id => exercise_cha.id,
|
|
|
|
|
:user_id => user.id,
|
|
|
|
|
:score => exercise_cha_score.round(1),
|
|
|
|
|
:answer_text => code,
|
|
|
|
|
:status => answer_status
|
|
|
|
|
}
|
|
|
|
|
ExerciseShixunAnswer.create(sx_option)
|
|
|
|
|
score5 += exercise_cha_score
|
|
|
|
|
else
|
|
|
|
|
ex_shixun_answer_content.first.update_attributes(score:exercise_cha_score.round(1),answer_text:code)
|
|
|
|
|
score5 += 0.0
|
|
|
|
|
end
|
|
|
|
|
score5 += exercise_cha_score
|
|
|
|
|
else
|
|
|
|
|
score5 += 0.0
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|