Merge branch 'dev_aliyun' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun

dev_forum
jingquan huang 5 years ago
commit 73e2840018

@ -1385,7 +1385,7 @@ class ExercisesController < ApplicationController
@paging_type = params[:sort].to_s @paging_type = params[:sort].to_s
end end
ques_result_all = exercise_commit_result(@exercise_questions,@exercise_commit_user_ids,@exercise_commit_users) ques_result_all = exercise_commit_result(@exercise_questions,@exercise_commit_user_ids)
if @paging_type == "percent" if @paging_type == "percent"
@question_result_hash = ques_result_all.sort_by{|s| s[:percent]} @question_result_hash = ques_result_all.sort_by{|s| s[:percent]}

@ -84,12 +84,12 @@ module ExercisesHelper
end end
#试卷的统计结果页面计算各题的 #试卷的统计结果页面计算各题的
def exercise_commit_result(questions,user_ids,commit_users) def exercise_commit_result(questions,user_ids)
question_infos = [] question_infos = []
percent = 0.0 percent = 0.0
questions.each do |ex| questions.each do |ex|
ex_total_score = user_ids.count * ex&.question_score #该试卷的已回答的总分 ex_total_score = user_ids.count * ex&.question_score #该试卷的已回答的总分
ex_answers = ex.exercise_answers ex_answers = ex.exercise_answers.includes(:exercise_choice)
if ex.question_type != Exercise::PRACTICAL if ex.question_type != Exercise::PRACTICAL
ques_title = ex.question_title ques_title = ex.question_title
ques_less_title = nil ques_less_title = nil
@ -115,14 +115,15 @@ module ExercisesHelper
right_users_count = 0 #该问题的回答正确的人数 right_users_count = 0 #该问题的回答正确的人数
#计算每个问题的答案人数 #计算每个问题的答案人数
commit_users.transaction do # commit_users.transaction do
commit_users.each do |user| #
answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).where(user_id:user.user_id)&.map {|s| s.exercise_choice.choice_position}.uniq # end
user_ids.each do |user_id|
answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).find(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq
if answer_choice_array.sort == standard_answer if answer_choice_array.sort == standard_answer
right_users_count += 1 right_users_count += 1
end end
end end
end
percent = effictive_users_count > 0 ? (right_users_count / effictive_users_count.to_f).round(3)*100 : 0.0 percent = effictive_users_count > 0 ? (right_users_count / effictive_users_count.to_f).round(3)*100 : 0.0
ex.exercise_choices.each do |c| ex.exercise_choices.each do |c|
right_answer = standard_answer.include?(c.choice_position) #选项的标准答案为选项的位置 right_answer = standard_answer.include?(c.choice_position) #选项的标准答案为选项的位置

@ -3,7 +3,7 @@ class UserExtension < ApplicationRecord
enum identity: { teacher: 0, student: 1, professional: 2, developer: 3 } enum identity: { teacher: 0, student: 1, professional: 2, developer: 3 }
belongs_to :user, touch: true belongs_to :user, touch: true
belongs_to :school belongs_to :school, optional: true
belongs_to :department, optional: true belongs_to :department, optional: true
def identity_text def identity_text

Loading…
Cancel
Save