|
|
@ -11,24 +11,26 @@ namespace :subjects do
|
|
|
|
str = []
|
|
|
|
str = []
|
|
|
|
puts("Parallel.worker_number: #{Parallel.worker_number}")
|
|
|
|
puts("Parallel.worker_number: #{Parallel.worker_number}")
|
|
|
|
subjects.find_in_batches(start: (Parallel.worker_number/4) * subjects.count,
|
|
|
|
subjects.find_in_batches(start: (Parallel.worker_number/4) * subjects.count,
|
|
|
|
finish: ((Parallel.worker_number+1)/4) * subjects.count) do |subject|
|
|
|
|
finish: ((Parallel.worker_number+1)/4) * subjects.count) do |s|
|
|
|
|
puts("---------------------data_statistic: #{subject.id}")
|
|
|
|
s.each do |subject|
|
|
|
|
Rails.logger.info("---------------------data_statistic: #{subject.id}")
|
|
|
|
puts("---------------------data_statistic: #{subject.id}")
|
|
|
|
data = Subjects::DataStatisticService.new(subject)
|
|
|
|
Rails.logger.info("---------------------data_statistic: #{subject.id}")
|
|
|
|
study_count = data.study_count
|
|
|
|
data = Subjects::DataStatisticService.new(subject)
|
|
|
|
next if study_count == 0
|
|
|
|
study_count = data.study_count
|
|
|
|
course_study_count = data.course_study_count
|
|
|
|
next if study_count == 0
|
|
|
|
initiative_study = study_count - course_study_count
|
|
|
|
course_study_count = data.course_study_count
|
|
|
|
str << ("(#{subject.id}, #{study_count}, #{course_study_count}, #{initiative_study}, " +
|
|
|
|
initiative_study = study_count - course_study_count
|
|
|
|
"#{data.passed_count}, #{data.course_used_count}, #{data.school_used_count}, " +
|
|
|
|
str << ("(#{subject.id}, #{study_count}, #{course_study_count}, #{initiative_study}, " +
|
|
|
|
"'#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')")
|
|
|
|
"#{data.passed_count}, #{data.course_used_count}, #{data.school_used_count}, " +
|
|
|
|
puts "index: #{index}; worker_number: #{Parallel.worker_number}"
|
|
|
|
"'#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')")
|
|
|
|
puts "####str: #{str}"
|
|
|
|
puts "index: #{index}; worker_number: #{Parallel.worker_number}"
|
|
|
|
if str.size == 50 || subject == s.last
|
|
|
|
puts "####str: #{str}"
|
|
|
|
sql = "REPLACE INTO subject_records(#{column_value}) VALUES #{str.uniq.join(",")}"
|
|
|
|
if str.size == 50 || subject == s.last
|
|
|
|
puts sql
|
|
|
|
sql = "REPLACE INTO subject_records(#{column_value}) VALUES #{str.uniq.join(",")}"
|
|
|
|
ActiveRecord::Base.connection.execute sql
|
|
|
|
puts sql
|
|
|
|
str = []
|
|
|
|
ActiveRecord::Base.connection.execute sql
|
|
|
|
|
|
|
|
str = []
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|