dev_forum
SylorHuang 5 years ago
parent 194d7ee8d6
commit 9787d70f92

@ -86,10 +86,10 @@ module ExercisesHelper
#试卷的统计结果页面计算各题的
def exercise_commit_result(questions,user_ids)
question_infos = []
percent = 0.0
questions.each do |ex|
ex_total_score = user_ids.count * ex&.question_score #该试卷的已回答的总分
ex_answers = ex.exercise_answers
if ex.question_type != Exercise::PRACTICAL
ques_title = ex.question_title
ques_less_title = nil
@ -103,15 +103,23 @@ module ExercisesHelper
effictive_users_count = effictive_users.size #有效回答数可能有重复的用户id这里仅统计是否回答这个问题的全部人数
ex_answered_scores = effictive_users.score_reviewed.pluck(:score).sum #该问题的全部得分
if ex_total_score == 0.0
percent = 0.0
else
percent = (ex_answered_scores / ex_total_score.to_f).round(3) * 100 #正确率
if ex.question_type > Exercise::COMPLETION #当为主观题和实训题时,
if ex_total_score != 0.0
percent = (ex_answered_scores / ex_total_score.to_f).round(3) * 100 #正确率
end
end
question_answer_infos = []
if ex.question_type <= Exercise::JUDGMENT #单选题
standard_answer = ex.exercise_standard_answers.pluck(:exercise_choice_id) #标准答案的位置
if ex.question_type <= Exercise::JUDGMENT #选择题和判断题
standard_answer = ex.exercise_standard_answers.pluck(:exercise_choice_id).sort #标准答案的位置
right_users_count = 0 #该问题的回答正确的人数
user_ids.each do |user_id|
user_an_choice = effictive_users.where(user_id:user_id).pluck(:exercise_choice_id).sort
if user_an_choice == standard_answer
right_users_count += 1
end
end
percent = effictive_users_count > 0 ? (right_users_count / effictive_users_count.to_f).round(3)*100 : 0.0
ex.exercise_choices.each do |c|
right_answer = standard_answer.include?(c.choice_position) #选项的标准答案为选项的位置
answer_this_choice = effictive_users.search_exercise_answer("exercise_choice_id",c.id)
@ -125,7 +133,7 @@ module ExercisesHelper
:choice_position => c.choice_position,
:choice_text => c.choice_text,
:choice_users_count => answer_users_count,
:choice_percent => answer_percent.round(1),
:choice_percent => answer_percent.round(1).to_s,
:right_answer => right_answer
}
question_answer_infos.push(answer_option)
@ -161,13 +169,14 @@ module ExercisesHelper
:choice_position => index+1,
:choice_text => s_choice_text,
:choice_users_count => user_count,
:choice_percent => answer_percent.round(1),
:choice_percent => answer_percent.round(1).to_s,
:right_answer => true
}
question_answer_infos.push(answer_option)
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
user_wrong_count = (effictive_users_count - all_user_count )
if effictive_users_count > 0 && user_wrong_count >= 0
@ -179,7 +188,7 @@ module ExercisesHelper
:choice_position => (standard_answer_count + 1),
:choice_text => "wrong",
:choice_users_count => user_wrong_count,
:choice_percent => wrong_percent.round(1),
:choice_percent => wrong_percent.round(1).to_s,
:right_answer => false
}
question_answer_infos.push(wrong_answer_position)
@ -188,12 +197,10 @@ module ExercisesHelper
full_scores = effictive_users.search_exercise_answer("score",ex_score).count #满分人数
no_full_scores = effictive_users.exercise_no_full_scores(ex_score).count #部分分数人数
zero_scores = effictive_users.search_exercise_answer("score",0.0).count #包含为0分的及未评阅的
# review_scores = ex.exercise_answer_comments.count #主观题的评阅数量
un_review_scores = effictive_users_count - full_scores - no_full_scores - zero_scores #未评阅数
if un_review_scores < 0
un_review_scores = 0
end
# zero_scores = all_zero_scores - un_review_scores #已评阅且答案未0分的人数
main_scores_array = [full_scores,no_full_scores,zero_scores,un_review_scores]
main_scores_array.each_with_index do |s,index|
right_answer = (index == 0)
@ -207,7 +214,7 @@ module ExercisesHelper
:choice_position => index+1,
:choice_text => index+1,
:choice_users_count => s,
:choice_percent => score_percent.round(1),
:choice_percent => score_percent.round(1).to_s,
:right_answer => right_answer
}
question_answer_infos.push(answer_option)
@ -224,7 +231,7 @@ module ExercisesHelper
shixun_answered_scores = cha_shixun_answer.score_reviewed.pluck(:score).sum #该问题的全部得分
if shixun_answered_scores == 0.0
game_percent = "0.0"
game_percent = 0.0
else
game_percent = (shixun_answered_scores / shixun_scores.to_f).round(3) * 100 #正确率
end
@ -242,7 +249,7 @@ module ExercisesHelper
:choice_position => index+1,
:choice_text => index+1,
:choice_users_count => s,
:choice_percent => score_percent.round(1),
:choice_percent => score_percent.round(1).to_s,
:right_answer => right_answer
}
shixun_chas.push(answer_option)
@ -252,7 +259,7 @@ module ExercisesHelper
:cha_name => c.challenge.subject,
:cha_position => c.position,
:cha_details => shixun_chas,
:cha_percent => game_percent
:cha_percent => game_percent.round(1).to_s
}
question_answer_infos.push(shixun_new_chas)
end

Loading…
Cancel
Save