From dbbcfcc332ec3ad5c702031beccea104b4985c06 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 23 Dec 2019 17:10:46 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E5=AD=A6=E7=94=9F?= =?UTF-8?q?=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/migrate_course_student.rake | 32 +++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 lib/tasks/migrate_course_student.rake diff --git a/lib/tasks/migrate_course_student.rake b/lib/tasks/migrate_course_student.rake new file mode 100644 index 000000000..913cb2562 --- /dev/null +++ b/lib/tasks/migrate_course_student.rake @@ -0,0 +1,32 @@ +# 执行示例 RAILS_ENV=production bundle exec rake migrate_course_student:student args=3835,2526,21950,1000 +# args 第一个课程 course_id,第二个参数是学校school_id,第三个参数是部门id,第四个参数是迁移数量 +# + +desc "同步学校的学生" +namespace :migrate_course_student do + if ENV['args'] + course_id = ENV['args'].split(",")[0] # 对应课堂的id + school_id = ENV['args'].split(",")[1] # 对应学校id + department_id = ENV['args'].split(",")[2] # 对应部门id + limit = ENV['args'].split(",")[3] # 限制导入的数量 + end + + task :student => :environment do + course = Course.find course_id + users = User.joins(:user_extension).where(user_extensions: {school_id: school_id, department_id: department_id, identity: 1}).limit(limit) + user_ids = [] + + users.each do |user| + if user.student_id.present? && !course.students.exists?(user_id: user.id) + begin + CourseMember.create!(course_id: course_id, user_id: user.id, role: 4) + user_ids << user.id + rescue Exception => e + Rails.logger(e.message) + end + end + end + CourseAddStudentCreateWorksJob.perform_later(course_id, user_ids) + + end +end \ No newline at end of file From e972dd939a2f79ef19596b0ad1896f45a5e98f6f Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 23 Dec 2019 18:12:20 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/excellent_course_exercise.rake | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/tasks/excellent_course_exercise.rake b/lib/tasks/excellent_course_exercise.rake index e05a813f4..c3700957c 100644 --- a/lib/tasks/excellent_course_exercise.rake +++ b/lib/tasks/excellent_course_exercise.rake @@ -36,14 +36,15 @@ namespace :excellent_course_exercise do # index < pass_count 之前的学生都是通关的,之后的未通过 members.each_with_index do |member, index| exercise_user = exercise.exercise_users.where(user_id: member.user_id).take - if exercise_question_ids.length == 20 + question_length = exercise_question_ids.length + if question_length == 20 rand_num = index < pass_count - 1 ? rand(15..20) : rand(1..10) - elsif exercise_question_ids.length == 17 + elsif question_length == 17 rand_num = index < pass_count - 1 ? rand(12..17) : rand(1..9) - elsif exercise_question_ids.length == 39 + elsif question_length == 39 rand_num = index < pass_count - 1 ? rand(30..39) : rand(1..18) else - rand_num = exercise_question_ids.length + rand_num = index < pass_count - 1 ? rand((question_length-3)..question_length) : rand(1..(question_length-8)) end if exercise_user && exercise_user.commit_status == 0 From 15753532fbbc7333c7022c77c46b5de17fc1f387 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 23 Dec 2019 18:22:11 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/excellent_course_exercise.rake | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/tasks/excellent_course_exercise.rake b/lib/tasks/excellent_course_exercise.rake index c3700957c..a8f860c2d 100644 --- a/lib/tasks/excellent_course_exercise.rake +++ b/lib/tasks/excellent_course_exercise.rake @@ -14,19 +14,19 @@ namespace :excellent_course_exercise do course = Course.find_by(id: course_id) course.exercises.each_with_index do |exercise, index| - # if exercise.exercise_users.where(commit_status: 1).count == 0 + if exercise.exercise_users.where(commit_status: 1).count == 0 # 第一个试卷的参与人数和通过人数都是传的数据,后续的随机 if index == 0 members = course.students.order("id asc").limit(participant_count) update_exercise_user(exercise, members, pass_count) else - new_participant_count = rand((participant_count - 423)..participant_count) - new_pass_count = rand((new_participant_count - 113)..new_participant_count) + new_participant_count = rand((participant_count - 20)..participant_count) + new_pass_count = rand((new_participant_count - 30)..new_participant_count) members = course.students.order("id asc").limit(new_participant_count) update_exercise_user(exercise, members, new_pass_count) end - # end + end end end From 69f7c8cc25c095e3e33bc6f9a0c0b733d4cc0583 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 23 Dec 2019 19:40:02 +0800 Subject: [PATCH 4/8] =?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/controllers/comments_controller.rb | 2 +- .../20191223113620_modify_task_pass_for_challenges.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20191223113620_modify_task_pass_for_challenges.rb diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 851567c92..474132903 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -22,7 +22,7 @@ class CommentsController < ApplicationController @discuss = @hack.discusses.new(reply_params) @discuss.hidden = false @discuss.user_id = current_user.id - @discuss.root_id = params[:parent_id] + @discuss.root_id = params[:comments][:parent_id] @discuss.save! rescue Exception => e uid_logger_error("reply discuss failed : #{e.message}") diff --git a/db/migrate/20191223113620_modify_task_pass_for_challenges.rb b/db/migrate/20191223113620_modify_task_pass_for_challenges.rb new file mode 100644 index 000000000..097892ac5 --- /dev/null +++ b/db/migrate/20191223113620_modify_task_pass_for_challenges.rb @@ -0,0 +1,6 @@ +class ModifyTaskPassForChallenges < ActiveRecord::Migration[5.2] + def change + challenge = Challenge.find(6917) + challenge.update_attribute(:task_pass, challenge.gsub(" ", "").gsub("rac", "\frac")) + end +end From d03c8d469f4b4d4c4eb85f33e3c09f3abde32fc4 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 23 Dec 2019 19:41:08 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E8=BF=87=E5=85=B3=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/comments_controller.rb | 2 +- db/migrate/20191223113620_modify_task_pass_for_challenges.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 474132903..851567c92 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -22,7 +22,7 @@ class CommentsController < ApplicationController @discuss = @hack.discusses.new(reply_params) @discuss.hidden = false @discuss.user_id = current_user.id - @discuss.root_id = params[:comments][:parent_id] + @discuss.root_id = params[:parent_id] @discuss.save! rescue Exception => e uid_logger_error("reply discuss failed : #{e.message}") diff --git a/db/migrate/20191223113620_modify_task_pass_for_challenges.rb b/db/migrate/20191223113620_modify_task_pass_for_challenges.rb index 097892ac5..cfcb77fc7 100644 --- a/db/migrate/20191223113620_modify_task_pass_for_challenges.rb +++ b/db/migrate/20191223113620_modify_task_pass_for_challenges.rb @@ -1,6 +1,6 @@ class ModifyTaskPassForChallenges < ActiveRecord::Migration[5.2] def change challenge = Challenge.find(6917) - challenge.update_attribute(:task_pass, challenge.gsub(" ", "").gsub("rac", "\frac")) + challenge.update_attribute(:task_pass, challenge.task_pass.gsub(" ", "").gsub("rac", "\frac")) end end From e5e24d545521de2dd6582f96bd703a1e2714796d Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 23 Dec 2019 19:43:09 +0800 Subject: [PATCH 6/8] 1 --- db/migrate/20191223113620_modify_task_pass_for_challenges.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/db/migrate/20191223113620_modify_task_pass_for_challenges.rb b/db/migrate/20191223113620_modify_task_pass_for_challenges.rb index cfcb77fc7..f0d04f964 100644 --- a/db/migrate/20191223113620_modify_task_pass_for_challenges.rb +++ b/db/migrate/20191223113620_modify_task_pass_for_challenges.rb @@ -1,6 +1,7 @@ class ModifyTaskPassForChallenges < ActiveRecord::Migration[5.2] def change challenge = Challenge.find(6917) - challenge.update_attribute(:task_pass, challenge.task_pass.gsub(" ", "").gsub("rac", "\frac")) + task_pass = challenge.task_pass.gsub(" ", "").gsub("rac", '\frac') + challenge.update_attribute(:task_pass, task_pass) end end From 328d5108785bc3753206a53cf13c9fcce835cf54 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 23 Dec 2019 19:43:32 +0800 Subject: [PATCH 7/8] 1 --- ...enges.rb => 20191223113621_modify_task_pass_for_challenges.rb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename db/migrate/{20191223113620_modify_task_pass_for_challenges.rb => 20191223113621_modify_task_pass_for_challenges.rb} (100%) diff --git a/db/migrate/20191223113620_modify_task_pass_for_challenges.rb b/db/migrate/20191223113621_modify_task_pass_for_challenges.rb similarity index 100% rename from db/migrate/20191223113620_modify_task_pass_for_challenges.rb rename to db/migrate/20191223113621_modify_task_pass_for_challenges.rb From 382e8475f553117d83ffdeb01393d758ca0ed3fc Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 23 Dec 2019 19:45:25 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E8=BF=87=E5=85=B3=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20191223113621_modify_task_pass_for_challenges.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/db/migrate/20191223113621_modify_task_pass_for_challenges.rb b/db/migrate/20191223113621_modify_task_pass_for_challenges.rb index f0d04f964..dbbbafced 100644 --- a/db/migrate/20191223113621_modify_task_pass_for_challenges.rb +++ b/db/migrate/20191223113621_modify_task_pass_for_challenges.rb @@ -1,7 +1,8 @@ class ModifyTaskPassForChallenges < ActiveRecord::Migration[5.2] def change - challenge = Challenge.find(6917) - task_pass = challenge.task_pass.gsub(" ", "").gsub("rac", '\frac') - challenge.update_attribute(:task_pass, task_pass) + Challenge.find_each do |challenge| + task_pass = challenge.task_pass.gsub(" ", "").gsub("rac", '\frac') + challenge.update_attribute(:task_pass, task_pass) + end end end