From 98aaf84addb8593182b4f5ca89fcfb345ad0d294 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 22 Aug 2019 11:07:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=AF=95=E5=8D=B7=E7=9A=84?= =?UTF-8?q?=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/exercises_helper.rb | 2 +- ...20190822022306_add_exercise_user_update.rb | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20190822022306_add_exercise_user_update.rb diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index d8a91f571..d4ecf6d1a 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -406,7 +406,7 @@ module ExercisesHelper #TODO: 旧版多选题的标准答案是放在一个里面的,新版又做成了一个题有多个标准答案(exercise_choice_id存放的是标准答案的位置..) if q.question_type == 1 && standard_answer.size == 1 - standard_answer = standard_answer.first.to_s.split("").map(&:to_i) + standard_answer = standard_answer.first.to_s.split("").map(&:to_i).sort end if user_answer_content == standard_answer #答案一致,多选或单选才给分,答案不对不给分 diff --git a/db/migrate/20190822022306_add_exercise_user_update.rb b/db/migrate/20190822022306_add_exercise_user_update.rb new file mode 100644 index 000000000..c15e1a8e0 --- /dev/null +++ b/db/migrate/20190822022306_add_exercise_user_update.rb @@ -0,0 +1,19 @@ +class AddExerciseUserUpdate < ActiveRecord::Migration[5.2] + include ExercisesHelper + def change + exs = Exercise.all.is_exercise_published.where("published_time > ?",(Time.now - 2.months)).includes(:exercise_questions,:exercise_users) + exs.each do |ex| + ex_users = ex.exercise_users.exercise_user_committed.where("end_at is not null and end_at > ?",(Time.now - 2.months)) + if ex_users.present? + ex_users.each do |ex_user| + calculate_score = calculate_student_score(ex,ex_user.user)[:total_score] + subjective_score = ex_user.subjective_score + total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score + total_score = calculate_score + total_score_subjective_score + ex_user.update_attributes(score:total_score,objective_score:calculate_score) + puts ex_user.id + end + end + end + end +end