diff --git a/db/migrate/20190822022306_add_exercise_user_update.rb b/db/migrate/20190822022306_add_exercise_user_update.rb index f45e6a8ee..223ee520b 100644 --- a/db/migrate/20190822022306_add_exercise_user_update.rb +++ b/db/migrate/20190822022306_add_exercise_user_update.rb @@ -1,20 +1,19 @@ 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) - 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 + # exs = Exercise.all.is_exercise_published.where("publish_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 diff --git a/lib/tasks/excellent_course_exercise.rake b/lib/tasks/excellent_course_exercise.rake index 0d8875806..a7fac1a8f 100644 --- a/lib/tasks/excellent_course_exercise.rake +++ b/lib/tasks/excellent_course_exercise.rake @@ -14,16 +14,18 @@ namespace :excellent_course_exercise do course = Course.find_by(id: course_id) course.exercises.each_with_index do |exercise, index| - # 第一个试卷的参与人数和通过人数都是传的数据,后续的随机 - 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) + 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) - members = course.students.order("id asc").limit(new_participant_count) - update_exercise_user(exercise, members, new_pass_count) + members = course.students.order("id asc").limit(new_participant_count) + update_exercise_user(exercise, members, new_pass_count) + end end end end diff --git a/lib/tasks/public_course.rake b/lib/tasks/public_course.rake index ff50a4e28..5e56926b3 100644 --- a/lib/tasks/public_course.rake +++ b/lib/tasks/public_course.rake @@ -110,6 +110,23 @@ namespace :public_course do end + task :create_homework_work => :environment do + course = Course.find(course_id) + course.practice_homeworks.each do |homework| + if homework.student_works.count == 0 + str = "" + CourseMember.students(course).each do |student| + str += "," if str != "" + str += "(#{homework.id},#{student.user_id}, '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" + end + if str != "" + sql = "insert into student_works (homework_common_id, user_id, created_at, updated_at) values" + str + ActiveRecord::Base.connection.execute sql + end + end + end + end + def min_swith(time) puts time return time < 9 ? "0#{time}" : time