|
|
|
@ -1,36 +1,41 @@
|
|
|
|
|
desc "统计实践课程的学习统计数据"
|
|
|
|
|
|
|
|
|
|
namespace :subjects do
|
|
|
|
|
buffer_size = 1000
|
|
|
|
|
task data_statistic: :environment do
|
|
|
|
|
puts("---------------------data_statistic_begin")
|
|
|
|
|
Rails.logger.info("---------------------data_statistic_begin")
|
|
|
|
|
subjects = Subject.where(status: 2)
|
|
|
|
|
str = ""
|
|
|
|
|
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)
|
|
|
|
|
#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)
|
|
|
|
|
unless course_study_count == sr.course_study_count &&
|
|
|
|
|
passed_count == sr.passed_count &&
|
|
|
|
|
course_used_count == sr.course_used_count &&
|
|
|
|
|
school_used_count == sr.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")
|
|
|
|
|
end
|
|
|
|
@ -39,6 +44,9 @@ namespace :subjects do
|
|
|
|
|
puts("---------------------course_info_statistic_begin")
|
|
|
|
|
Rails.logger.info("---------------------course_info_statistic_begin")
|
|
|
|
|
subjects = Subject.where(status: 2)
|
|
|
|
|
str = ""
|
|
|
|
|
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}")
|
|
|
|
|