用户提交答卷后,给出得分

sw_new_course
huang 10 years ago
parent c7476b3f86
commit bc47382115

@ -190,9 +190,9 @@ class ExerciseController < ApplicationController
@exercise_question.question_score = params[:question_score] @exercise_question.question_score = params[:question_score]
################处理选项 ################处理选项
if params[:question_answer] if params[:question_answer]
# @exercise_question.exercise_choices.each do |answer| @exercise_question.exercise_choices.each do |answer|
# answer.destroy unless params[:question_answer].keys.include? answer.id.to_s answer.destroy unless params[:question_answer].keys.include? answer.id.to_s
# end end
# 界面需要判断选择题至少有一个选项 # 界面需要判断选择题至少有一个选项
for i in 1..@exercise_question.exercise_choices.count for i in 1..@exercise_question.exercise_choices.count
question = @exercise_question.exercise_choices.find_by_id params[:question_answer].keys[i-1] question = @exercise_question.exercise_choices.find_by_id params[:question_answer].keys[i-1]
@ -265,9 +265,10 @@ class ExerciseController < ApplicationController
end end
end end
# 学生提交答卷 # 学生提交答卷,选着答案的课程中提交
def commit_answer def commit_answer
eq = ExerciseQuestion.find(params[:poll_question_id]) eq = ExerciseQuestion.find(params[:exercise_question_id])
# 已提交过的则不允许答题
if has_commit_exercise?(@exercise.id,User.current.id) && (!User.current.admin?) if has_commit_exercise?(@exercise.id,User.current.id) && (!User.current.admin?)
render :json => {:text => "failure"} render :json => {:text => "failure"}
return return
@ -369,11 +370,12 @@ class ExerciseController < ApplicationController
# 老师不需要提交 # 老师不需要提交
if User.current.allowed_to?(:as_teacher,@course) if User.current.allowed_to?(:as_teacher,@course)
redirect_to exercise_url(@exercise) redirect_to exercise_url(@exercise)
# REDO: 提示提交成功
else else
# 答题过程中需要统计完成量 # 答题过程中需要统计完成量
@uncomplete_question = get_uncomplete_question(@exercise, User.current) @uncomplete_question = get_uncomplete_question(@exercise, User.current)
# 获取改学生的考试得分 # 获取改学生的考试得分
score = get_answer_score(@exercise) score = calculate_student_score(@exercise, User.current)
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)
@ -395,6 +397,26 @@ class ExerciseController < ApplicationController
end end
end end
# 计算学生得分
def calculate_student_score(exercise, user)
score = 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.exercise_choice_id.include?(answer.exercise_choice_id)
score = score + question.question_score
end
else
if answer.exercise_choice_id == standard_answer.exercise_choice_id
score = score + question.question_score
end
end
end
score
end
private private
# ExerciseUser记录用户是否已提交问卷有对应的记录则已提交没有则新建一个 # ExerciseUser记录用户是否已提交问卷有对应的记录则已提交没有则新建一个
@ -419,12 +441,18 @@ class ExerciseController < ApplicationController
uncomplete_question uncomplete_question
end end
# 获取问题的答案 # 获取当前学生回答问题的答案
def get_user_answer(question,user) def get_user_answer(question,user)
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
# 获取问题的标准答案
def get_user_standard_answer(question,user)
standard_answer = question.exercise_standard_answers
standard_answer
end
# 是否完成了答题 # 是否完成了答题
def get_complete_question(exercise,user) def get_complete_question(exercise,user)
questions = exercise.exercise_questions questions = exercise.exercise_questions

Loading…
Cancel
Save