|
|
|
@ -12,7 +12,7 @@ namespace :subjects do
|
|
|
|
|
"school_used_count, created_at, updated_at"
|
|
|
|
|
subjects.find_in_batches(batch_size: 50) do |s|
|
|
|
|
|
str = []
|
|
|
|
|
Parallel.each_with_index(s, in_processes: 4) do |subject, index|
|
|
|
|
|
Parallel.each_with_index(s, in_processes: 6) do |subject, index|
|
|
|
|
|
puts("---------------------data_statistic: #{subject.id}")
|
|
|
|
|
Rails.logger.info("---------------------data_statistic: #{subject.id}")
|
|
|
|
|
data = Subjects::DataStatisticService.new(subject)
|
|
|
|
@ -80,12 +80,11 @@ namespace :subjects do
|
|
|
|
|
puts("---------------------shixun_info_statistic_begin")
|
|
|
|
|
Rails.logger.info("---------------------shixun_info_statistic_begin")
|
|
|
|
|
subjects = Subject.where(status: 2, hidden: 0)
|
|
|
|
|
str = ""
|
|
|
|
|
buffer_size = 0
|
|
|
|
|
column_value = "subject_id, shixun_id, stage, shixun_name, challenge_count, course_count, " +
|
|
|
|
|
"school_count, used_count, passed_count, evaluate_count, passed_ave_time, created_at, updated_at"
|
|
|
|
|
subjects.find_in_batches(batch_size: 50) do |s|
|
|
|
|
|
Parallel.each_with_index(s, in_processes: 4) do |subject|
|
|
|
|
|
str = []
|
|
|
|
|
Parallel.each_with_index(s, in_processes: 6) do |subject|
|
|
|
|
|
puts("---------------------shixun_info_statistic: #{subject.id}")
|
|
|
|
|
Rails.logger.info("---------------------shixun_info_statistic: #{subject.id}")
|
|
|
|
|
data = Subjects::ShixunUsedInfoService.call(subject)
|
|
|
|
@ -96,21 +95,20 @@ namespace :subjects do
|
|
|
|
|
"#{key[:course_count]}, #{key[:school_count]}, #{key[:used_count]}, #{key[:passed_count]}, " +
|
|
|
|
|
"#{key[:evaluate_count]}, #{key[:passed_ave_time]}, " +
|
|
|
|
|
"'#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')")
|
|
|
|
|
buffer_size += 1
|
|
|
|
|
if buffer_size == 1000 || key == data.last
|
|
|
|
|
sql = "REPLACE INTO subject_shixun_infos(#{column_value}) VALUES #{str}"
|
|
|
|
|
if str.size == 1000
|
|
|
|
|
sql = "REPLACE INTO subject_shixun_infos(#{column_value}) VALUES #{str.uniq.join(",")}"
|
|
|
|
|
str_c = str
|
|
|
|
|
puts sql
|
|
|
|
|
ActiveRecord::Base.connection.execute sql
|
|
|
|
|
str = ""
|
|
|
|
|
buffer_size = 0
|
|
|
|
|
str -= str_c
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
if buffer_size > 0
|
|
|
|
|
sql = "REPLACE INTO subject_shixun_infos(#{column_value}) VALUES #{str}"
|
|
|
|
|
puts sql
|
|
|
|
|
ActiveRecord::Base.connection.execute sql
|
|
|
|
|
if str.size > 0
|
|
|
|
|
sql = "REPLACE INTO subject_shixun_infos(#{column_value}) VALUES #{str.uniq.join(",")}"
|
|
|
|
|
puts sql
|
|
|
|
|
ActiveRecord::Base.connection.execute sql
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
puts("---------------------shixun_info_statistic_end")
|
|
|
|
|
Rails.logger.info("---------------------shixun_info_statistic_end")
|
|
|
|
|