You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
educoder/lib/tasks/static_all.rake

25 lines
1.3 KiB

5 years ago
desc "统计每个学校使用数据"
namespace :static_all do
task :repo => :environment do
5 years ago
school_alls = School.includes(courses: [:homework_commons, :attachments, :course_videos], user_extensions: :user).all
5 years ago
proc_num = ENV['processes'].blank? ? 5 : ENV['processes'].to_i
5 years ago
school_alls.find_in_batches(batch_size: 50) do |schools|
5 years ago
Parallel.each(schools, in_processes: proc_num) do |school|
5 years ago
puts("school_id: #{school.id}")
data = Schools::SchoolStatisticService.new(school)
sta_all = StaAll.find_or_initialize_by(school_id: school.id)
attrs = {tea_count: data.teacher_count, stu_count: data.student_count, courses_count: data.courses_count,
active_users_count: data.acitve_user_3_months_count, curr_courses_count: data.curr_courses_count,
homw_shixuns_count: data.homw_shixuns_count, homw_other_count: data.homw_other_count,
sources_count: data.sources_count, videos_count: data.videos_count, shixuns_count: data.shixuns_count,
myshixuns_count: data.myshixuns_count, mys_passed_count: data.pass_myshixun_count,
games_count: data.games_count, games_passed_count: data.pass_games_count, build_count: data.evaluate_count}
puts "sta_all: #{attrs}"
sta_all.assign_attributes(attrs)
sta_all.save!
end
5 years ago
end
5 years ago
5 years ago
end
end