三种类型题目计算总分

sw_new_course
huang 10 years ago
parent 74f6cb2e64
commit ed86e3ee5a

@ -437,6 +437,7 @@ class ExerciseController < ApplicationController
@uncomplete_question = get_uncomplete_question(@exercise, User.current) @uncomplete_question = get_uncomplete_question(@exercise, User.current)
# 获取改学生的考试得分 # 获取改学生的考试得分
@score = calculate_student_score(@exercise, User.current) @score = calculate_student_score(@exercise, User.current)
# @score = 100
if @uncomplete_question.count < 1 if @uncomplete_question.count < 1
# 查看是否有已提交记录 # 查看是否有已提交记录
eu = get_exercise_user(@exercise.id, User.current.id) eu = get_exercise_user(@exercise.id, User.current.id)
@ -461,22 +462,38 @@ class ExerciseController < ApplicationController
# 计算学生得分 # 计算学生得分
def calculate_student_score(exercise, user) def calculate_student_score(exercise, user)
score = 0 score = 0
score1 = 0
score2 = 0
score3 = 0
exercise_qustions = exercise.exercise_questions exercise_qustions = exercise.exercise_questions
exercise_qustions.each do |question| exercise_qustions.each do |question|
answer = get_user_answer(question, user) answer = get_user_answer(question, user)
standard_answer = get_user_standard_answer(question, user) standard_answer = get_user_standard_answer(question, user)
unless answer.nil?
# 问答题有多个答案 # 问答题有多个答案
if question.question_type == 3 if question.question_type == 3
if standard_answer.include?(answer.exercise_choice_id) if standard_answer.include?(answer.first.answer_text)
score += question.question_score unless question.question_score.empty? 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 end
else else
if answer.exercise_choice_id == standard_answer.exercise_choice_id ecs = ExerciseAnswer.where("user_id =? and exercise_question_id =?", user.id, question.id)
score += question.question_score unless question.question_score.empty? 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
end end
end end
score score = score1 + score2 + score3
end end
private private
@ -495,7 +512,7 @@ class ExerciseController < ApplicationController
uncomplete_question = [] uncomplete_question = []
all_questions.each do |question| all_questions.each do |question|
answers = get_user_answer(question, user) answers = get_user_answer(question, user)
if answers.nil? || answers.count < 1 if answers.nil?
uncomplete_question << question uncomplete_question << question
end end
end end
@ -504,6 +521,7 @@ class ExerciseController < ApplicationController
# 获取当前学生回答问题的答案 # 获取当前学生回答问题的答案
def get_user_answer(question,user) 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 = question.exercise_answers.where("#{ExerciseAnswer.table_name}.user_id = #{user.id}")
user_answer user_answer
end end
@ -516,7 +534,7 @@ class ExerciseController < ApplicationController
standard_answer << answer.answer_text standard_answer << answer.answer_text
end end
else else
standard_answer = question.exercise_standard_answers standard_answer = question.exercise_standard_answers.first
end end
standard_answer standard_answer
end end

@ -54,7 +54,7 @@
</div> </div>
<div class="testStatus" id="mcq_question_list" style="display: <%=mcq_question_list.count > 0 ? "" : "none" %>"> <div class="testStatus" id="mcq_question_list" style="display: <%=mcq_question_list.count > 0 ? "" : "none" %>">
<h3 class="fontGrey3">多选题</h3> <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="poll_questions_<%= exercise_question.id%>">
<div id="show_poll_questions_<%= exercise_question.id %>"> <div id="show_poll_questions_<%= exercise_question.id %>">
<div> <div>

Loading…
Cancel
Save