diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 517fa327c..c8b272480 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -319,9 +319,25 @@ class ProjectsController < ApplicationController else @events_pages = ForgeActivity.includes(:project).where("forge_activities.project_id = ? and projects.is_public = ? and forge_act_type != ? ",@project,1, "Document").order("created_at desc").page(params['page'|| 1]).per(10); end - g = Gitlab.client + # g = Gitlab.client unless @project.gpid.nil? || @project.project_score.changeset_num == 0 - @static_total_per_user = g.rep_stats(@project.gpid) + # rep_statics_commit = @project.rep_statics.order("commits_num desc") + rep_statics_commit = RepStatics.find_by_sql("SELECT * FROM `rep_statics` where project_id = #{@project.id} order by commits_num desc limit 10") + rep_statics_code = RepStatics.find_by_sql("SELECT * FROM `rep_statics` where project_id = #{@project.id} order by changeset desc limit 10") + # rep_statics_code = @project.rep_statics.sort_by {|u| u.changeset}.reverse + @a_uname = rep_statics_commit.map {|s| s.uname } + @a_uname_code = rep_statics_code.map {|s| s.uname } + @a_commits_num = rep_statics_commit.map {|s| s.commits_num.to_i } + @a_commits_add = rep_statics_code.map {|s| s.add.to_i } + @a_commits_del = rep_statics_code.map {|s| s.del.to_i } + @a_commits_changeset = rep_statics_code.map {|s| s.changeset.to_i } + g = Gitlab.client + begin + g_branch = g.project(@project.gpid).default_branch.to_s + rescue + logger.error("get gitlab project failed!") + end + @rev = g_branch.nil? ? "master" : g_branch end # 根据对应的请求,返回对应的数据 respond_to do |format| diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 82a6196cb..380e880ad 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -348,8 +348,10 @@ update # (show_error_not_found; return) unless @entries g = Gitlab.client @changesets = g.commits(@project.gpid, :ref_name => @rev) + g_project = g.project(@project.gpid) # 总的提交数 - @changesets_all_count = @project.gpid.nil? ? 0 : g.project(@project.gpid).commit_count + @changesets_all_count = @project.gpid.nil? ? 0 : g_project.commit_count + @g_default_branch = g_project.default_branch.nil? ? "master" : g_project.default_branch # 访问该页面的是会后则刷新 if @project.project_score.nil? ProjectScore.create(:project_id => @project.id, :score => false) @@ -573,7 +575,17 @@ update g = Gitlab.client begin @static_total_per_user = g.rep_stats(project_id, :rev => rev) - @static_total_per_user + # 更新rep_statics统计数 + @static_total_per_user.each do |static| + rep_static = RepStatics.where("project_id =? and email =?", @project.id, static.email.to_s).first + if rep_static.nil? + RepStatics.create(:project_id => @project.id, :uname => static.uname, :commits_num => static.commits_num, :email => static.email, :add => static.add, :del => static.del, :changeset => static.changes) + else + if @rev == params[:default_branch] + rep_static.update_attributes(:uname => static.uname, :commits_num => static.commits_num, :email => static.email, :add => static.add, :del => static.del, :changeset => static.changes) + end + end + end # @static_month__per_user = g.rep_stats(project_id, :rev => rev, :creator => creator, :period => 2) # @static_week_per_user = g.rep_stats(project_id, :rev => rev, :creator => creator, :period => 3) rescue diff --git a/app/models/project.rb b/app/models/project.rb index 184b3c7af..ceec0e182 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -115,6 +115,7 @@ class Project < ActiveRecord::Base has_many :org_projects,:dependent => :destroy has_many :organization,:through => :org_projects + has_many :rep_statics, :class_name => 'RepStatics' # has_many :journals diff --git a/app/models/rep_statics.rb b/app/models/rep_statics.rb new file mode 100644 index 000000000..584af6560 --- /dev/null +++ b/app/models/rep_statics.rb @@ -0,0 +1,4 @@ +class RepStatics < ActiveRecord::Base + belongs_to :project + attr_accessible :add, :commits_num, :del, :email, :project_id, :uname, :changeset +end diff --git a/app/views/projects/_rep_static.html.erb b/app/views/projects/_rep_static.html.erb index 0522fd34e..9ebf68d0c 100644 --- a/app/views/projects/_rep_static.html.erb +++ b/app/views/projects/_rep_static.html.erb @@ -10,14 +10,18 @@ type: 'line' }, title: { - text: '版本库代码提交量' + text: '版本库代码提交行数', + style:{ + fontSize: '14px' + } + }, subtitle: { // text: 'Source: WorldClimate.com' }, xAxis: { // categories: ["Jan", "Jan", "Jan", 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] - categories: <%= raw(@static_total_per_user.map{|c| c.uname}) %> + categories: <%= raw(@a_uname_code) %> }, yAxis: { title: { @@ -34,6 +38,12 @@ } }, plotOptions: { + series: { + marker: { + radius: 3, //曲线点半径,默认是4 + symbol: 'circle' //曲线点类型:"circle", "square", "diamond", "triangle","triangle-down",默认是"circle" + } + }, line: { dataLabels: { enabled: true @@ -41,21 +51,55 @@ enableMouseTracking: false } }, - series: [{ - name: '改动或增加', - color: '#fd9e04', - -// data: [7.0, 6.9, 9.5, 14.5, 18.4, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6] - data: <%= @static_total_per_user.map{|c| c.add.to_i} %> + series: [ + { + name: '总变更', + color: '#d05d5a', + fontWeight: 'normal', + data: <%= @a_commits_changeset %>, + dataLabels: { + enabled: false, + style: { + fontSize: '13px', + color: '#aaa', + fontFamily: 'Arial', + textShadow: '0px 0px 6px rgb(0, 0, 0), 0px 0px 3px rgb(f, f, f)', + fontWeight: 'normal' + } + }, + lineWidth: 1.5 + }, + { + name: '改动或增加', + color: '#5b6b76', + data: <%= @a_commits_add %>, + dataLabels: { + enabled: false, + style: { + fontSize: '13px', + color: '#aaa', + fontFamily: 'Arial', + textShadow: '0px 0px 6px rgb(0, 0, 0), 0px 0px 3px rgb(f, f, f)', + fontWeight: 'normal' + } + }, + lineWidth: 1.5 }, { - name: '删除', - color: '#46baed ', - data: <%= @static_total_per_user.map{|c| c.del.to_i} %> - },{ - name: '总变更', - color: '#d397d5', - data: <%= @static_total_per_user.map{|c| c.changes.to_i} %> + name: '删除', + color: '#84b5bb', + data: <%= @a_commits_del %>, + dataLabels: { + enabled: false, + style: { + fontSize: '13px', + color: '#aaa', + fontFamily: 'Arial', + textShadow: '0px 0px 6px rgb(0, 0, 0), 0px 0px 3px rgb(f, f, f)', + fontWeight: 'normal' + } + }, + lineWidth: 1.5 }] }); @@ -68,14 +112,18 @@ enabled: false }, title: { - text: '版本库代码提交次数' + text: '版本库代码提交次数', + style:{ + fontSize: '14px' + } + }, subtitle: { // text: 'Source: WorldClimate.com' }, xAxis: { // categories: ["Jan", "Jan", "Jan", 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] - categories: <%= raw(@static_total_per_user.map{|c| c.uname}) %> + categories: <%= raw(@a_uname) %> }, yAxis: { title: { @@ -89,6 +137,12 @@ } }, plotOptions: { + series: { + marker: { + radius: 3, //曲线点半径,默认是4 + symbol: 'circle' //曲线点类型:"circle", "square", "diamond", "triangle","triangle-down",默认是"circle" + } + }, line: { dataLabels: { enabled: true @@ -97,9 +151,24 @@ } }, series: [{ - name: '提交次数', + name: '提交次数', + fontWeight: 'normal', + color: '#d05d5a', // data: [7.0, 6.9, 9.5, 14.5, 18.4, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6] - data: <%= @static_total_per_user.map{|c| c.commits_num.to_i} %> + data: <%= @a_commits_num %>, + dataLabels: { + enabled: false, + + style: { + fontSize: '13px', + color: '#aaa', + fontFamily: 'Arial', + textShadow: '0px 0px 6px rgb(0, 0, 0), 0px 0px 3px rgb(f, f, f)', + fontWeight: 'normal' + } + }, + lineWidth: 1.5 + } // { // name: 'London', @@ -108,4 +177,5 @@ ] }); }); - \ No newline at end of file + +
\ No newline at end of file diff --git a/app/views/repositories/show.html.erb b/app/views/repositories/show.html.erb index b3cad6ced..329dee898 100644 --- a/app/views/repositories/show.html.erb +++ b/app/views/repositories/show.html.erb @@ -25,7 +25,7 @@