diff --git a/app/controllers/admins/projects_rank_controller.rb b/app/controllers/admins/projects_rank_controller.rb
new file mode 100644
index 000000000..b92037caa
--- /dev/null
+++ b/app/controllers/admins/projects_rank_controller.rb
@@ -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
\ No newline at end of file
diff --git a/app/controllers/admins/users_rank_controller.rb b/app/controllers/admins/users_rank_controller.rb
new file mode 100644
index 000000000..2c7a62ae5
--- /dev/null
+++ b/app/controllers/admins/users_rank_controller.rb
@@ -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
\ No newline at end of file
diff --git a/app/services/cache/v2/project_date_rank_service.rb b/app/services/cache/v2/project_date_rank_service.rb
index 9d8ffca90..2ada442a8 100644
--- a/app/services/cache/v2/project_date_rank_service.rb
+++ b/app/services/cache/v2/project_date_rank_service.rb
@@ -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)
diff --git a/app/views/admins/projects_rank/index.html.erb b/app/views/admins/projects_rank/index.html.erb
new file mode 100644
index 000000000..056e0a0da
--- /dev/null
+++ b/app/views/admins/projects_rank/index.html.erb
@@ -0,0 +1,74 @@
+<% define_admin_breadcrumbs do %>
+ <% add_admin_breadcrumb('项目排行榜', admins_path) %>
+<% end %>
+
+
+
+
+
+
+
+
+ 排名 |
+ 项目 |
+ 得分 |
+ 访问数 |
+ 关注数 |
+ 点赞数 |
+ fork数 |
+ 疑修数 |
+ 合并请求数 |
+ 提交数 |
+
+
+
+ <% @date_rank.each_with_index do |item, index| %>
+
+ <%= index + 1%> |
+ <% project_common = $redis_cache.hgetall("v2-project-common:#{item[0]}") %>
+ <% owner_common = $redis_cache.hgetall("v2-owner-common:#{project_common["owner_id"]}")%>
+
+ /<%= project_common["identifier"]%>">
+ <%= project_common["name"] %>
+
+ |
+
+ <%= item[1] %> |
+ <% 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") %>
+ <%= visits || 0 %> |
+ <% watchers = $redis_cache.hget(project_date_statistic_key, "watchers") %>
+ <%= watchers || 0 %> |
+ <% praises = $redis_cache.hget(project_date_statistic_key, "praises") %>
+ <%= praises || 0 %> |
+ <% forks = $redis_cache.hget(project_date_statistic_key, "forks") %>
+ <%= forks || 0 %> |
+ <% issues = $redis_cache.hget(project_date_statistic_key, "issues") %>
+ <%= issues || 0 %> |
+ <% pullrequests = $redis_cache.hget(project_date_statistic_key, "pullrequests") %>
+ <%= pullrequests || 0 %> |
+ <% commits = $redis_cache.hget(project_date_statistic_key, "commits") %>
+ <%= commits || 0 %> |
+ <% else %>
+ 暂无数据 |
+ <% end %>
+
+ <% end %>
+
+
+
+
\ No newline at end of file
diff --git a/app/views/admins/shared/_sidebar.html.erb b/app/views/admins/shared/_sidebar.html.erb
index afd0dad68..fb96f088e 100644
--- a/app/views/admins/shared/_sidebar.html.erb
+++ b/app/views/admins/shared/_sidebar.html.erb
@@ -14,6 +14,12 @@
- <%= sidebar_item(admins_path, '概览', icon: 'dashboard', controller: 'admins-dashboards') %>
+ -
+ <%= sidebar_item_group('#user-submenu', '排行榜', icon: 'user') do %>
+
- <%= sidebar_item(admins_users_rank_index_path, '用户排行榜', icon: 'user', controller: 'admins-users_rank') %>
+ - <%= sidebar_item(admins_projects_rank_index_path, '项目排行榜', icon: 'user', controller: 'admins-projects_rank') %>
+ <% end %>
+
-
<%= sidebar_item_group('#user-submenu', '用户', icon: 'user') do %>
- <%= sidebar_item(admins_users_path, '用户列表', icon: 'user', controller: 'admins-users') %>
diff --git a/app/views/admins/users_rank/index.html.erb b/app/views/admins/users_rank/index.html.erb
new file mode 100644
index 000000000..9fa5a5aec
--- /dev/null
+++ b/app/views/admins/users_rank/index.html.erb
@@ -0,0 +1,74 @@
+<% define_admin_breadcrumbs do %>
+ <% add_admin_breadcrumb('用户排行榜', admins_path) %>
+<% end %>
+
+
+
+
+
+
+
+
+ 排名 |
+ 用户 |
+ 得分 |
+ 影响力 |
+ 贡献度 |
+ 活跃度 |
+ 项目经验 |
+ 语言能力 |
+
+
+
+ <% @date_rank.each_with_index do |item, index| %>
+
+ <%= index + 1%> |
+ <% owner_common = $redis_cache.hgetall("v2-owner-common:#{item[0]}")%>
+
+ ">
+ <%= owner_common["name"] %>
+
+ |
+ <% 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%>
+ <%= score %> |
+ <%= influence%> |
+ <%= contribution%> |
+ <%= activity%> |
+ <%= experience%> |
+ <%= language%> |
+
+ <% end %>
+
+
+
+
\ No newline at end of file
diff --git a/config/routes.rb b/config/routes.rb
index 22773794c..dc538d93f 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -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