|
|
|
@ -120,21 +120,7 @@ module ExercisesHelper
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
# if ex.question_type != Exercise::MULTIPLE
|
|
|
|
|
# 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) #正确率
|
|
|
|
|
# else
|
|
|
|
|
# multiple_score = 0
|
|
|
|
|
# user_ids.each do |user_id|
|
|
|
|
|
# ex_answer_score = ex_answers.select{|answer| answer.user_id == user_id}&.first&.score.to_f
|
|
|
|
|
# multiple_score += ex_answer_score
|
|
|
|
|
# end
|
|
|
|
|
# percent = (ex_total_score == 0.0 ? 0.0 : (multiple_score / ex_total_score.to_f).round(3) * 100) #正确率
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
|
|
question_answer_infos = []
|
|
|
|
|
if ex.question_type <= Exercise::JUDGMENT #选择题和判断题
|
|
|
|
|
ex_choices = ex.exercise_choices
|
|
|
|
@ -178,43 +164,66 @@ module ExercisesHelper
|
|
|
|
|
question_answer_infos.push(answer_option)
|
|
|
|
|
end
|
|
|
|
|
elsif ex.question_type == Exercise::COMPLETION #填空题
|
|
|
|
|
effictive_users_ids = effictive_users.where("answer_text is not null and answer_text !=''").pluck(:user_id).uniq
|
|
|
|
|
effictive_users_count = effictive_users_ids.size
|
|
|
|
|
user_wrong_count = 0
|
|
|
|
|
effictive_users_ids.each do |s|
|
|
|
|
|
user_score = effictive_users.where(user_id: s).pluck(:score).sum
|
|
|
|
|
if user_score.to_f < ex&.question_score.to_f
|
|
|
|
|
user_wrong_count = user_wrong_count + 1
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
# user_wrong_ids = effictive_users.where()
|
|
|
|
|
# user_wrong_count = (user_wrong_ids & effictive_users_ids).uniq.size
|
|
|
|
|
ex_ordered = ex.is_ordered
|
|
|
|
|
null_standard_answer = ex.exercise_standard_answers
|
|
|
|
|
null_stand_choice = null_standard_answer.pluck(:exercise_choice_id).uniq #一个exercise_choice_id可能对应多个answer_text
|
|
|
|
|
null_stand_choice = null_standard_answer.pluck(:exercise_choice_id) #一个exercise_choice_id可能对应多个answer_text
|
|
|
|
|
null_stand_text = null_standard_answer.pluck(:answer_text)
|
|
|
|
|
standard_answer_count = 0
|
|
|
|
|
each_null_score = null_stand_choice.size > 0 ? (ex&.question_score.to_f / null_stand_choice.uniq.size).round(3) : 0.0
|
|
|
|
|
all_user_count = 0
|
|
|
|
|
null_stand_choice.each_with_index do |s,index|
|
|
|
|
|
user_count = 0
|
|
|
|
|
if ex_ordered #有序排列
|
|
|
|
|
|
|
|
|
|
if ex_ordered
|
|
|
|
|
all_user_answers = effictive_users.pluck(:answer_text)
|
|
|
|
|
null_stand_choice.each_with_index do |s,index|
|
|
|
|
|
s_choice_text = null_stand_text[index]
|
|
|
|
|
user_count = 0
|
|
|
|
|
# user_count = user_count + effictive_users.where("exercise_choice_id = ? and answer_text = ?",s,s_choice_text).pluck(:user_id).uniq.size
|
|
|
|
|
user_count = user_count + effictive_users.select{|answer| answer.exercise_choice_id == s && answer.answer_text == s_choice_text}.size
|
|
|
|
|
else
|
|
|
|
|
null_stand_text = null_stand_text.uniq
|
|
|
|
|
s_choice_text = null_stand_text[index]
|
|
|
|
|
user_count = user_count + effictive_users.select{|answer| answer.answer_text == s_choice_text }.size #回答了标准答案的用户
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
answer_percent = ((effictive_users_count == 0) ? 0.0 : (user_count / effictive_users_count.to_f ).round(3))
|
|
|
|
|
answer_option = {
|
|
|
|
|
answer_percent = ((effictive_users_count == 0) ? 0.0 : (user_count / effictive_users_count.to_f ).round(3))
|
|
|
|
|
answer_option = {
|
|
|
|
|
:choice_position => index+1,
|
|
|
|
|
:choice_text => s_choice_text,
|
|
|
|
|
:choice_users_count => user_count,
|
|
|
|
|
:choice_percent => answer_percent.round(2).to_s,
|
|
|
|
|
:right_answer => true
|
|
|
|
|
}
|
|
|
|
|
question_answer_infos.push(answer_option)
|
|
|
|
|
all_user_count += user_count
|
|
|
|
|
standard_answer_count += 1
|
|
|
|
|
}
|
|
|
|
|
question_answer_infos.push(answer_option)
|
|
|
|
|
all_user_count += user_count
|
|
|
|
|
standard_answer_count += 1
|
|
|
|
|
all_user_answers = all_user_answers - [s]
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
# cycled_stand = {}
|
|
|
|
|
null_stand_text.uniq.each_with_index do |stand, index|
|
|
|
|
|
user_count = 0
|
|
|
|
|
user_count = user_count + effictive_users.where("answer_text = ?",stand).pluck(:user_id).uniq.size
|
|
|
|
|
answer_percent = ((effictive_users_count == 0) ? 0.0 : (user_count / effictive_users_count.to_f ).round(3))
|
|
|
|
|
answer_option = {
|
|
|
|
|
:choice_position => index+1,
|
|
|
|
|
:choice_text => stand,
|
|
|
|
|
:choice_users_count => user_count,
|
|
|
|
|
:choice_percent => answer_percent.round(2).to_s,
|
|
|
|
|
:right_answer => true
|
|
|
|
|
}
|
|
|
|
|
question_answer_infos.push(answer_option)
|
|
|
|
|
all_user_count += user_count
|
|
|
|
|
standard_answer_count += 1
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
answer_user_score = all_user_count * each_null_score
|
|
|
|
|
percent = (ex_total_score == 0.0 ? 0.0 : (answer_user_score / ex_total_score.to_f).round(3) * 100) #正确率
|
|
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
wrong_percent = (user_wrong_count / effictive_users_count.to_f ).round(3)
|
|
|
|
|
else
|
|
|
|
@ -481,17 +490,28 @@ module ExercisesHelper
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
st_answer_text = standard_answer_array.pluck(:answer_text).reject(&:blank?).map{|a| a.strip.downcase}
|
|
|
|
|
st_answer_text = standard_answer_array.pluck(:answer_text).reject(&:blank?).map{|a| a.strip.downcase}.uniq
|
|
|
|
|
answers_content.each do |u|
|
|
|
|
|
u_answer_text = u.answer_text.strip.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)
|
|
|
|
|
if st_answer_text.size == 1
|
|
|
|
|
if st_answer_text.first == u_answer_text
|
|
|
|
|
u.update_column("score",q_score_2)
|
|
|
|
|
score2 = score2 + q_score_2
|
|
|
|
|
else
|
|
|
|
|
u.update_column('score',-1.0)
|
|
|
|
|
score2 += 0.0
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
u.update_column('score',-1.0)
|
|
|
|
|
score2 += 0.0
|
|
|
|
|
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)
|
|
|
|
|
else
|
|
|
|
|
u.update_column('score',-1.0)
|
|
|
|
|
score2 += 0.0
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|