diff --git a/app/controllers/admins/issues_rank_controller.rb b/app/controllers/admins/issues_rank_controller.rb new file mode 100644 index 000000000..530678ad5 --- /dev/null +++ b/app/controllers/admins/issues_rank_controller.rb @@ -0,0 +1,29 @@ +class Admins::IssuesRankController < Admins::BaseController + + def index + @statistics = DailyProjectStatistic.where('date >= ? AND date <= ?', begin_date, end_date) + @statistics = @statistics.group(:project_id).joins(:project).select("project_id, + sum(issues) as issues, + sum(closed_issues) as closed_issues, + projects.issues_count as issues_count") + @statistics = @statistics.order("#{sort_by} #{sort_direction}").limit(50) + end + + private + def begin_date + params.fetch(:begin_date, (Date.today-7.days).to_s) + end + + def end_date + params.fetch(:end_date, Date.today.to_s) + end + + def sort_by + DailyProjectStatistic.column_names.include?(params.fetch(:sort_by, "issues")) ? params.fetch(:sort_by, "issues") : "issues" + end + + def sort_direction + %w(desc asc).include?(params.fetch(:sort_direction, "desc")) ? params.fetch(:sort_direction, "desc") : "desc" + end + +end \ No newline at end of file diff --git a/app/jobs/daily_project_statistics_job.rb b/app/jobs/daily_project_statistics_job.rb index ad606f137..3672d1924 100644 --- a/app/jobs/daily_project_statistics_job.rb +++ b/app/jobs/daily_project_statistics_job.rb @@ -13,6 +13,7 @@ class DailyProjectStatisticsJob < ApplicationJob praises = result["praises"].to_i forks = result["forks"].to_i issues = result["issues"].to_i + closed_issues = result["closed_issues"].to_i pullrequests = result["pullrequests"].to_i commits = result["commits"].to_i score = visits *1 + watchers *5 + praises * 5 + forks * 10 + issues *5 + pullrequests * 10 + commits * 5 @@ -25,6 +26,7 @@ class DailyProjectStatisticsJob < ApplicationJob praises: praises, forks: forks, issues: issues, + closed_issues: closed_issues, pullrequests: pullrequests, commits: commits ) diff --git a/app/models/daily_project_statistic.rb b/app/models/daily_project_statistic.rb index f7fc0aad7..ffe51bdb3 100644 --- a/app/models/daily_project_statistic.rb +++ b/app/models/daily_project_statistic.rb @@ -2,18 +2,20 @@ # # Table name: daily_project_statistics # -# id :integer not null, primary key -# project_id :integer -# date :string(255) -# visits :integer default("0") -# watchers :integer default("0") -# praises :integer default("0") -# forks :integer default("0") -# issues :integer default("0") -# pullrequests :integer default("0") -# commits :integer default("0") -# created_at :datetime not null -# updated_at :datetime not null +# id :integer not null, primary key +# project_id :integer +# date :date +# score :integer default("0") +# visits :integer default("0") +# watchers :integer default("0") +# praises :integer default("0") +# forks :integer default("0") +# issues :integer default("0") +# pullrequests :integer default("0") +# commits :integer default("0") +# created_at :datetime not null +# updated_at :datetime not null +# closed_issues :integer default("0") # # Indexes # diff --git a/app/views/admins/issues_rank/index.html.erb b/app/views/admins/issues_rank/index.html.erb new file mode 100644 index 000000000..b52076966 --- /dev/null +++ b/app/views/admins/issues_rank/index.html.erb @@ -0,0 +1,37 @@ +<% define_admin_breadcrumbs do %> + <% add_admin_breadcrumb('项目排行榜', admins_path) %> +<% end %> + + +
排名 | +项目 | +新增疑修数 | +关闭疑修数 | +当前疑修数量 | +
---|---|---|---|---|
<%= index + 1%> | ++ "> + <%= "#{item&.project&.owner&.real_name}/#{item&.project&.name}" %> + + | +<%= item&.issues %> | +<%= item&.closed_issues %> | +<%= item&.issues_count %> | +