新增:项目疑修排行榜

This commit is contained in:
yystopf 2024-01-16 10:19:02 +08:00
parent 7d813c0ebe
commit 1c8811fda6
9 changed files with 116 additions and 12 deletions

View File

@ -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

View File

@ -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
)

View File

@ -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
#

View File

@ -0,0 +1,37 @@
<% define_admin_breadcrumbs do %>
<% add_admin_breadcrumb('项目排行榜', admins_path) %>
<% end %>
<div class="box search-form-container user-list-form">
<%= form_tag(admins_issues_rank_index_path, method: :get, class: 'form-inline search-form flex-1', id: 'issue-rank-date-form') do %>
<div class="input-group">
<span class="input-group-text">开始日期</span>
<input class="form-control datetimepicker" type="text" name="begin_date" value="<%= params[:begin_date] || (Date.today - 7.days).to_s%>" aria-label="选择日期">
</div>
<div class="input-group">
<span class="input-group-text">截止日期</span>
<input class="form-control datetimepicker" type="text" name="end_date" value="<%= params[:end_date] || Date.today.to_s%>" aria-label="选择日期">
</div>
<% end %>
</div>
<div class="box admin-list-container issue-rank-list-container">
<%= render partial: 'admins/issues_rank/shared/data_list', locals: { statistics: @statistics } %>
</div>
<script>
$(".datetimepicker").on('change', function() {
$("#issue-rank-date-form").submit()
});
$(".datetimepicker").on('change', function() {
$("#issue-rank-date-form").submit()
});
$('.datetimepicker').datetimepicker({
language: 'zh-CN', // 中文语言包
autoclose: 1, // 选中日期后自动关闭
format: 'yyyy-mm-dd', // 日期格式
minView: "month", // 最小日期显示单元,这里最小显示月份界面,即可以选择到日
todayBtn: 1, // 显示今天按钮
todayHighlight: 1, // 显示今天高亮
});
</script>

View File

@ -0,0 +1 @@
$('.issue-rank-list-container').html("<%= j( render partial: 'admins/issues_rank/shared/data_list', locals: { statistics: @statistics } ) %>");

View File

@ -0,0 +1,26 @@
<table class="table table-hover text-center subject-list-table">
<thead class="thead-light">
<tr>
<th width="20%">排名</th>
<th width="20%">项目</th>
<th width="20%">新增疑修数</th>
<th width="20%">关闭疑修数</th>
<th width="20%">当前疑修数量</th>
</tr>
</thead>
<tbody>
<% statistics.each_with_index do |item, index| %>
<tr class="">
<td><%= index + 1%></td>
<td>
<a target="_blank" href="<%= "/#{item&.project&.owner&.login}/#{item&.project&.identifier}"%>">
<%= "#{item&.project&.owner&.real_name}/#{item&.project&.name}" %>
</a>
</td>
<td><%= item&.issues %></td>
<td><%= item&.closed_issues %></td>
<td><%= item&.issues_count %></td>
</tr>
<% end %>
</tbody>
</table>

View File

@ -81,6 +81,7 @@
<%= sidebar_item_group('#rank-submenu', '活跃度排行', icon: 'calendar') do %>
<li><%= sidebar_item(admins_users_rank_index_path, '用户活跃度排行', icon: 'user', controller: 'admins-users_rank') %></li>
<li><%= sidebar_item(admins_projects_rank_index_path, '项目活跃度排行', icon: 'database', controller: 'admins-projects_rank') %></li>
<li><%= sidebar_item(admins_issues_rank_index_path, '疑修活跃度排行', icon: 'database', controller: 'admins-issues_rank') %></li>
<% end %>
</li>

View File

@ -822,6 +822,7 @@ Rails.application.routes.draw do
resources :identity_verifications
resources :site_pages
resources :page_themes
resources :issues_rank, only: [:index]
resources :projects_rank, only: [:index]
resources :sites
resources :edu_settings

View File

@ -0,0 +1,5 @@
class AddClosedIssuesToDailyProjectStatistics < ActiveRecord::Migration[5.2]
def change
add_column :daily_project_statistics, :closed_issues, :integer, default: 0
end
end