diff --git a/db/migrate/20191223113621_modify_task_pass_for_challenges.rb b/db/migrate/20191223113621_modify_task_pass_for_challenges.rb new file mode 100644 index 000000000..dbbbafced --- /dev/null +++ b/db/migrate/20191223113621_modify_task_pass_for_challenges.rb @@ -0,0 +1,8 @@ +class ModifyTaskPassForChallenges < ActiveRecord::Migration[5.2] + def change + Challenge.find_each do |challenge| + task_pass = challenge.task_pass.gsub(" ", "").gsub("rac", '\frac') + challenge.update_attribute(:task_pass, task_pass) + end + end +end diff --git a/lib/tasks/excellent_course_exercise.rake b/lib/tasks/excellent_course_exercise.rake index e05a813f4..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 @@ -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 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