From 127a243bd27b49d54f8e0da24357bd1931e0522e Mon Sep 17 00:00:00 2001
From: huang
Date: Fri, 24 Jul 2015 09:18:34 +0800
Subject: [PATCH] =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=BA=93=EF=BC=9A=E7=94=A8?=
=?UTF-8?q?=E6=88=B7=E6=9C=80=E8=BF=91=E4=B8=80=E6=9C=88=E6=8F=90=E4=BA=A4?=
=?UTF-8?q?=E6=AC=A1=E6=95=B0=E7=BB=9F=E8=AE=A1?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/controllers/repositories_controller.rb | 25 ++++++++++++----------
app/views/repositories/stats.html.erb | 8 +++++++
config/locales/zh.yml | 2 ++
3 files changed, 24 insertions(+), 11 deletions(-)
diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb
index f71d11802..cabc88f6b 100644
--- a/app/controllers/repositories_controller.rb
+++ b/app/controllers/repositories_controller.rb
@@ -461,6 +461,8 @@ update
data = graph_commits_per_author(@repository)
when "author_commits_per_month"
data = graph_author_commits_per_month(@repository)
+ when "author_commits_six_month"
+ data = author_commits_six_month(@repository)
when "author_qoc_per_author"
data = graph_author_qoc_per_author(@repository)
end
@@ -540,15 +542,12 @@ update
def graph_commits_per_month(repository)
@date_to = Date.today
@date_from = @date_to << 11
- @date_from = Date.civil(@date_from.year, @date_from.month, 1) ## Date.new(2001,2,-1) #=> #
- # commits_by_day[0] 为data 【2】为count
+ @date_from = Date.civil(@date_from.year, @date_from.month, 1)
commits_by_day = Changeset.count(
:all, :group => :commit_date,
:conditions => ["repository_id = ? AND commit_date BETWEEN ? AND ?", repository.id, @date_from, @date_to])
commits_by_month = [0] * 12
- commits_by_day.each do |c|
- commits_by_month[(@date_to.month - c.first.to_date.month) % 12] += c.last
- end
+ commits_by_day.each {|c| commits_by_month[(@date_to.month - c.first.to_date.month) % 12] += c.last }
changes_by_day = Change.count(
:all, :group => :commit_date, :include => :changeset,
@@ -627,10 +626,15 @@ update
# 用户每月提交次数
def graph_author_commits_per_month(repository)
- commits_by_author = Changeset.count(:all, :group => :committer, :conditions => ["repository_id = ?", repository.id])
- commits_by_author = commits_by_author.to_a.sort! {|x, y| x.last <=> y.last}.last(25)
-
- changes_by_author = Change.count(:all, :group => :committer, :include => :changeset, :conditions => ["#{Changeset.table_name}.repository_id = ?", repository.id])
+ @date_to = Date.today
+ @date_from = @date_to << 1
+ @date_from = Date.civil(@date_from.year, @date_from.month, 1)
+ commits_by_author = Changeset.count(:all, :group => :committer,
+ :conditions => ["#{Changeset.table_name}.repository_id = ? AND #{Changeset.table_name}.commit_date BETWEEN ? AND ?", repository.id, @date_from, @date_to])
+ commits_by_author = commits_by_author.to_a.sort! {|x, y| x.last <=> y.last}.last(40)
+
+ changes_by_author = Change.count(:all, :group => :committer, :include => :changeset,
+ :conditions => ["#{Changeset.table_name}.repository_id = ? AND #{Changeset.table_name}.commit_date BETWEEN ? AND ?", repository.id, @date_from, @date_to])
h = changes_by_author.inject({}) {|o, i| o[i.first] = i.last; o}
fields = commits_by_author.collect {|r| r.first}
@@ -666,9 +670,8 @@ update
graph.burn
end
- def graph_author_qoc_per_author(repository)
+
- end
def check_hidden_repo
project = Project.find(params[:id])
diff --git a/app/views/repositories/stats.html.erb b/app/views/repositories/stats.html.erb
index 0eb04b891..ebb670438 100644
--- a/app/views/repositories/stats.html.erb
+++ b/app/views/repositories/stats.html.erb
@@ -17,5 +17,13 @@
<%# 用户每月提交代码量 %>
<%= tag("embed", :width => 670, :height => 400, :type => "image/svg+xml", :src => url_for(:controller => 'repositories', :action => 'graph', :id => @project, :repository_id => @repository.identifier_param, :graph => "author_qoc_per_author")) %>
+
+ <%# 用户最近六个月的提交次数 %>
+ <%= tag("embed", :width => 670, :height => 400, :type => "image/svg+xml", :src => url_for(:controller => 'repositories', :action => 'graph', :id => @project, :repository_id => @repository.identifier_param, :graph => "author_commits_six_month")) %>
+
+
+ <%# 用户最近一年的提交次数 %>
+ <%= tag("embed", :width => 670, :height => 400, :type => "image/svg+xml", :src => url_for(:controller => 'repositories', :action => 'graph', :id => @project, :repository_id => @repository.identifier_param, :graph => "author_qoc_per_author")) %>
+
<%= link_to l(:button_back), :action => 'show', :id => @project %>
<% html_title(l(:label_repository), l(:label_statistics)) -%>
diff --git a/config/locales/zh.yml b/config/locales/zh.yml
index 2c628894e..14a00eb67 100644
--- a/config/locales/zh.yml
+++ b/config/locales/zh.yml
@@ -716,6 +716,8 @@ zh:
label_commits_per_month: 每月提交次数
label_commits_per_author: 每用户提交次数
label_author_commits_per_month: 用户最近一月的提交次数
+ label_author_commits_six_month: 用户最近六个月的提交次数
+ label_author_commits_year: 最近一年的提交次数
label_view_diff: 查看差别
label_diff_inline: 直列
label_diff_side_by_side: 并排