|
|
|
@ -5,26 +5,35 @@ namespace :subjects do
|
|
|
|
|
puts("---------------------data_statistic_begin")
|
|
|
|
|
Rails.logger.info("---------------------data_statistic_begin")
|
|
|
|
|
subjects = Subject.where(status: 2)
|
|
|
|
|
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_each do |subject|
|
|
|
|
|
puts("---------------------data_statistic: #{subject.id}")
|
|
|
|
|
Rails.logger.info("---------------------data_statistic: #{subject.id}")
|
|
|
|
|
sr = SubjectRecord.find_or_create_by!(subject_id: subject.id)
|
|
|
|
|
data = Subjects::DataStatisticService.new(subject)
|
|
|
|
|
study_count = data.study_count
|
|
|
|
|
# 总人数没有变化的话,不同课堂之类的变化了
|
|
|
|
|
course_study_count = (study_count == sr.study_count ? sr.course_study_count : data.course_study_count)
|
|
|
|
|
passed_count = (study_count == sr.study_count ? sr.passed_count : data.passed_count)
|
|
|
|
|
course_used_count = (study_count == sr.study_count ? sr.course_used_count : data.course_used_count)
|
|
|
|
|
school_used_count = (study_count == sr.study_count ? sr.school_used_count : data.school_used_count)
|
|
|
|
|
update_params = {
|
|
|
|
|
study_count: study_count,
|
|
|
|
|
course_study_count: course_study_count,
|
|
|
|
|
initiative_study: (study_count - course_study_count),
|
|
|
|
|
passed_count: passed_count,
|
|
|
|
|
course_used_count: course_used_count,
|
|
|
|
|
school_used_count: school_used_count
|
|
|
|
|
}
|
|
|
|
|
sr.update_attributes!(update_params)
|
|
|
|
|
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
|
|
|
|
|
if buffer_size == 1000
|
|
|
|
|
sql = "REPLACE INTO subject_records(#{column_value}) VALUES #{str}"
|
|
|
|
|
puts sql
|
|
|
|
|
ActiveRecord::Base.connection.execute sql
|
|
|
|
|
str = ""
|
|
|
|
|
buffer_size = 0
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
if buffer_size > 0
|
|
|
|
|
sql = "REPLACE INTO subject_records(#{column_value}) VALUES #{str}"
|
|
|
|
|
puts sql
|
|
|
|
|
ActiveRecord::Base.connection.execute sql
|
|
|
|
|
end
|
|
|
|
|
puts("---------------------data_statistic_end")
|
|
|
|
|
Rails.logger.info("---------------------data_statistic_end")
|
|
|
|
@ -34,22 +43,35 @@ namespace :subjects do
|
|
|
|
|
puts("---------------------course_info_statistic_begin")
|
|
|
|
|
Rails.logger.info("---------------------course_info_statistic_begin")
|
|
|
|
|
subjects = Subject.where(status: 2)
|
|
|
|
|
str = ""
|
|
|
|
|
buffer_size = 0
|
|
|
|
|
column_value = "subject_id, school_id, school_name, course_count, student_count, choice_shixun_num, " +
|
|
|
|
|
"choice_shixun_frequency, created_at, updated_at"
|
|
|
|
|
subjects.find_each do |subject|
|
|
|
|
|
puts("---------------------course_info_statistic: #{subject.id}")
|
|
|
|
|
Rails.logger.info("---------------------course_info_statistic: #{subject.id}")
|
|
|
|
|
data = Subjects::CourseUsedInfoService.call(subject)
|
|
|
|
|
data.each do |key|
|
|
|
|
|
scr = SubjectCourseRecord.find_or_create_by!(school_id: key[:school_id], subject_id: subject.id)
|
|
|
|
|
update_params = {
|
|
|
|
|
school_name: key[:school_name],
|
|
|
|
|
course_count: key[:course_count],
|
|
|
|
|
student_count: key[:student_count],
|
|
|
|
|
choice_shixun_num: key[:choice_shixun_num],
|
|
|
|
|
choice_shixun_frequency: key[:choice_shixun_frequency]
|
|
|
|
|
}
|
|
|
|
|
scr.update_attributes(update_params)
|
|
|
|
|
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
|
|
|
|
|
sql = "REPLACE INTO subject_course_records(#{column_value}) VALUES #{str}"
|
|
|
|
|
puts sql
|
|
|
|
|
ActiveRecord::Base.connection.execute sql
|
|
|
|
|
str = ""
|
|
|
|
|
buffer_size = 0
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
if buffer_size > 0
|
|
|
|
|
sql = "REPLACE INTO subject_course_records(#{column_value}) VALUES #{str}"
|
|
|
|
|
puts sql
|
|
|
|
|
ActiveRecord::Base.connection.execute sql
|
|
|
|
|
end
|
|
|
|
|
puts("---------------------course_info_statistic_end")
|
|
|
|
|
Rails.logger.info("---------------------course_info_statistic_end")
|
|
|
|
|
end
|
|
|
|
@ -58,26 +80,36 @@ namespace :subjects do
|
|
|
|
|
puts("---------------------shixun_info_statistic_begin")
|
|
|
|
|
Rails.logger.info("---------------------shixun_info_statistic_begin")
|
|
|
|
|
subjects = Subject.where(status: 2)
|
|
|
|
|
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_each(batch_size: 100) do |subject|
|
|
|
|
|
puts("---------------------shixun_info_statistic: #{subject.id}")
|
|
|
|
|
Rails.logger.info("---------------------shixun_info_statistic: #{subject.id}")
|
|
|
|
|
data = Subjects::ShixunUsedInfoService.call(subject)
|
|
|
|
|
data.each do |key|
|
|
|
|
|
ssi = SubjectShixunInfo.find_or_create_by!(shixun_id: key[:shixun_id], subject_id: subject.id)
|
|
|
|
|
update_params = {
|
|
|
|
|
stage: key[:stage],
|
|
|
|
|
shixun_name: key[:name],
|
|
|
|
|
challenge_count: key[:challenge_count],
|
|
|
|
|
course_count: key[:course_count],
|
|
|
|
|
school_count: key[:school_count],
|
|
|
|
|
used_count: key[:used_count],
|
|
|
|
|
passed_count: key[:passed_count],
|
|
|
|
|
evaluate_count: key[:evaluate_count],
|
|
|
|
|
passed_ave_time: key[:passed_ave_time]
|
|
|
|
|
}
|
|
|
|
|
ssi.update_attributes(update_params)
|
|
|
|
|
next if key[:shixun_id].nil?
|
|
|
|
|
str += ", " unless str.empty?
|
|
|
|
|
str += ("(#{subject.id}, #{key[:shixun_id]}, '#{key[:stage]}', '#{key[:name]}', #{key[:challenge_count]}, " +
|
|
|
|
|
"#{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
|
|
|
|
|
sql = "REPLACE INTO subject_shixun_infos(#{column_value}) VALUES #{str}"
|
|
|
|
|
puts sql
|
|
|
|
|
ActiveRecord::Base.connection.execute sql
|
|
|
|
|
str = ""
|
|
|
|
|
buffer_size = 0
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
if buffer_size > 0
|
|
|
|
|
sql = "REPLACE INTO subject_shixun_infos(#{column_value}) VALUES #{str}"
|
|
|
|
|
puts sql
|
|
|
|
|
ActiveRecord::Base.connection.execute sql
|
|
|
|
|
end
|
|
|
|
|
puts("---------------------shixun_info_statistic_end")
|
|
|
|
|
Rails.logger.info("---------------------shixun_info_statistic_end")
|
|
|
|
|
end
|
|
|
|
@ -86,22 +118,34 @@ namespace :subjects do
|
|
|
|
|
puts("---------------------user_info_statistic_begin")
|
|
|
|
|
Rails.logger.info("---------------------user_info_statistic_begin")
|
|
|
|
|
subjects = Subject.where(status: 2)
|
|
|
|
|
subjects.find_each(batch_size: 100) do |subject|
|
|
|
|
|
str = ""
|
|
|
|
|
buffer_size = 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_each(batch_size: 50) do |subject|
|
|
|
|
|
puts("---------------------user_info_statistic: #{subject.id}")
|
|
|
|
|
data = Subjects::UserUsedInfoService.call(subject)
|
|
|
|
|
data.each do |key|
|
|
|
|
|
sui = SubjectUserInfo.find_or_create_by!(user_id: key[:user_id], subject_id: subject.id)
|
|
|
|
|
update_params = {
|
|
|
|
|
username: key[:name],
|
|
|
|
|
passed_myshixun_count: key[:passed_myshixun_count],
|
|
|
|
|
passed_games_count: key[:passed_games_count],
|
|
|
|
|
code_line_count: key[:code_line_count],
|
|
|
|
|
evaluate_count: key[:evaluate_count],
|
|
|
|
|
cost_time: key[:cost_time]
|
|
|
|
|
}
|
|
|
|
|
sui.update_attributes(update_params)
|
|
|
|
|
next if key[:user_id].nil?
|
|
|
|
|
str += ", " unless str.empty?
|
|
|
|
|
str += ("(#{key[:user_id]}, #{subject.id}, '#{key[:name]}', '#{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')}')")
|
|
|
|
|
buffer_size += 1
|
|
|
|
|
if buffer_size == 1000
|
|
|
|
|
sql = "REPLACE INTO subject_user_infos(#{column_value}) VALUES #{str}"
|
|
|
|
|
puts sql
|
|
|
|
|
ActiveRecord::Base.connection.execute sql
|
|
|
|
|
str = ""
|
|
|
|
|
buffer_size = 0
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
if buffer_size > 0
|
|
|
|
|
sql = "REPLACE INTO subject_user_infos(#{column_value}) VALUES #{str}"
|
|
|
|
|
puts sql
|
|
|
|
|
ActiveRecord::Base.connection.execute sql
|
|
|
|
|
end
|
|
|
|
|
puts("---------------------user_info_statistic_end")
|
|
|
|
|
Rails.logger.info("---------------------user_info_statistic_end")
|
|
|
|
|
end
|
|
|
|
|