Merge branch 'sw_new_course' of http://repository.trustie.net/xianbo/trustie2 into sw_new_course

Conflicts:
	app/controllers/exercise_controller.rb
This commit is contained in:
cxt 2015-11-20 17:26:49 +08:00
commit d4d2adddb2
1 changed files with 45 additions and 11 deletions

View File

@ -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)
# 问答题有多个答案
if question.question_type == 3
if standard_answer.include?(answer.exercise_choice_id)
score += question.question_score unless question.question_score.empty?
end
else
if answer.exercise_choice_id == standard_answer.exercise_choice_id
score += question.question_score unless question.question_score.empty?
unless answer.nil?
# 问答题有多个答案
if question.question_type == 3
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
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
end
score
score = score1 + score2 + score3
end
private
@ -495,15 +512,32 @@ 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
uncomplete_question
end
# 获取当前学生回答问题的答案
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
# 是否完成了答题
# 获取问题的标准答案
def get_user_standard_answer(question,user)
if question.question_type == 3
standard_answer =[]
question.exercise_standard_answers.each do |answer|
standard_answer << answer.answer_text
end
else
standard_answer = question.exercise_standard_answers.first
end
standard_answer
end # 是否完成了答题
def get_complete_question(exercise,user)
questions = exercise.exercise_questions
complete_question = []