Merge branch 'dev_aliyun' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun

Adjustreact
caicai8 5 years ago
commit a1aa512c23

2
.gitignore vendored

@ -43,7 +43,7 @@
/public/react/config/stats.json
/public/react/stats.json
/public/react/.idea/*
/public/h5build
/public/npm-debug.log
# avatars

@ -0,0 +1,11 @@
class MigrateUserLocation < ActiveRecord::Migration[5.2]
def change
UserExtension.where("location like '%省'").each do |ue|
ue.update_column("location", ue.location.chop)
end
UserExtension.where("location_city like '%市'").each do |ue|
ue.update_column("location_city", ue.location_city.chop)
end
end
end

@ -5,12 +5,14 @@ namespace :subjects do
puts("---------------------data_statistic_begin")
Rails.logger.info("---------------------data_statistic_begin")
subjects = Subject.where(status: 2, hidden: 0)
str = ""
buffer_size = 0
column_value = "subject_id, study_count, course_study_count, initiative_study, passed_count, course_used_count, " +
"school_used_count, created_at, updated_at"
subjects.find_in_batches(batch_size: 50) do |s|
str = ""
buffer_size = 0
Parallel.each(s, in_processes: 4) do |subject|
buffer_size += 1
str += ", " unless str.empty?
puts("---------------------data_statistic: #{subject.id}")
Rails.logger.info("---------------------data_statistic: #{subject.id}")
data = Subjects::DataStatisticService.new(subject)
@ -18,12 +20,11 @@ namespace :subjects do
next if study_count == 0
course_study_count = data.course_study_count
initiative_study = study_count - course_study_count
str += ", " unless str.empty?
str += ("(#{subject.id}, #{study_count}, #{course_study_count}, #{initiative_study}, " +
"#{data.passed_count}, #{data.course_used_count}, #{data.school_used_count}, " +
"'#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')")
buffer_size += 1
puts "buffer_size: #{buffer_size}; subject: #{subject == s.last}; index:#{index+1}"
puts "buffer_size: #{buffer_size}; subject_id: #{subject.id}; s: #{s.last}; subject: #{subject == s.last};"
puts "####str: #{str}"
if buffer_size == 1000 || subject == s.last
sql = "REPLACE INTO subject_records(#{column_value}) VALUES #{str}"
puts sql
@ -56,14 +57,14 @@ namespace :subjects do
puts("---------------------course_info_statistic: #{subject.id}")
Rails.logger.info("---------------------course_info_statistic: #{subject.id}")
data = Subjects::CourseUsedInfoService.call(subject)
Parallel.map_with_index(data) do |key, index|
data.each do |key|
next if key[:school_id].nil?
str += ", " unless str.empty?
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')}')")
buffer_size += 1
if buffer_size == 1000 || (index + 1) == data.size
if buffer_size == 1000 || key == data.last
sql = "REPLACE INTO subject_course_records(#{column_value}) VALUES #{str}"
puts sql
ActiveRecord::Base.connection.execute sql
@ -95,7 +96,7 @@ namespace :subjects do
puts("---------------------shixun_info_statistic: #{subject.id}")
Rails.logger.info("---------------------shixun_info_statistic: #{subject.id}")
data = Subjects::ShixunUsedInfoService.call(subject)
data.each_with_index do |key, index|
data.each do |key|
next if key[:shixun_id].nil?
str += ", " unless str.empty?
str += ("(#{subject.id}, #{key[:shixun_id]}, '#{key[:stage]}', '#{key[:name]}', #{key[:challenge_count]}, " +
@ -103,7 +104,7 @@ namespace :subjects do
"#{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 || (index+1) == data.size
if buffer_size == 1000 || key == data.last
sql = "REPLACE INTO subject_shixun_infos(#{column_value}) VALUES #{str}"
puts sql
ActiveRecord::Base.connection.execute sql
@ -142,7 +143,7 @@ namespace :subjects do
"#{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')}')")
buffer_size += 1
if buffer_size == 1000 || (index+1 == data.size)
if buffer_size == 1000 || (key == data.last)
sql = "REPLACE INTO subject_user_infos(#{column_value}) VALUES #{str}"
ActiveRecord::Base.connection.execute sql
str = ""

Loading…
Cancel
Save