版本库动态中统计改成从数据库获取

beidou_tim
huang 9 years ago
parent 2a00c4ddd7
commit 40b45ce1b4

@ -319,9 +319,15 @@ 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 = @project.rep_statics
@a_uname = rep_statics.map {|s| s.uname }
@a_commits_num = rep_statics.map {|s| s.commits_num.to_i }
@a_commits_add = rep_statics.map {|s| s.add.to_i }
@a_commits_del = rep_statics.map {|s| s.del.to_i }
@a_commits_changeset = rep_statics.map {|s| s.changeset.to_i }
# @static_total_per_user = g.rep_stats(@project.gpid)
end
# 根据对应的请求,返回对应的数据
respond_to do |format|

@ -573,7 +573,15 @@ 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
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
# @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

@ -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

@ -0,0 +1,4 @@
class RepStatics < ActiveRecord::Base
belongs_to :project
attr_accessible :add, :commits_num, :del, :email, :project_id, :uname, :changeset
end

@ -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) %>
},
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
@ -45,17 +55,20 @@
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} %>
// 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: <%= @a_commits_add %>,
lineWidth: 1.5
},
{
name: '删除',
color: '#46baed ',
data: <%= @static_total_per_user.map{|c| c.del.to_i} %>
data: <%= @a_commits_del %>,
lineWidth: 1.5
},{
name: '总变更',
color: '#d397d5',
data: <%= @static_total_per_user.map{|c| c.changes.to_i} %>
data: <%= @a_commits_changeset %>,
lineWidth: 1.5
}]
});
@ -68,14 +81,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 +106,12 @@
}
},
plotOptions: {
series: {
marker: {
radius: 3, //曲线点半径默认是4
symbol: 'circle' //曲线点类型:"circle", "square", "diamond", "triangle","triangle-down",默认是"circle"
}
},
line: {
dataLabels: {
enabled: true
@ -99,7 +122,9 @@
series: [{
name: '提交次数',
// 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 %>,
lineWidth: 1.5
}
// {
// name: 'London',

@ -0,0 +1,14 @@
class CreateRepStatics < ActiveRecord::Migration
def change
create_table :rep_statics do |t|
t.integer :project_id
t.integer :commits_num
t.string :uname
t.string :email
t.integer :add
t.integer :del
t.timestamps
end
end
end

@ -0,0 +1,5 @@
class AddChangesetToRepStatics < ActiveRecord::Migration
def change
add_column :rep_statics, :changeset, :integer
end
end

@ -0,0 +1,26 @@
class SyncRepStatics < ActiveRecord::Migration
def up
g = Gitlab.client
# projects = Project.find_by_sql("SELECT p.* FROM projects p, project_scores ps where p.id = ps.project_id and p.gpid is not null and ps.changeset_num > 0")
projects = Project.where("gpid is not null")
count = projects.count / 30 + 2
transaction do
for i in 1 ... count do i
projects.page(i).per(30).each do |project|
begin
puts project.id
g.rep_stats(project.gpid).each do |static|
puts static.uname
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)
end
rescue
logger.error("Sync rep failed!")
end
end
end
end
end
def down
end
end

File diff suppressed because it is too large Load Diff

@ -0,0 +1,11 @@
FactoryGirl.define do
factory :rep_static, :class => 'RepStatics' do
project_id 1
commits_num 1
uname "MyString"
email "MyString"
add 1
del 1
end
end

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe RepStatics, :type => :model do
pending "add some examples to (or delete) #{__FILE__}"
end
Loading…
Cancel
Save