From 6035f984bad86eab0483aad19f02a17005627c17 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 22 Aug 2019 17:39:20 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=9A=84=E5=88=86=E6=95=B0?= =?UTF-8?q?=E8=BF=81=E7=A7=BB=E6=96=87=E4=BB=B6=E7=9A=84=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...20190822022306_add_exercise_user_update.rb | 38 ++++++++++++++----- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/db/migrate/20190822022306_add_exercise_user_update.rb b/db/migrate/20190822022306_add_exercise_user_update.rb index f45e6a8ee..8bf668934 100644 --- a/db/migrate/20190822022306_add_exercise_user_update.rb +++ b/db/migrate/20190822022306_add_exercise_user_update.rb @@ -2,19 +2,37 @@ class AddExerciseUserUpdate < ActiveRecord::Migration[5.2] include ExercisesHelper def change #2019,8,22添加 - exs = Exercise.all.is_exercise_published.where("publish_time > ?",(Time.now - 2.months)).includes(:exercise_questions,:exercise_users) + two_months = Time.now - 2.months + exs = Exercise.all.is_exercise_published.where("publish_time > ?",two_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 + if ex.exercise_questions.where("created_at < ?",Time.now - 1.month).pluck(:question_type).include?(1) #含有多选题,且是1个月前创建的才更新 + ex_users = ex.exercise_users.exercise_user_committed.where("end_at is not null and end_at > ?",two_months) + if ex_users.exists? + 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 + + #1936的试卷成绩有问题。 + # #https://www.educoder.net/courses/2935/exercises/1936/users/pizfnr5ts + ex_special = Exercise.find_by_id(1936) + ex_special_users = ex_special.exercise_users.exercise_user_committed.where("end_at is not null and end_at > ?",two_months) + if ex_special.present? && ex_special_users.exists? + ex_special_users.each do |ex_user| + calculate_score = calculate_student_score(ex_special,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