forked from Gitlink/forgeplus
Merge branch 'develop' into standalone_develop
This commit is contained in:
commit
08d8abd163
|
@ -0,0 +1,14 @@
|
|||
class Admins::ProjectsRankController < Admins::BaseController
|
||||
|
||||
def index
|
||||
@rank_date = rank_date
|
||||
@date_rank = $redis_cache.zrevrange("v2-project-rank-#{rank_date}", 0, -1, withscores: true)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def rank_date
|
||||
params.fetch(:date, Date.today.to_s)
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
class Admins::UsersRankController < Admins::BaseController
|
||||
|
||||
def index
|
||||
@rank_date = rank_date
|
||||
@date_rank = $redis_cache.zrevrange("v2-user-rank-#{rank_date}", 0, -1, withscores: true)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def rank_date
|
||||
params.fetch(:date, Date.today.to_s)
|
||||
end
|
||||
|
||||
|
||||
end
|
|
@ -28,6 +28,10 @@ class Cache::V2::ProjectDateRankService < ApplicationService
|
|||
"v2-project-rank-#{@rank_date.to_s}"
|
||||
end
|
||||
|
||||
def project_rank_statistic_key
|
||||
"v2-project-statistic:#{@project_id}-#{@rank_date.to_s}"
|
||||
end
|
||||
|
||||
def project_rank
|
||||
$redis_cache.zscore(project_rank_key, @project_id)
|
||||
end
|
||||
|
@ -35,24 +39,31 @@ class Cache::V2::ProjectDateRankService < ApplicationService
|
|||
def set_project_rank
|
||||
if @visits.present?
|
||||
$redis_cache.zincrby(project_rank_key, @visits.to_i * 1, @project_id)
|
||||
$redis_cache.hincrby(project_rank_statistic_key, "visits", @visits.to_i)
|
||||
end
|
||||
if @watchers.present?
|
||||
$redis_cache.zincrby(project_rank_key, @watchers.to_i * 5, @project_id)
|
||||
$redis_cache.hincrby(project_rank_statistic_key, "watchers", @watchers.to_i)
|
||||
end
|
||||
if @praises.present?
|
||||
$redis_cache.zincrby(project_rank_key, @praises.to_i * 5, @project_id)
|
||||
$redis_cache.hincrby(project_rank_statistic_key, "praises", @praises.to_i)
|
||||
end
|
||||
if @forks.present?
|
||||
$redis_cache.zincrby(project_rank_key, @forks.to_i * 10, @project_id)
|
||||
$redis_cache.hincrby(project_rank_statistic_key, "forks", @forks.to_i)
|
||||
end
|
||||
if @issues.present?
|
||||
$redis_cache.zincrby(project_rank_key, @issues.to_i * 5, @project_id)
|
||||
$redis_cache.hincrby(project_rank_statistic_key, "issues", @issues.to_i)
|
||||
end
|
||||
if @pullrequests.present?
|
||||
$redis_cache.zincrby(project_rank_key, @pullrequests.to_i * 10, @project_id)
|
||||
$redis_cache.hincrby(project_rank_statistic_key, "pullrequests", @pullrequests.to_i)
|
||||
end
|
||||
if @commits.present?
|
||||
$redis_cache.zincrby(project_rank_key, @commits.to_i * 5, @project_id)
|
||||
$redis_cache.hincrby(project_rank_statistic_key, "commits", @commits.to_i)
|
||||
end
|
||||
|
||||
$redis_cache.zscore(project_rank_key, @project_id)
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
<% define_admin_breadcrumbs do %>
|
||||
<% add_admin_breadcrumb('项目排行榜', admins_path) %>
|
||||
<% end %>
|
||||
|
||||
|
||||
<div class="box search-form-container user-list-form">
|
||||
<%= form_tag(admins_projects_rank_index_path, method: :get, class: 'form-inline search-form flex-1', id: 'project-rank-date-form') do %>
|
||||
<div class="form-group mr-2">
|
||||
<label for="status">日期:</label>
|
||||
<% dates_array = (0..30).to_a.map { |item| [(Date.today-item.days).to_s, (Date.today-item.days).to_s] } %>
|
||||
<%= select_tag(:date, options_for_select(dates_array, params[:date]), class:"form-control",id: "project-rank-date-select")%>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="box admin-list-container project-language-list-container">
|
||||
<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>
|
||||
<th width="20%">点赞数</th>
|
||||
<th width="20%">fork数</th>
|
||||
<th width="20%">疑修数</th>
|
||||
<th width="20%">合并请求数</th>
|
||||
<th width="20%">提交数</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @date_rank.each_with_index do |item, index| %>
|
||||
<tr class="">
|
||||
<td><%= index + 1%></td>
|
||||
<% project_common = $redis_cache.hgetall("v2-project-common:#{item[0]}") %>
|
||||
<% owner_common = $redis_cache.hgetall("v2-owner-common:#{project_common["owner_id"]}")%>
|
||||
<td>
|
||||
<a href="/<%= owner_common["login"] %>/<%= project_common["identifier"]%>">
|
||||
<%= project_common["name"] %>
|
||||
</a>
|
||||
</td>
|
||||
|
||||
<td><%= item[1] %></td>
|
||||
<% project_date_statistic_key = "v2-project-statistic:#{item[0]}-#{@rank_date}"%>
|
||||
<% if $redis_cache.exists(project_date_statistic_key)%>
|
||||
<% visits = $redis_cache.hget(project_date_statistic_key, "visits") %>
|
||||
<td><%= visits || 0 %></td>
|
||||
<% watchers = $redis_cache.hget(project_date_statistic_key, "watchers") %>
|
||||
<td><%= watchers || 0 %></td>
|
||||
<% praises = $redis_cache.hget(project_date_statistic_key, "praises") %>
|
||||
<td><%= praises || 0 %></td>
|
||||
<% forks = $redis_cache.hget(project_date_statistic_key, "forks") %>
|
||||
<td><%= forks || 0 %></td>
|
||||
<% issues = $redis_cache.hget(project_date_statistic_key, "issues") %>
|
||||
<td><%= issues || 0 %></td>
|
||||
<% pullrequests = $redis_cache.hget(project_date_statistic_key, "pullrequests") %>
|
||||
<td><%= pullrequests || 0 %></td>
|
||||
<% commits = $redis_cache.hget(project_date_statistic_key, "commits") %>
|
||||
<td><%= commits || 0 %></td>
|
||||
<% else %>
|
||||
<td colspan="7">暂无数据</td>
|
||||
<% end %>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<script>
|
||||
$("#project-rank-date-select").on('change', function() {
|
||||
$("#project-rank-date-form").submit()
|
||||
});
|
||||
</script>
|
|
@ -14,6 +14,12 @@
|
|||
<!-- Sidebar Links -->
|
||||
<ul class="list-unstyled components">
|
||||
<li><%= sidebar_item(admins_path, '概览', icon: 'dashboard', controller: 'admins-dashboards') %></li>
|
||||
<li>
|
||||
<%= sidebar_item_group('#user-submenu', '排行榜', icon: 'user') 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: 'user', controller: 'admins-projects_rank') %></li>
|
||||
<% end %>
|
||||
</li>
|
||||
<li>
|
||||
<%= sidebar_item_group('#user-submenu', '用户', icon: 'user') do %>
|
||||
<li><%= sidebar_item(admins_users_path, '用户列表', icon: 'user', controller: 'admins-users') %></li>
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
<% define_admin_breadcrumbs do %>
|
||||
<% add_admin_breadcrumb('用户排行榜', admins_path) %>
|
||||
<% end %>
|
||||
|
||||
|
||||
<div class="box search-form-container user-list-form">
|
||||
<%= form_tag(admins_users_rank_index_path, method: :get, class: 'form-inline search-form flex-1', id: 'user-rank-date-form') do %>
|
||||
<div class="form-group mr-2">
|
||||
<label for="status">日期:</label>
|
||||
<% dates_array = (0..30).to_a.map { |item| [(Date.today-item.days).to_s, (Date.today-item.days).to_s] } %>
|
||||
<%= select_tag(:date, options_for_select(dates_array, params[:date]), class:"form-control",id: "user-rank-date-select")%>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="box admin-list-container project-language-list-container">
|
||||
<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>
|
||||
<th width="20%">活跃度</th>
|
||||
<th width="20%">项目经验</th>
|
||||
<th width="20%">语言能力</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @date_rank.each_with_index do |item, index| %>
|
||||
<tr class="">
|
||||
<td><%= index + 1%></td>
|
||||
<% owner_common = $redis_cache.hgetall("v2-owner-common:#{item[0]}")%>
|
||||
<td>
|
||||
<a href="/<%= owner_common["login"] %>">
|
||||
<%= owner_common["name"] %>
|
||||
</a>
|
||||
</td>
|
||||
<% user_date_statistic_key = "v2-user-statistic:#{item[0]}-#{@rank_date}"%>
|
||||
<% follow_count = $redis_cache.hget(user_date_statistic_key, "follow-count") || 0 %>
|
||||
<% pullrequest_count = $redis_cache.hget(user_date_statistic_key, "pullrequest-count") || 0 %>
|
||||
<% issues_count = $redis_cache.hget(user_date_statistic_key, "issue-count") || 0 %>
|
||||
<% project_count = $redis_cache.hget(user_date_statistic_key, "project-count") || 0 %>
|
||||
<% fork_count = $redis_cache.hget(user_date_statistic_key, "fork-count") || 0 %>
|
||||
<% project_watchers_count = $redis_cache.hget(user_date_statistic_key, "project-watcher-count") || 0 %>
|
||||
<% project_praises_count = $redis_cache.hget(user_date_statistic_key, "project-praise-count") || 0 %>
|
||||
<% project_language = $redis_cache.hget(user_date_statistic_key, "project-language") %>
|
||||
<% project_languages_count = project_language.nil? || project_language == "{}" ? 0 : JSON.parse(project_language).length %>
|
||||
|
||||
<% influence = (60.0 + follow_count.to_i / (follow_count.to_i + 20.0) * 40.0).to_i %>
|
||||
<% contribution = (60.0 + pullrequest_count.to_i / (pullrequest_count.to_i + 20.0) * 40.0).to_i %>
|
||||
<% activity = (60.0 + issues_count.to_i / (issues_count.to_i + 80.0) * 40.0).to_i %>
|
||||
<% experience = 10 * project_count.to_i + 5 * fork_count.to_i + project_watchers_count.to_i + project_praises_count.to_i %>
|
||||
<% experience = (60.0 + experience / (experience + 100.0) * 40.0).to_i %>
|
||||
<% language = (60.0 + project_languages_count.to_i / (project_languages_count.to_i + 5.0) * 40.0).to_i %>
|
||||
<% score = influence+ contribution + activity + experience + language%>
|
||||
<td><%= score %></td>
|
||||
<td><%= influence%></td>
|
||||
<td><%= contribution%></td>
|
||||
<td><%= activity%></td>
|
||||
<td><%= experience%></td>
|
||||
<td><%= language%></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<script>
|
||||
$("#user-rank-date-select").on('change', function() {
|
||||
$("#user-rank-date-form").submit()
|
||||
});
|
||||
</script>
|
|
@ -761,6 +761,8 @@ Rails.application.routes.draw do
|
|||
get :visits_static
|
||||
end
|
||||
end
|
||||
resources :users_rank, only: [:index]
|
||||
resources :projects_rank, only: [:index]
|
||||
resources :sites
|
||||
resources :edu_settings
|
||||
resources :project_languages
|
||||
|
|
Loading…
Reference in New Issue