更改:项目排行榜查询丰富
This commit is contained in:
parent
0cb38bce4f
commit
75fff13550
|
@ -1,16 +1,77 @@
|
|||
class Admins::ProjectsRankController < Admins::BaseController
|
||||
|
||||
before_action :get_timeable_key_names, only:[:index]
|
||||
def index
|
||||
@rank_date = rank_date
|
||||
deleted_data = $redis_cache.smembers("v2-project-rank-deleted")
|
||||
$redis_cache.zrem("v2-project-rank-#{rank_date}", deleted_data) unless deleted_data.blank?
|
||||
@date_rank = $redis_cache.zrevrange("v2-project-rank-#{rank_date}", 0, -1, withscores: true)
|
||||
puts @names_array
|
||||
unless @names_array.blank?
|
||||
$redis_cache.zunionstore("admin-days-project-rank", @names_array)
|
||||
deleted_data = $redis_cache.smembers("v2-project-rank-deleted")
|
||||
$redis_cache.zrem("admin-days-project-rank", deleted_data) unless deleted_data.blank?
|
||||
@date_rank = $redis_cache.zrevrange("admin-days-project-rank", 0, -1, withscores: true)
|
||||
@date_rank = @date_rank.map do |i|
|
||||
visits = 0
|
||||
watchers = 0
|
||||
praises = 0
|
||||
forks = 0
|
||||
issues = 0
|
||||
pullrequests = 0
|
||||
commits = 0
|
||||
(begin_date..end_date).to_a.each do |d|
|
||||
result = $redis_cache.hgetall("v2-project-statistic:#{i[0]}-#{d}")
|
||||
visits += result["visits"].to_i
|
||||
watchers += result["watchers"].to_i
|
||||
praises += result["praises"].to_i
|
||||
forks += result["forks"].to_i
|
||||
issues += result["issues"].to_i
|
||||
pullrequests += result["pullrequests"].to_i
|
||||
commits += result["commits"].to_i
|
||||
end
|
||||
i + [visits,watchers,praises,forks,issues,pullrequests,commits]
|
||||
end
|
||||
case params[:sort_by]
|
||||
when 'visits'
|
||||
@date_rank = @date_rank.sort{|i| i[2]}
|
||||
when 'watchers'
|
||||
@date_rank = @date_rank.sort{|i| i[3]}
|
||||
when 'praises'
|
||||
@date_rank = @date_rank.sort{|i| i[4]}
|
||||
when 'forks'
|
||||
@date_rank = @date_rank.sort{|i| i[5]}
|
||||
when 'issues'
|
||||
@date_rank = @date_rank.sort{|i| i[6]}
|
||||
when 'pullrequests'
|
||||
@date_rank = @date_rank.sort{|i| i[7]}
|
||||
when 'commits'
|
||||
@date_rank = @date_rank.sort{|i| i[8]}
|
||||
else
|
||||
@date_rank = @date_rank.sort{|i| i[1]}
|
||||
end
|
||||
if params[:sort_direction].blank? || params[:sort_direction].to_s.downcase == "desc"
|
||||
@date_rank = @date_rank.reverse
|
||||
end
|
||||
else
|
||||
@date_rank = []
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def rank_date
|
||||
params.fetch(:date, Date.today.to_s)
|
||||
def begin_date
|
||||
params.fetch(:begin_date, Date.today.to_s)
|
||||
end
|
||||
|
||||
def end_date
|
||||
params.fetch(:end_date, Date.today.to_s)
|
||||
end
|
||||
|
||||
def get_timeable_key_names
|
||||
begin
|
||||
@names_array = []
|
||||
(begin_date..end_date).to_a.each do |i|
|
||||
@names_array << "v2-project-rank-#{i}"
|
||||
end
|
||||
rescue
|
||||
@names_array = []
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -6,69 +6,27 @@
|
|||
<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>
|
||||
<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")%>
|
||||
<%= select_tag(:begin_date, options_for_select(dates_array, params[:begin_date]), class:"form-control",id: "project-rank-begin-date-select")%>
|
||||
</div>
|
||||
<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(:end_date, options_for_select(dates_array, params[:end_date]), class:"form-control",id: "project-rank-end-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="30%">项目</th>
|
||||
<th width="10%">得分</th>
|
||||
<th width="10%">访问数</th>
|
||||
<th width="10%">关注数</th>
|
||||
<th width="10%">点赞数</th>
|
||||
<th width="10%">fork数</th>
|
||||
<th width="10%">疑修数</th>
|
||||
<th width="10%">合并请求数</th>
|
||||
<th width="10%">提交数</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"]%>">
|
||||
<%= "#{owner_common["name"]}/#{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 class="box admin-list-container project-rank-list-container">
|
||||
<%= render partial: 'admins/projects_rank/shared/data_list', locals: { date_rank: @date_rank } %>
|
||||
</div>
|
||||
<script>
|
||||
$("#project-rank-date-select").on('change', function() {
|
||||
$("#project-rank-begin-date-select").on('change', function() {
|
||||
$("#project-rank-date-form").submit()
|
||||
});
|
||||
$("#project-rank-end-date-select").on('change', function() {
|
||||
$("#project-rank-date-form").submit()
|
||||
});
|
||||
</script>
|
|
@ -0,0 +1 @@
|
|||
$('.project-rank-list-container').html("<%= j( render partial: 'admins/projects_rank/shared/data_list', locals: { date_rank: @date_rank } ) %>");
|
|
@ -0,0 +1,39 @@
|
|||
<table class="table table-hover text-center subject-list-table">
|
||||
<thead class="thead-light">
|
||||
<tr>
|
||||
<th width="20%">排名</th>
|
||||
<th width="30%">项目</th>
|
||||
<th width="10%">得分</th>
|
||||
<th width="10%"><%= sort_tag('访问数', name: 'visits', path: admins_projects_rank_index_path) %></th>
|
||||
<th width="10%"><%= sort_tag('关注数', name: 'watchers', path: admins_projects_rank_index_path) %></th>
|
||||
<th width="10%"><%= sort_tag('点赞数', name: 'praises', path: admins_projects_rank_index_path) %></th>
|
||||
<th width="10%"><%= sort_tag('fork数', name: 'forks', path: admins_projects_rank_index_path) %></th>
|
||||
<th width="10%"><%= sort_tag('疑修数', name: 'issues', path: admins_projects_rank_index_path) %></th>
|
||||
<th width="10%"><%= sort_tag('合并请求数', name: 'pullrequests', path: admins_projects_rank_index_path) %></th>
|
||||
<th width="10%"><%= sort_tag('提交数', name: 'commits', path: admins_projects_rank_index_path) %></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"]%>">
|
||||
<%= "#{owner_common["name"]}/#{project_common["name"]}" %>
|
||||
</a>
|
||||
</td>
|
||||
|
||||
<td><%= item[1] %></td>
|
||||
<td><%= item[2] %></td>
|
||||
<td><%= item[3] %></td>
|
||||
<td><%= item[4] %></td>
|
||||
<td><%= item[5] %></td>
|
||||
<td><%= item[6] %></td>
|
||||
<td><%= item[7] %></td>
|
||||
<td><%= item[8] %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
Loading…
Reference in New Issue