Merge branch 'dev_aliyun' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun
commit
b2007f53ca
@ -0,0 +1,21 @@
|
|||||||
|
class CreateStudentWorkJob < ApplicationJob
|
||||||
|
queue_as :default
|
||||||
|
|
||||||
|
def perform(homework_id)
|
||||||
|
homework = HomeworkCommon.find_by(id: homework_id)
|
||||||
|
course = homework&.course
|
||||||
|
return if homework.blank? || course.blank?
|
||||||
|
|
||||||
|
attrs = %i[homework_common_id user_id created_at updated_at]
|
||||||
|
|
||||||
|
same_attrs = {homework_common_id: homework.id}
|
||||||
|
|
||||||
|
StudentWork.bulk_insert(*attrs) do |worker|
|
||||||
|
student_ids = course.students.pluck(:user_id)
|
||||||
|
|
||||||
|
student_ids.each do |user_id|
|
||||||
|
worker.add same_attrs.merge(user_id: user_id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -1,19 +1,39 @@
|
|||||||
class AddExerciseUserUpdate < ActiveRecord::Migration[5.2]
|
class AddExerciseUserUpdate < ActiveRecord::Migration[5.2]
|
||||||
include ExercisesHelper
|
|
||||||
def change
|
# include ExercisesHelper
|
||||||
# exs = Exercise.all.is_exercise_published.where("publish_time > ?",(Time.now - 2.months)).includes(:exercise_questions,:exercise_users)
|
# def change
|
||||||
# exs.each do |ex|
|
# #2019,8,22添加
|
||||||
# ex_users = ex.exercise_users.exercise_user_committed.where("end_at is not null and end_at > ?",(Time.now - 2.months))
|
# two_months = Time.now - 2.months
|
||||||
# if ex_users.present?
|
# exs = Exercise.all.is_exercise_published.where("publish_time > ?",two_months).includes(:exercise_questions,:exercise_users)
|
||||||
# ex_users.each do |ex_user|
|
# exs.each do |ex|
|
||||||
# calculate_score = calculate_student_score(ex,ex_user.user)[:total_score]
|
# if ex.exercise_questions.where("created_at < ?",Time.now - 1.month).pluck(:question_type).include?(1) #含有多选题,且是1个月前创建的才更新
|
||||||
# subjective_score = ex_user.subjective_score
|
# ex_users = ex.exercise_users.exercise_user_committed.where("end_at is not null and end_at > ?",two_months)
|
||||||
# total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score
|
# if ex_users.exists?
|
||||||
# total_score = calculate_score + total_score_subjective_score
|
# ex_users.each do |ex_user|
|
||||||
# ex_user.update_attributes(score:total_score,objective_score:calculate_score)
|
# calculate_score = calculate_student_score(ex,ex_user.user)[:total_score]
|
||||||
# puts ex_user.id
|
# subjective_score = ex_user.subjective_score
|
||||||
# end
|
# total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score
|
||||||
# end
|
# total_score = calculate_score + total_score_subjective_score
|
||||||
# end
|
# ex_user.update_attributes(score:total_score,objective_score:calculate_score)
|
||||||
end
|
# 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
|
end
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe CreateStudentWorkJob, type: :job do
|
||||||
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
|
end
|
Loading…
Reference in new issue