|
|
|
@ -57,13 +57,13 @@ namespace :subjects do
|
|
|
|
|
str << ("(#{subject.id}, #{key[:school_id]}, '#{key[:school_name]}', #{key[:course_count]}, " +
|
|
|
|
|
"#{key[:student_count]}, #{key[:choice_shixun_num]}, #{key[:choice_shixun_frequency]}, " +
|
|
|
|
|
"'#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')")
|
|
|
|
|
if str.size == 1000
|
|
|
|
|
sql = "REPLACE INTO subject_course_records(#{column_value}) VALUES #{str.uniq.join(",")}"
|
|
|
|
|
str_c = str
|
|
|
|
|
puts sql
|
|
|
|
|
ActiveRecord::Base.connection.execute sql
|
|
|
|
|
str -= str_c
|
|
|
|
|
end
|
|
|
|
|
# if str.size == 1000
|
|
|
|
|
# sql = "REPLACE INTO subject_course_records(#{column_value}) VALUES #{str.uniq.join(",")}"
|
|
|
|
|
# str_c = str
|
|
|
|
|
# puts sql
|
|
|
|
|
# ActiveRecord::Base.connection.execute sql
|
|
|
|
|
# str -= str_c
|
|
|
|
|
# end
|
|
|
|
|
end
|
|
|
|
|
if str.size > 0
|
|
|
|
|
sql = "REPLACE INTO subject_course_records(#{column_value}) VALUES #{str.uniq.join(",")}"
|
|
|
|
@ -96,11 +96,11 @@ 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')}')")
|
|
|
|
|
if str.size == 1000
|
|
|
|
|
sql = "REPLACE INTO subject_shixun_infos(#{column_value}) VALUES #{str.join(",")}"
|
|
|
|
|
puts sql
|
|
|
|
|
ActiveRecord::Base.connection.execute sql
|
|
|
|
|
end
|
|
|
|
|
# if str.size == 1000
|
|
|
|
|
# sql = "REPLACE INTO subject_shixun_infos(#{column_value}) VALUES #{str.join(",")}"
|
|
|
|
|
# puts sql
|
|
|
|
|
# ActiveRecord::Base.connection.execute sql
|
|
|
|
|
# end
|
|
|
|
|
end
|
|
|
|
|
if str.size > 0
|
|
|
|
|
sql = "REPLACE INTO subject_shixun_infos(#{column_value}) VALUES #{str.join(",")}"
|
|
|
|
@ -119,7 +119,7 @@ namespace :subjects do
|
|
|
|
|
subjects = Subject.where(status: 2, hidden: 0)
|
|
|
|
|
column_value = "user_id, subject_id, username, passed_myshixun_count, passed_games_count, " +
|
|
|
|
|
"code_line_count, evaluate_count, cost_time, created_at, updated_at"
|
|
|
|
|
subjects.find_in_batches(batch_size: 50) do |s|
|
|
|
|
|
subjects.find_in_batches(batch_size: 20) do |s|
|
|
|
|
|
Parallel.each_with_index(s, in_processes: 4) do |subject, index, str = []|
|
|
|
|
|
puts("---------------------user_info_statistic: #{subject.id}")
|
|
|
|
|
data = Subjects::UserUsedInfoService.call(subject)
|
|
|
|
@ -127,10 +127,11 @@ namespace :subjects do
|
|
|
|
|
str << ("(#{key[:user_id]}, #{subject.id}, '#{key[:name].gsub(/'/, '"')}', #{key[:passed_myshixun_count]}, " +
|
|
|
|
|
"#{key[:passed_games_count]}, #{key[:code_line_count]}, #{key[:evaluate_count]}, #{key[:cost_time]}, " +
|
|
|
|
|
"'#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')")
|
|
|
|
|
if str.size == 1000
|
|
|
|
|
sql = "REPLACE INTO subject_user_infos(#{column_value}) VALUES #{str.join(",")}"
|
|
|
|
|
ActiveRecord::Base.connection.execute sql
|
|
|
|
|
end
|
|
|
|
|
# if str.size == 1000
|
|
|
|
|
# sql = "REPLACE INTO subject_user_infos(#{column_value}) VALUES #{str.join(",")}"
|
|
|
|
|
# ActiveRecord::Base.connection.execute sql
|
|
|
|
|
# str = []
|
|
|
|
|
# end
|
|
|
|
|
end
|
|
|
|
|
if str.size > 0
|
|
|
|
|
sql = "REPLACE INTO subject_user_infos(#{column_value}) VALUES #{str.join(",")}"
|
|
|
|
|