diff --git a/app/controllers/admins/dashboards_controller.rb b/app/controllers/admins/dashboards_controller.rb index 3971971ff..0d88d0440 100644 --- a/app/controllers/admins/dashboards_controller.rb +++ b/app/controllers/admins/dashboards_controller.rb @@ -1,10 +1,33 @@ class Admins::DashboardsController < Admins::BaseController def index - @active_user_count = User.where(last_login_on: today).count - @weekly_active_user_count = User.where(last_login_on: current_week).count - @month_active_user_count = User.where(last_login_on: current_month).count + # 用户活跃数 + day_user_ids = CommitLog.where(created_at: today).pluck(:project_id).uniq + weekly_user_ids = CommitLog.where(created_at: current_week).pluck(:project_id).uniq + month_user_ids = CommitLog.where(created_at: current_month).pluck(:project_id).uniq + @active_user_count = User.where(last_login_on: today).or(User.where(id: day_user_ids)).count + @weekly_active_user_count = User.where(last_login_on: current_week).or(User.where(id: weekly_user_ids)).count + @month_active_user_count = User.where(last_login_on: current_month).or(User.where(id: month_user_ids)).count + user_ids = User.where(created_on: pre_week).pluck(:id).uniq + weekly_keep_user_count = User.where(id: user_ids).where(last_login_on: current_week).count + @weekly_keep_rate = format("%.2f", weekly_keep_user_count > 0 ? weekly_keep_user_count / weekly_keep_user_count : 0) - @new_user_count = User.where(created_on: current_month).count + # 新用户注册数 + @day_new_user_count = User.where(created_on: today).count + @weekly_new_user_count = User.where(created_on: current_week).count + @month_new_user_count = User.where(created_on: current_month).count + + # 活跃项目数 + day_project_ids = CommitLog.where(created_at: today).pluck(:project_id).uniq + weekly_project_ids = CommitLog.where(created_at: current_week).pluck(:project_id).uniq + month_project_ids = CommitLog.where(created_at: current_month).pluck(:project_id).uniq + @day_active_project_count = Project.where(updated_on: today).or(Project.where(id: day_project_ids)).count + @weekly_active_project_count = Project.where(updated_on: current_week).or(Project.where(id: weekly_project_ids)).count + @month_active_project_count = Project.where(updated_on: current_month).or(Project.where(id: month_project_ids)).count + + # 新增项目数 + @day_new_project_count = User.where(created_on: today).count + @weekly_new_project_count = User.where(created_on: current_week).count + @month_new_project_count = User.where(created_on: current_month).count end def month_active_user @@ -48,4 +71,8 @@ class Admins::DashboardsController < Admins::BaseController def current_month 30.days.ago.beginning_of_day..Time.now.end_of_day end + + def pre_week + 14.days.ago.beginning_of_day..7.days.ago.beginning_of_day + end end \ No newline at end of file diff --git a/app/views/admins/dashboards/index.html.erb b/app/views/admins/dashboards/index.html.erb index e02c307a5..649c00904 100644 --- a/app/views/admins/dashboards/index.html.erb +++ b/app/views/admins/dashboards/index.html.erb @@ -2,217 +2,57 @@ <% add_admin_breadcrumb('概览', admins_path) %> <% end %> -
-
-
- -
-
-
-
-
-
-
当日活跃用户
- <%= @active_user_count %> -
-
-
- -
-
-
- - - - -
-
-
-
-
-
-
-
-
7天内活跃用户数
- <%= @weekly_active_user_count %> -
-
-
- -
-
-
- - - - -
-
-
-
-
-
-
-
-
30天内活跃用户数
- <%= @month_active_user_count %> -
-
-
- -
-
-
- - - - -
-
-
-
-
-
-
-
-
30天内新增用户数
- <%= @new_user_count %> -
-
-
- -
-
-
- - - - -
-
-
-
-
-
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
指标名称当日数七日内30日内周用户留存率
+ + <%=@active_user_count %><%=@weekly_active_user_count %><%=@month_active_user_count %><%="#{@weekly_keep_rate.to_f * 100 }%" %>
+ + <%=@day_new_user_count %><%=@weekly_new_user_count %><%=@month_new_user_count %><%="--" %>
+ + <%=@day_active_project_count %><%=@weekly_new_project_count %><%=@month_new_project_count %><%="--" %>
+ + <%=@day_new_project_count %><%=@weekly_new_user_count %><%=@month_new_user_count %><%="--" %>
- -
-
-
-
- - - - - - - - -
-
- -
-
-
-
-
30天内新增用户
-
-
-
-
-
-
-
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - <%# 5.times do %> - - - - - - - - - <%# end %> - - - - - - - - - - - - - - - - - - - - - - - - - - - - <%# 5.times do %> - - - - - - - - - - - - - - - - - - - <%# end %> - - - - - - - \ No newline at end of file +
+
\ No newline at end of file