diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 65a0b9e9..7a4f91fa 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -81,12 +81,11 @@ class ExerciseController < ApplicationController @can_edit_excercise = can_edit_exercise @exercise, @exercise_user if !@can_edit_excercise && !@exercise_user.status time = (@exercise_user.start_at.to_i + @exercise.time.to_i * 60) > @exercise.end_time.to_i ? @exercise.end_time : Time.at(@exercise_user.start_at.to_i + @exercise.time.to_i * 60) - @exercise_user.update_attributes(:status => true, :end_at => time, :commit_status => 1) s_score = calculate_student_score(@exercise, @exercise_user.user) - @exercise_user.update_attributes(:objective_score => s_score, :score => (s_score + (@exercise_user.subjective_score && @exercise_user.subjective_score > 0 ? @exercise_user.subjective_score : 0))) - if @exercise_user.user.exercise_answer.where(:exercise_question_id => @exercise.exercise_questions.where(:question_type => 4).map(&:id)).empty? - @exercise_user.update_attributes(:subjective_score => 0) - end + sub_score = @exercise_user.user.exercise_answer.where(:exercise_question_id => @exercise.exercise_questions.where(:question_type => 4).map(&:id)).empty? ? 0 : @exercise_user.subjective_score + total_score = s_score + (sub_score && sub_score > 0 ? sub_score : 0) + @exercise_user.update_attributes(:status => true, :end_at => time, :commit_status => 1, :objective_score => s_score, + :subjective_score => sub_score, :score => total_score) end if @exercise_user.commit_status == 1 && @exercise.end_time > Time.now @@ -313,12 +312,11 @@ class ExerciseController < ApplicationController @exercise.exercise_status = 3 @exercise.exercise_users.each do |exercise_user| if exercise_user.commit_status == 0 && !exercise_user.start_at.nil? - exercise_user.update_attributes(:commit_status => 1, :end_at => params[:exercise_end_time], :status => true) s_score = calculate_student_score(@exercise, exercise_user.user) - exercise_user.update_attributes(:objective_score => s_score, :score => (s_score + (exercise_user.subjective_score && exercise_user.subjective_score > 0 ? exercise_user.subjective_score : 0))) - if exercise_user.user.exercise_answer.where(:exercise_question_id => @exercise.exercise_questions.where(:question_type => 4).map(&:id)).empty? - exercise_user.update_attributes(:subjective_score => 0) - end + sub_score = exercise_user.user.exercise_answer.where(:exercise_question_id => @exercise.exercise_questions.where(:question_type => 4).map(&:id)).empty? ? 0 : exercise_user.subjective_score + total_score = s_score + (sub_score && sub_score > 0 ? sub_score : 0) + exercise_user.update_attributes(:commit_status => 1, :end_at => params[:exercise_end_time], :status => true, :objective_score => s_score, + :subjective_score => sub_score, :score => total_score) end end elsif @exercise.end_time > Time.now && @exercise.exercise_status == 3 @@ -373,7 +371,7 @@ class ExerciseController < ApplicationController :question_title => question_title, :question_type => params[:question_type] || 1, :question_number => @exercise.exercise_questions.count + 1, - :question_score => params[:question_score], + :question_score => params[:question_type] == '5' ? 0 : params[:question_score], :shixun_id => params[:shixun] } @exercise_questions = @exercise.exercise_questions.new option @@ -766,12 +764,10 @@ class ExerciseController < ApplicationController exercise_users.each do |exercise_user| if exercise_user.commit_status == 0 && !exercise_user.start_at.nil? time = (exercise_user.start_at.to_i + @exercise.time.to_i * 60) > @exercise.end_time.to_i ? @exercise.end_time : Time.at(exercise_user.start_at.to_i + @exercise.time.to_i * 60) - exercise_user.update_attributes(:status => 1, :commit_status => 1, :end_at => time) s_score = calculate_student_score(@exercise, exercise_user.user) - exercise_user.update_attributes(:objective_score => s_score, :score => (s_score + (exercise_user.subjective_score && exercise_user.subjective_score > 0 ? exercise_user.subjective_score : 0))) - if exercise_user.user.exercise_answer.where(:exercise_question_id => @exercise.exercise_questions.where(:question_type => 4).map(&:id)).empty? - exercise_user.update_attributes(:subjective_score => 0) - end + sub_score = exercise_user.user.exercise_answer.where(:exercise_question_id => @exercise.exercise_questions.where(:question_type => 4).map(&:id)).empty? ? 0 : exercise_user.subjective_score + exercise_user.update_attributes(:status => 1, :commit_status => 1, :end_at => time, :objective_score => s_score, :subjective_score => sub_score, + :score => (s_score + (exercise_user.subjective_score && exercise_user.subjective_score > 0 ? exercise_user.subjective_score : 0))) end end #end @@ -827,23 +823,20 @@ class ExerciseController < ApplicationController setting_time = exercise_group_setting @exercise, member.try(:course_group) if ((Time.now.to_i - exercise_user.start_at.to_i) > @exercise.time.to_i * 60) || setting_time.end_time < Time.now time = (exercise_user.start_at.to_i + @exercise.time.to_i * 60) > setting_time.end_time.to_i ? setting_time.end_time : Time.at(exercise_user.start_at.to_i + @exercise.time.to_i * 60) - exercise_user.update_attributes(:commit_status => 1, :end_at => time, :status => true) - s_score = calculate_student_score(@exercise, exercise_user.user) - exercise_user.update_attributes(:objective_score => s_score, :score => (s_score + (exercise_user.subjective_score && exercise_user.subjective_score > 0 ? exercise_user.subjective_score : 0))) - if exercise_user.user.exercise_answer.where(:exercise_question_id => @exercise.exercise_questions.where(:question_type => 4).map(&:id)).empty? - exercise_user.update_attributes(:subjective_score => 0) - end + sub_score = exercise_user.user.exercise_answer.where(:exercise_question_id => @exercise.exercise_questions.where(:question_type => 4).map(&:id)).empty? ? 0 : exercise_user.subjective_score + total_score = s_score + (sub_score && sub_score > 0 ? sub_score : 0) + exercise_user.update_attributes(:commit_status => 1, :end_at => time, :status => true, :objective_score => s_score, + :subjective_score => sub_score, :score => total_score) end end end @exercise.exercise_users.where("commit_status = 1 and score is null").each do |exercise_user| s_score = calculate_student_score(@exercise, exercise_user.user) - exercise_user.update_attributes(:objective_score => s_score, :score => (s_score + (exercise_user.subjective_score && exercise_user.subjective_score > 0 ? exercise_user.subjective_score : 0))) - if exercise_user.user.exercise_answer.where(:exercise_question_id => @exercise.exercise_questions.where(:question_type => 4).map(&:id)).empty? - exercise_user.update_attributes(:subjective_score => 0) - end + sub_score = exercise_user.user.exercise_answer.where(:exercise_question_id => @exercise.exercise_questions.where(:question_type => 4).map(&:id)).empty? ? 0 : exercise_user.subjective_score + total_score = s_score + (sub_score && sub_score > 0 ? sub_score : 0) + exercise_user.update_attributes(:objective_score => s_score, :subjective_score => sub_score, :score => total_score) end @group_teacher = @is_teacher && @member.present? && @member.teacher_course_groups.count > 0 @@ -1119,13 +1112,12 @@ class ExerciseController < ApplicationController # 试卷未截止且试卷未提交过才能提交 if @exercise.exercise_status == 2 && cur_exercise_user.present? && cur_exercise_user.commit_status == 0 - cur_exercise_user.update_attributes(:status => 1, :commit_status => 1, :end_at => Time.now) #if @exercise.time && @exercise.time != -1 score = calculate_student_score(@exercise, User.current) - cur_exercise_user.update_attributes(:objective_score => score, :score => score + (cur_exercise_user.subjective_score > 0 ? cur_exercise_user.subjective_score : 0)) - if User.current.exercise_answer.where(:exercise_question_id => @exercise.exercise_questions.where(:question_type => 4).map(&:id)).empty? - cur_exercise_user.update_attributes(:subjective_score => 0) - end + sub_score = User.current.exercise_answer.where(:exercise_question_id => @exercise.exercise_questions.where(:question_type => 4).map(&:id)).empty? ? 0 : cur_exercise_user.subjective_score + total_score = score + (sub_score && sub_score > 0 ? sub_score : 0) + cur_exercise_user.update_attributes(:status => 1, :commit_status => 1, :end_at => Time.now, :objective_score => score, + :subjective_score => sub_score, :score => total_score) # 提交后给老师和助教发消息 tid_str = "" diff --git a/db/migrate/20190508012752_migrate_exercise_score.rb b/db/migrate/20190508012752_migrate_exercise_score.rb new file mode 100644 index 00000000..c1c8e5f8 --- /dev/null +++ b/db/migrate/20190508012752_migrate_exercise_score.rb @@ -0,0 +1,13 @@ +class MigrateExerciseScore < ActiveRecord::Migration + def up + change_column :exercise_users, :score, :float + change_column :exercise_users, :objective_score, :float + change_column :exercise_users, :subjective_score, :float + change_column :exercise_answers, :score, :float + change_column :exercise_shixun_answers, :score, :float + change_column :exercise_answer_comments, :score, :float + end + + def down + end +end diff --git a/db/migrate/20190508023840_migrate_exercise_1527_score.rb b/db/migrate/20190508023840_migrate_exercise_1527_score.rb new file mode 100644 index 00000000..3b01d8bd --- /dev/null +++ b/db/migrate/20190508023840_migrate_exercise_1527_score.rb @@ -0,0 +1,28 @@ +class MigrateExercise1527Score < ActiveRecord::Migration + def up + exercise = Exercise.where(:id => 1527).first + if exercise.present? + exercise.exercise_users.each do |exercise_user| + score = 0 + exercise.exercise_questions.each do |question| + question.exercise_shixun_challenges.each do |exercise_cha| + if exercise_cha.exercise_shixun_answers.where(:user_id => exercise_user.user_id).count > 1 + exercise_cha.exercise_shixun_answers.where(:user_id => exercise_user.user_id).last.destroy + end + end + + ExerciseShixunAnswer.where(exercise_question_id: question.id, user_id: exercise_user.user_id, status: 1, score: 12).update_all(score: 12.5) + + ExerciseShixunAnswer.where(exercise_question_id: question.id, user_id: exercise_user.user_id).each do |answer| + score += answer.score + end + end + + exercise_user.update_attributes(objective_score: score, score: score) + end + end + end + + def down + end +end