From 69b9cbee80125e0c1043a87d036f69caa5cc4d3e Mon Sep 17 00:00:00 2001
From: huang
Date: Fri, 24 Jul 2015 16:56:37 +0800
Subject: [PATCH 1/2] =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=BA=93=E4=BB=A3?=
=?UTF-8?q?=E7=A0=81=E7=BB=9F=E8=AE=A1=EF=BC=88=E6=9C=AA=E5=AE=8C=E6=88=90?=
=?UTF-8?q?=EF=BC=89?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/views/repositories/stats.html.erb | 8 ++++++++
config/locales/zh.yml | 4 +++-
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/app/views/repositories/stats.html.erb b/app/views/repositories/stats.html.erb
index ebb670438..ba14e18b1 100644
--- a/app/views/repositories/stats.html.erb
+++ b/app/views/repositories/stats.html.erb
@@ -25,5 +25,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_code_six_months")) %>
+
+
+ <%# 用户最近一年的代码量 %>
+ <%= 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_code_year")) %>
+
<%= 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 9b3254bb2..a5f4f4d10 100644
--- a/config/locales/zh.yml
+++ b/config/locales/zh.yml
@@ -716,8 +716,10 @@ zh:
label_commits_per_month: 每月提交次数
label_commits_per_author: 每用户提交次数
label_author_commits_per_month: 用户最近一月的提交次数
- label_author_commits_six_month: 用户最近六个月的提交次数
+ label_author_commits_six_month: 用户最近六个月提交次数
label_author_commits_year: 最近一年的提交次数
+ label_author_code_six_month: 用户最近六个月代码量
+ label_author_code_year: 用户最近一年代码量
label_view_diff: 查看差别
label_diff_inline: 直列
label_diff_side_by_side: 并排
From ea93a68a84137bbc3787922130c411cfcfbf3848 Mon Sep 17 00:00:00 2001
From: huang
Date: Fri, 24 Jul 2015 17:40:43 +0800
Subject: [PATCH 2/2] =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=BA=93=EF=BC=9A?=
=?UTF-8?q?=E7=94=A8=E6=88=B7=E5=85=AD=E4=B8=AA=E6=9C=88=E4=BB=A3=E7=A0=81?=
=?UTF-8?q?=E9=87=8F=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 | 43 ++++++++++++++++++++++
1 file changed, 43 insertions(+)
diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb
index 717007f54..fc05b082d 100644
--- a/app/controllers/repositories_controller.rb
+++ b/app/controllers/repositories_controller.rb
@@ -465,6 +465,8 @@ update
data = author_commits_six_month(@repository)
when "author_qoc_per_author"
data = graph_author_qoc_per_author(@repository)
+ when "author_code_six_months"
+ data = author_code_six_month(@repository)
end
if data
headers["Content-Type"] = "image/svg+xml"
@@ -696,6 +698,47 @@ update
graph.burn
end
+ # 最近六个月代码量统计
+ def author_code_six_month(repository)
+ @date_to = Date.today
+ @date_from = @date_to << 6
+ @date_from = Date.civil(@date_from.year, @date_from.month, @date_from.day)
+ commits_by_author = Changeset.count(: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)
+ all_author = []
+ commits_by_author.each do |cba|
+ all_author << cba.first
+ end
+ all_author = all_author.collect {|c| c.gsub(%r{<.+@.+>}, '') }
+ commits_by_author = repository.commits(all_author, @date_from, @date_to)
+
+ fields = commits_by_author.collect {|r| r.first}
+ commits_data = commits_by_author.collect {|r| r.last}
+
+ fields = fields + [""]*(10 - fields.length) if fields.length<10
+ commits_data = commits_data + [0]*(10 - commits_data.length) if commits_data.length<10
+
+ # Remove email adress in usernames
+ fields = fields.collect {|c| c.gsub(%r{<.+@.+>}, '') }
+
+ graph = SVG::Graph::BarHorizontal.new(
+ :height => 400,
+ :width => 600,
+ :fields => fields,
+ :stack => :side,
+ :scale_integers => true,
+ :show_data_values => true,
+ :rotate_y_labels => false,
+ :graph_title => l(:label_author_commits_six_month),
+ :show_graph_title => true
+ )
+ graph.add_data(
+ :data => commits_data,
+ :title => l(:label_revision_plural)
+ )
+ graph.burn
+ end
+
def check_hidden_repo
project = Project.find(params[:id])