modify school active user count

pre_develop
p31729568 6 years ago
parent f0d41767e7
commit c389f0f2a6

@ -0,0 +1,3 @@
class SchoolDailyActiveUser < ActiveRecord::Base
belongs_to :school_daily_report
end

@ -1,3 +1,5 @@
class SchoolDailyReport < ActiveRecord::Base
belongs_to :school
has_many :school_daily_active_users, dependent: :delete_all
end

@ -6,7 +6,7 @@ class Management::SchoolDataGrowService
attr_reader :params
sort_columns :teacher_increase_count, :student_increase_count,
:course_increase_count, :shixun_increase_count, :active_user_count,
:course_increase_count, :shixun_increase_count, :uniq_active_user_count,
:shixun_homework_count, :shixun_evaluate_count,
default_by: :teacher_increase_count, default_direction: :desc
@ -27,6 +27,7 @@ class Management::SchoolDataGrowService
'SUM(shixun_increase_count) shixun_increase_count,'\
'SUM(shixun_homework_count) shixun_homework_count,'\
'SUM(shixun_evaluate_count) shixun_evaluate_count,'\
'COUNT(distinct(au.user_id)) uniq_active_user_count,'\
'SUM(active_user_count) active_user_count'
)
@ -45,6 +46,7 @@ class Management::SchoolDataGrowService
'SUM(shixun_increase_count) shixun_increase_count,'\
'SUM(shixun_homework_count) shixun_homework_count,'\
'SUM(shixun_evaluate_count) shixun_evaluate_count,'\
'COUNT(distinct(au.user_id)) uniq_active_user_count,'\
'SUM(active_user_count) active_user_count'
).first
end
@ -60,6 +62,7 @@ class Management::SchoolDataGrowService
end
reports = School.joins("LEFT JOIN school_daily_reports sdr ON sdr.school_id = schools.id AND #{date_condition}")
reports = reports.joins("LEFT JOIN school_daily_active_users au ON au.school_daily_report_id = sdr.id")
keyword = params[:keyword].try(:to_s).try(:strip)
if keyword.present?

@ -9,7 +9,9 @@ class StatisticSchoolDailyReportTask
student_count = users.where(created_on: yesterday, user_extensions: { identity: User::STUDENT }).count
# 活跃用户
active_user_count = users.where(last_login_on: yesterday).count
active_user_ids = users.where(last_login_on: yesterday).pluck(:id)
active_user_count = active_user_ids.size
# 新增课堂
course_count = school.courses.where(created_at: yesterday).count
@ -38,7 +40,10 @@ class StatisticSchoolDailyReportTask
shixun_homework_count: shixun_homework_count, shixun_evaluate_count: shixun_evaluate_count,
shixun_increase_count: shixun_count, active_user_count: active_user_count, date: current_date
}
SchoolDailyReport.create!(create_params)
report = SchoolDailyReport.create!(create_params)
values = '(' + active_user_ids.join(", #{report.id}),(") + ", #{report.id})"
user_sql = "INSERT INTO school_daily_active_users(user_id, school_daily_report_id) VALUES#{values}"
SchoolDailyActiveUser.connection.execute(user_sql)
end
end

@ -12,7 +12,9 @@
新增实训<span class="color-red"><%= @grow_summary.shixun_increase_count || 0 %></span>个,
新增实训作业<span class="color-red"><%= @grow_summary.shixun_homework_count || 0 %></span>个,
新增实训评测<span class="color-red"><%= @grow_summary.shixun_evaluate_count || 0 %></span>个,
活跃用户<span class="color-red"><%= @grow_summary.active_user_count || 0 %></span>个
活跃用户<span class="color-red">
<%= @grow_summary.uniq_active_user_count.to_i.zero? ? @grow_summary.active_user_count.to_i : @grow_summary.uniq_active_user_count.to_i %>
</span>个
</div>
<table class="edu-pop-table edu-txt-center" cellpadding="0" cellspacing="0" style="table-layout: fixed">
<thead>
@ -27,7 +29,7 @@
<th width="12%"><%= sort_tag('新增实训', name: 'shixun_increase_count', path: school_data_grow_managements_path) %></th>
<th width="12%"><%= sort_tag('新增实训作业', name: 'shixun_homework_count', path: school_data_grow_managements_path) %></th>
<th width="12%"><%= sort_tag('新增实训评测', name: 'shixun_evaluate_count', path: school_data_grow_managements_path) %></th>
<th width="12%"><%= sort_tag('活跃用户', name: 'active_user_count', path: school_data_grow_managements_path) %></th>
<th width="12%"><%= sort_tag('活跃用户', name: 'uniq_active_user_count', path: school_data_grow_managements_path) %></th>
</tr>
</thead>
<tbody>
@ -42,7 +44,7 @@
<td><%= report.shixun_increase_count.to_i %></td>
<td><%= report.shixun_homework_count.to_i %></td>
<td><%= report.shixun_evaluate_count.to_i %></td>
<td><%= report.active_user_count.to_i %></td>
<td><%= report.uniq_active_user_count.to_i.zero? ? report.active_user_count.to_i : report.uniq_active_user_count.to_i %></td>
</tr>
<% end %>
</tbody>

@ -0,0 +1,10 @@
class CreateSchoolDailyActiveUsers < ActiveRecord::Migration
def change
create_table :school_daily_active_users do |t|
t.integer :school_daily_report_id
t.integer :user_id
end
add_index :school_daily_active_users, :school_daily_report_id
end
end
Loading…
Cancel
Save