三种类型题目计算总分
This commit is contained in:
parent
74f6cb2e64
commit
ed86e3ee5a
|
@ -437,6 +437,7 @@ class ExerciseController < ApplicationController
|
|||
@uncomplete_question = get_uncomplete_question(@exercise, User.current)
|
||||
# 获取改学生的考试得分
|
||||
@score = calculate_student_score(@exercise, User.current)
|
||||
# @score = 100
|
||||
if @uncomplete_question.count < 1
|
||||
# 查看是否有已提交记录
|
||||
eu = get_exercise_user(@exercise.id, User.current.id)
|
||||
|
@ -461,22 +462,38 @@ class ExerciseController < ApplicationController
|
|||
# 计算学生得分
|
||||
def calculate_student_score(exercise, user)
|
||||
score = 0
|
||||
score1 = 0
|
||||
score2 = 0
|
||||
score3 = 0
|
||||
exercise_qustions = exercise.exercise_questions
|
||||
exercise_qustions.each do |question|
|
||||
answer = get_user_answer(question, user)
|
||||
standard_answer = get_user_standard_answer(question, user)
|
||||
unless answer.nil?
|
||||
# 问答题有多个答案
|
||||
if question.question_type == 3
|
||||
if standard_answer.include?(answer.exercise_choice_id)
|
||||
score += question.question_score unless question.question_score.empty?
|
||||
if standard_answer.include?(answer.first.answer_text)
|
||||
score1 = score+ question.question_score unless question.question_score.nil?
|
||||
end
|
||||
elsif question.question_type == 1
|
||||
if answer.first.exercise_choice.choice_position == standard_answer.exercise_choice_id
|
||||
score2 = score + question.question_score unless question.question_score.nil?
|
||||
end
|
||||
else
|
||||
if answer.exercise_choice_id == standard_answer.exercise_choice_id
|
||||
score += question.question_score unless question.question_score.empty?
|
||||
ecs = ExerciseAnswer.where("user_id =? and exercise_question_id =?", user.id, question.id)
|
||||
arr = []
|
||||
ecs.each do |ec|
|
||||
arr << ec.exercise_choice.choice_position
|
||||
end
|
||||
arr.sort
|
||||
arr = arr.join("")
|
||||
if arr.to_i == standard_answer.exercise_choice_id
|
||||
score3 = score + question.question_score unless question.question_score.nil?
|
||||
end
|
||||
end
|
||||
end
|
||||
score
|
||||
end
|
||||
score = score1 + score2 + score3
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -495,7 +512,7 @@ class ExerciseController < ApplicationController
|
|||
uncomplete_question = []
|
||||
all_questions.each do |question|
|
||||
answers = get_user_answer(question, user)
|
||||
if answers.nil? || answers.count < 1
|
||||
if answers.nil?
|
||||
uncomplete_question << question
|
||||
end
|
||||
end
|
||||
|
@ -504,6 +521,7 @@ class ExerciseController < ApplicationController
|
|||
|
||||
# 获取当前学生回答问题的答案
|
||||
def get_user_answer(question,user)
|
||||
# user_answer = ExerciseAnswer.where("user_id=? and exercise_question_id=?", user.id, question.id).first
|
||||
user_answer = question.exercise_answers.where("#{ExerciseAnswer.table_name}.user_id = #{user.id}")
|
||||
user_answer
|
||||
end
|
||||
|
@ -516,7 +534,7 @@ class ExerciseController < ApplicationController
|
|||
standard_answer << answer.answer_text
|
||||
end
|
||||
else
|
||||
standard_answer = question.exercise_standard_answers
|
||||
standard_answer = question.exercise_standard_answers.first
|
||||
end
|
||||
standard_answer
|
||||
end
|
||||
|
|
|
@ -54,7 +54,7 @@
|
|||
</div>
|
||||
<div class="testStatus" id="mcq_question_list" style="display: <%=mcq_question_list.count > 0 ? "" : "none" %>">
|
||||
<h3 class="fontGrey3">多选题</h3>
|
||||
<% mcq_question_list.each_with_index do |exercise_question, index| %>
|
||||
<% mcq_question_list.each_with_index do |exercise_question, list_index| %>
|
||||
<div id="poll_questions_<%= exercise_question.id%>">
|
||||
<div id="show_poll_questions_<%= exercise_question.id %>">
|
||||
<div>
|
||||
|
|
Loading…
Reference in New Issue