diff --git a/app/controllers/admins/dashboards_controller.rb b/app/controllers/admins/dashboards_controller.rb index 3971971ff..5ac1508d1 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", user_ids.size > 0 ? weekly_keep_user_count.to_f / user_ids.size : 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 = Project.where(created_on: today).count + @weekly_new_project_count = Project.where(created_on: current_week).count + @month_new_project_count = Project.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/controllers/commit_logs_controller.rb b/app/controllers/commit_logs_controller.rb new file mode 100644 index 000000000..c02d199b0 --- /dev/null +++ b/app/controllers/commit_logs_controller.rb @@ -0,0 +1,25 @@ +class CommitLogsController < ApplicationController + + def create + tip_exception "未认证" unless params[:token].to_s == "7917908927b6f1b792f2027a08a8b24a2de42c1692c2fd45da0dee5cf90a5af5" + ref = params[:ref] + commit_id = params[:commits][0][:id] + message = params[:commits][0][:message] + user_name = params[:pusher][:login] + user_mail = params[:pusher][:email] + user = User.find_by(mail: user_mail) + user = User.find_by(login: user_name) if user.blank? + + repository_id = params[:repository][:id] + repository_name = params[:repository][:name] + repository_full_name = params[:repository][:full_name] + owner_name = repository_full_name.split("/")[0] + owner = User.find_by(login: owner_name) + project = Project.where(identifier: repository_name).where(user_id: owner&.id)&.first + project = Project.where(identifier: repository_name).where(gpid: repository_id)&.first if project.blank? + CommitLog.create(user: user, project: project, repository_id: repository_id, + name: repository_name, full_name: repository_full_name, + ref: ref, commit_id: commit_id, message: message) + + end +end diff --git a/app/models/commit_log.rb b/app/models/commit_log.rb new file mode 100644 index 000000000..9b51b0631 --- /dev/null +++ b/app/models/commit_log.rb @@ -0,0 +1,6 @@ +class CommitLog < ApplicationRecord + belongs_to :user + belongs_to :project + belongs_to :repository + +end diff --git a/app/views/admins/dashboards/index.html.erb b/app/views/admins/dashboards/index.html.erb index e02c307a5..2d86b4b6c 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 %> -
指标名称 | +当日数 | +七日内 | +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_active_project_count %> | +<%=@month_active_project_count %> | +<%="--" %> | +
+ + | +<%=@day_new_project_count %> | +<%=@weekly_new_project_count %> | +<%=@month_new_project_count %> | +<%="--" %> | +